Skip to content

Commit

Permalink
Custom declaration order check sevntu-checkstyle#195 Compilable UT in…
Browse files Browse the repository at this point in the history
…puts
  • Loading branch information
alexkravin committed Sep 1, 2014
1 parent 12aef23 commit 992a130
Show file tree
Hide file tree
Showing 6 changed files with 89 additions and 106 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ public void testCustomDecrationOrder() throws Exception
final DefaultConfiguration checkConfig =
createCheckConfig(CustomDeclarationOrderCheck.class);
final String[] expected = {
"10:5: " + getCheckMessage(MSG_KEY_FIELD, "Field(private static final long serialVersionUID)", "Field(.*final public.*|.*public final.*)"),
"20:5: " + getCheckMessage(MSG_KEY_FIELD, "Field(protected.*)", "Field(private.*)"),
"22:5: " + getCheckMessage(MSG_KEY_FIELD, "Field(@SuppressWarnings(.*serial.*).*)", "Field(private.*)"),
"45:5: " + getCheckMessage(MSG_KEY_CONSTRUCTOR, "Ctor()", "Method(.*abstract.*public.*|.*public.*abstract.*|protected.*)"),
"52:5: " + getCheckMessage(MSG_KEY_METHOD, "Method(public static.*(new|edit|create).*)", "Method(.*abstract.*public.*|.*public.*abstract.*|protected.*)"),
"10:5: " + getCheckMessage(MSG_KEY_FIELD, "Field(private static final long serialVersionUID)", "Field(.*final public.*|.*public final.*)"),
"20:5: " + getCheckMessage(MSG_KEY_FIELD, "Field(protected.*)", "Field(private.*)"),
"22:5: " + getCheckMessage(MSG_KEY_FIELD, "Field(@SuppressWarnings(.*serial.*).*)", "Field(private.*)"),
"45:5: " + getCheckMessage(MSG_KEY_CONSTRUCTOR, "Ctor()", "Method(.*abstract.*public.*|.*public.*abstract.*|protected.*)"),
"52:5: " + getCheckMessage(MSG_KEY_METHOD, "Method(public static.*(new|edit|create).*)", "Method(.*abstract.*public.*|.*public.*abstract.*|protected.*)"),
"60:9: " + getCheckMessage(MSG_KEY_FIELD, "Field(.*final public.*|.*public final.*)", "Field(private.*)"),
"80:9: " + getCheckMessage(MSG_KEY_CLASS, "InnerClass (public.*abstract.*)", "InnerClass (private.*)"),
"84:5: " + getCheckMessage(MSG_KEY_METHOD, "Method(@Deprecated.*)", "InnerClass (private.*)"),
Expand Down Expand Up @@ -51,10 +51,10 @@ public void anonymousClasses()
final DefaultConfiguration checkConfig =
createCheckConfig(CustomDeclarationOrderCheck.class);
final String[] expected = {
"38:5: " + getCheckMessage(MSG_KEY_FIELD, "DeclareAnnonClassField(private.*)", "Field(public.*)"),
"53:5: " + getCheckMessage(MSG_KEY_FIELD, "DeclareAnnonClassField(private.*)", "Field(private.*)"),
"65:5: " + getCheckMessage(MSG_KEY_FIELD, "DeclareAnnonClassField()", "Ctor(public.*)"),
"94:9: " + getCheckMessage(MSG_KEY_FIELD, "DeclareAnnonClassField(private.*)", "Field(private.*)"),
"39:5: " + getCheckMessage(MSG_KEY_FIELD, "DeclareAnnonClassField(private.*)", "Field(public.*)"),
"54:5: " + getCheckMessage(MSG_KEY_FIELD, "DeclareAnnonClassField(private.*)", "Field(private.*)"),
"66:5: " + getCheckMessage(MSG_KEY_FIELD, "DeclareAnnonClassField()", "Ctor(public.*)"),
"95:9: " + getCheckMessage(MSG_KEY_FIELD, "DeclareAnnonClassField(private.*)", "Field(private.*)"),
};
checkConfig
.addAttribute(
Expand All @@ -80,22 +80,22 @@ public void gettersSetters()
final DefaultConfiguration checkConfig =
createCheckConfig(CustomDeclarationOrderCheck.class);
final String[] expected = {
"51:5: " + getCheckMessage(MSG_KEY_METHOD, "GetterSetter(.*)", "Method(.*)"),
"57:5: " + getCheckMessage(MSG_KEY_METHOD, "GetterSetter(.*)", "Method(.*)"),
"62:5: " + getCheckMessage(MSG_KEY_METHOD, "GetterSetter(.*)", "Method(.*)"),
"67:5: " + getCheckMessage(MSG_KEY_METHOD, "GetterSetter(.*)", "Method(.*)"),
"72:5: " + getCheckMessage(MSG_KEY_METHOD, "GetterSetter(.*)", "Method(.*)"),
"77:5: " + getCheckMessage(MSG_KEY_METHOD, "GetterSetter(.*)", "Method(.*)"),
"92: " + getCheckMessage(MSG_KEY_INVALID_SETTER, "setField", "getField"),
"129: " + getCheckMessage(MSG_KEY_INVALID_SETTER, "setField", "getField"),
"134: " + getCheckMessage(MSG_KEY_INVALID_SETTER, "setX", "getX"),
"139: " + getCheckMessage(MSG_KEY_INVALID_SETTER, "setVisible", "isVisible"),
"169: " + getCheckMessage(MSG_KEY_INVALID_SETTER, "setField", "getField"),
"177:5: " + getCheckMessage(MSG_KEY_METHOD, "GetterSetter(.*)", "Method(.*)"),
"181:5: " + getCheckMessage(MSG_KEY_METHOD, "GetterSetter(.*)", "Method(.*)"),
"293:5: " + getCheckMessage(MSG_KEY_METHOD, "GetterSetter(.*)", "Method(.*)"),
"297:5: " + getCheckMessage(MSG_KEY_METHOD, "GetterSetter(.*)", "Method(.*)"),
"302:5: " + getCheckMessage(MSG_KEY_METHOD, "GetterSetter(.*)", "Method(.*)"),
"50:5: " + getCheckMessage(MSG_KEY_METHOD, "GetterSetter(.*)", "Method(.*)"),
"56:5: " + getCheckMessage(MSG_KEY_METHOD, "GetterSetter(.*)", "Method(.*)"),
"61:5: " + getCheckMessage(MSG_KEY_METHOD, "GetterSetter(.*)", "Method(.*)"),
"66:5: " + getCheckMessage(MSG_KEY_METHOD, "GetterSetter(.*)", "Method(.*)"),
"71:5: " + getCheckMessage(MSG_KEY_METHOD, "GetterSetter(.*)", "Method(.*)"),
"76:5: " + getCheckMessage(MSG_KEY_METHOD, "GetterSetter(.*)", "Method(.*)"),
"91: " + getCheckMessage(MSG_KEY_INVALID_SETTER, "setField", "getField"),
"128: " + getCheckMessage(MSG_KEY_INVALID_SETTER, "setField", "getField"),
"133: " + getCheckMessage(MSG_KEY_INVALID_SETTER, "setX", "getX"),
"138: " + getCheckMessage(MSG_KEY_INVALID_SETTER, "setVisible", "isVisible"),
"168: " + getCheckMessage(MSG_KEY_INVALID_SETTER, "setField", "getField"),
"176:5: " + getCheckMessage(MSG_KEY_METHOD, "GetterSetter(.*)", "Method(.*)"),
"180:5: " + getCheckMessage(MSG_KEY_METHOD, "GetterSetter(.*)", "Method(.*)"),
"282:5: " + getCheckMessage(MSG_KEY_METHOD, "GetterSetter(.*)", "Method(.*)"),
"286:5: " + getCheckMessage(MSG_KEY_METHOD, "GetterSetter(.*)", "Method(.*)"),
"291:5: " + getCheckMessage(MSG_KEY_METHOD, "GetterSetter(.*)", "Method(.*)"),
};
checkConfig.addAttribute(
"customDeclarationOrder",
Expand All @@ -112,10 +112,10 @@ public void innerInterfacesAndEnums()
final DefaultConfiguration checkConfig =
createCheckConfig(CustomDeclarationOrderCheck.class);
final String[] expected = {
"40:5: " + getCheckMessage(MSG_KEY_FIELD, "Field(private)", "InnerInterface(.*)"),
"48:5: " + getCheckMessage(MSG_KEY_FIELD, "Field(private)", "InnerEnum(.*)"),
"56:5: " + getCheckMessage(MSG_KEY_INTERFACE, "InnerInterface(.*)", "InnerEnum(.*)"),
"69:5: " + getCheckMessage(MSG_KEY_METHOD, "Method(.*)", "InnerEnum(.*)"),
"41:5: " + getCheckMessage(MSG_KEY_FIELD, "Field(private)", "InnerInterface(.*)"),
"49:5: " + getCheckMessage(MSG_KEY_FIELD, "Field(private)", "InnerEnum(.*)"),
"57:5: " + getCheckMessage(MSG_KEY_INTERFACE, "InnerInterface(.*)", "InnerEnum(.*)"),
"70:5: " + getCheckMessage(MSG_KEY_METHOD, "Method(.*)", "InnerEnum(.*)"),
};

checkConfig.addAttribute(
Expand All @@ -133,8 +133,8 @@ public void mainMethod()
final DefaultConfiguration checkConfig =
createCheckConfig(CustomDeclarationOrderCheck.class);
final String[] expected = {
"9:5: " + getCheckMessage(MSG_KEY_FIELD, "Field(private)", "Method(.*)"),
"16:5: " + getCheckMessage(MSG_KEY_FIELD, "Field(private)", "Method(.*)"),
"10:5: " + getCheckMessage(MSG_KEY_FIELD, "Field(private)", "Method(.*)"),
"17:5: " + getCheckMessage(MSG_KEY_FIELD, "Field(private)", "Method(.*)"),
};
checkConfig.addAttribute(
"customDeclarationOrder",
Expand All @@ -143,4 +143,4 @@ public void mainMethod()
checkConfig.addAttribute("caseSensitive", "false");
verify(checkConfig, getPath("InputCustomDeclarationOrderCheckMainMethod.java"), expected);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,9 @@ protected void test3() {

}

class Test {
class Test1 {

Test() {
Test1() {
}

private String someTest;
Expand All @@ -122,7 +122,7 @@ void otherMethod() {
}
}

class ClassForIssue58 {
class ClassForIssue528 {
private void simplePrivate() {
class Inner {
int number;
Expand Down Expand Up @@ -171,4 +171,4 @@ class B {
private boolean is;
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
class Ok_1 {
private Integer i1 = new Integer(){
package com.github.sevntu.checkstyle.checks.coding;
class InputCustomDeclarationOrderCheckAnonymousClasses {
private Object i1 = new Object(){
int getInt() {
return 1;
}
};
protected Integer i2 = new Integer(){
protected Object i2 = new Object(){
int getInt() {
return 1;
}
};
Integer i3 = new Integer(){
Object i3 = new Object(){
int getInt() {
return 1;
}
};
public Integer i4 = new Integer(){
public Object i4 = new Object(){
int getInt() {
return 1;
}
Expand All @@ -23,57 +24,57 @@ int getInt() {
private int max = 3;
public int min = 1;

public Ok() {
public InputCustomDeclarationOrderCheckAnonymousClasses() {
}

public void a() {
}
}

class Errors_1 {
class Errors_11 {
//wrong order
private int max = 3;
public int min = 1;

private Integer i1 = new Integer(){
private Object i1 = new Object(){
int getInt() {
return 1;
}
};
}

class Errors_2 {
private Integer i1 = new Integer(){
class Errors_12 {
private Object i1 = new Object(){
int getInt() {
return 1;
}
};
//wrong order
private double d1 = 4.6;
private Integer i2 = new Integer(){
private Object i2 = new Object(){
int getInt() {
return 1;
}
};
}

class Errors_3 {
class Errors_31 {
//wrong order
public Errors_3() {
public Errors_31() {
}

Integer i = new Integer() {
Object i = new Object() {
int getInt() {
return 34;
}
};
}

class Ok_2 {
class Ok_210{
private int k = 7;

public void process(){
Integer i = new Integer(){
Object i = new Object(){
int getInt() {
return 34;
}
Expand All @@ -91,7 +92,7 @@ public void simple() {}
class Erros {
// wrong order
private int x;
private Integer i = new Integer() {
private Object i = new Object() {
int getInt() {
return 1;
}
Expand All @@ -100,7 +101,7 @@ public void title() {}
}
}

public class SpacePadder {
class SpacePadder {

final static String[] SPACES = { " ", " ", " ", " ", // 1,2,4,8
// spaces
Expand Down Expand Up @@ -148,4 +149,4 @@ final static public void spacePad(StringBuilder sbuf, int length) {
}
}
}
}
}
Loading

0 comments on commit 992a130

Please sign in to comment.