Skip to content

Commit

Permalink
Issue #3678: update ITs to load certain config by id if there few of …
Browse files Browse the repository at this point in the history
…them in file
  • Loading branch information
romani committed Dec 30, 2016
1 parent d2dfb60 commit 4d1b3a2
Show file tree
Hide file tree
Showing 7 changed files with 192 additions and 10 deletions.
Expand Up @@ -260,8 +260,7 @@ protected static Configuration getCheckConfig(String checkName) throws Checkstyl
result = configs.get(0);
}
else {
result = configs.get(0);
//throw new IllegalStateException("multiple instances of the same Check is detected");
throw new IllegalStateException("multiple instances of the same Check is detected");
}
return result;
}
Expand Down
Expand Up @@ -50,7 +50,7 @@ public void rightCurlyTestAlone() throws Exception {
"79:27: " + getCheckMessage(RightCurlyCheck.class, MSG_KEY_LINE_BREAK_BEFORE, "}", 27),
};

final Configuration checkConfig = getCheckConfig("RightCurly", "RightCurlyDefault");
final Configuration checkConfig = getCheckConfig("RightCurly", "RightCurlySame");
final String filePath = getPath("InputRightCurlyOther.java");

final Integer[] warnList = getLinesWithWarn(filePath);
Expand All @@ -61,7 +61,7 @@ public void rightCurlyTestAlone() throws Exception {
public void rightCurlyTestSame() throws Exception {
final String[] expected = CommonUtils.EMPTY_STRING_ARRAY;

final Configuration checkConfig = getCheckConfig("RightCurly", "RightCurlyDefault");
final Configuration checkConfig = getCheckConfig("RightCurly", "RightCurlySame");
final String filePath = getPath("InputRightCurlySame.java");

final Integer[] warnList = getLinesWithWarn(filePath);
Expand All @@ -76,7 +76,7 @@ public void testRightCurlySameAndLiteralDoDefault() throws Exception {
"83:9: " + getCheckMessage(RightCurlyCheck.class, MSG_KEY_LINE_SAME, "}", 9),
};

final Configuration checkConfig = getCheckConfig("RightCurly", "RightCurlyDefault");
final Configuration checkConfig = getCheckConfig("RightCurly", "RightCurlySame");
final String filePath = getPath("InputRightCurlyDoWhile.java");

final Integer[] warnList = getLinesWithWarn(filePath);
Expand Down
Expand Up @@ -37,16 +37,30 @@ protected String getPath(String fileName) throws IOException {
}

@Test
public void separatorWrapTest() throws Exception {
public void separatorWrapDotTest() throws Exception {

final String[] expected = {
"28:30: " + getCheckMessage(SeparatorWrapCheck.class, "line.new", "."),
};

final Configuration checkConfig = getCheckConfig("SeparatorWrap");
final Configuration checkConfig = getCheckConfig("SeparatorWrap", "SeparatorWrapDot");
final String filePath = getPath("InputSeparatorWrap.java");

final Integer[] warnList = getLinesWithWarn(filePath);
verify(checkConfig, filePath, expected, warnList);
}

@Test
public void separatorWrapCommaTest() throws Exception {

final String[] expected = {
"31:17: " + getCheckMessage(SeparatorWrapCheck.class, "line.previous", ","),
};

final Configuration checkConfig = getCheckConfig("SeparatorWrap", "SeparatorWrapComma");
final String filePath = getPath("InputSeparatorWrapComma.java");

final Integer[] warnList = getLinesWithWarn(filePath);
verify(checkConfig, filePath, expected, warnList);
}
}
Expand Up @@ -41,7 +41,8 @@ public void annotationTest() throws Exception {

final Class<AnnotationLocationCheck> clazz = AnnotationLocationCheck.class;
getCheckMessage(clazz, "annotation.location.alone");
final Configuration checkConfig = getCheckConfig("AnnotationLocation");
final Configuration checkConfig = getCheckConfig("AnnotationLocation",
"AnnotationLocationMostCases");

final String msgLocationAlone = "annotation.location.alone";
final String msgLocation = "annotation.location";
Expand All @@ -64,4 +65,24 @@ public void annotationTest() throws Exception {
final Integer[] warnList = getLinesWithWarn(filePath);
verify(checkConfig, filePath, expected, warnList);
}

@Test
public void annotationTestVariables() throws Exception {

final Class<AnnotationLocationCheck> clazz = AnnotationLocationCheck.class;
getCheckMessage(clazz, "annotation.location.alone");
final Configuration checkConfig = getCheckConfig("AnnotationLocation",
"AnnotationLocationVariables");

final String msgLocationAlone = "annotation.location.alone";
final String msgLocation = "annotation.location";
final String[] expected = {
"63: " + getCheckMessage(clazz, msgLocation, "MyAnnotation2", "7", "4"),
};

final String filePath = getPath("InputAnnotationLocationVariables.java");

final Integer[] warnList = getLinesWithWarn(filePath);
verify(checkConfig, filePath, expected, warnList);
}
}
@@ -0,0 +1,45 @@
package com.google.checkstyle.test.chapter4formatting.rule451wheretobreak;

public class InputSeparatorWrapComma {
public void goodCase()
{
int i = 0;
String s = "ffffooooString";
s
.isEmpty(); //ok
s.isEmpty();

foo(i,
s); //ok
}
public static void foo(int i, String s)
{

}
}

class badCaseComma {

public void goodCase(int... aFoo)
{
int i = 0;

String s = "ffffooooString";
boolean b = s.
isEmpty();
foo(i
,s); //warn
int[] j;
}
public static String foo(int i, String s)
{
String maxLength = "123";
int truncationLength = 1;
CharSequence seq = null;
Object truncationIndicator = null;
return new StringBuilder(maxLength )
.append(seq, 0, truncationLength )
.append(truncationIndicator)
.toString();
}
}
@@ -1,7 +1,7 @@
package com.google.checkstyle.test.chapter4formatting.rule485annotations;

@MyAnnotation2 @MyAnnotation1 //warn
class InputCorrectAnnotationIndentation
class InputAnnotationLocation
{

@MyAnnotation2 @MyAnnotation1
Expand All @@ -18,7 +18,7 @@ class InputCorrectAnnotationIndentation

@MyAnnotation2
@MyAnnotation1 //warn
public InputCorrectAnnotationIndentation() {}
public InputAnnotationLocation() {}

@MyAnnotationWithParam("foo")
@MyAnnotation2 void foo1() {}
Expand Down
@@ -0,0 +1,103 @@
package com.google.checkstyle.test.chapter4formatting.rule485annotations;

@MyAnnotation2 @MyAnnotation1 // ok - in variables config
class InputAnnotationLocationVariables
{

@MyAnnotation2 @MyAnnotation1
public int a;

@MyAnnotation1 public int b;

@MyAnnotation2
@MyAnnotation1
public int c;

@MyAnnotation1
public int d;

@MyAnnotation2
@MyAnnotation1 // ok - in variables config
public InputAnnotationLocationVariables() {}

@MyAnnotationWithParam("foo")
@MyAnnotation2 void foo1() {}

@MyAnnotation1
@MyAnnotation2 // ok - in variables config
void foo2() {}

@MyAnnotation1
@MyAnnotation2 // ok - in variables config
@MyAnnotation3 // ok - in variables configwarn
@MyAnnotation4 // ok - in variables config
class InnerClass
{
@MyAnnotation2 @MyAnnotation1
public int a;

@MyAnnotation1 public int b;

@MyAnnotation2
@MyAnnotation1
public int c;

@MyAnnotation1
public int d;

@MyAnnotation2
@MyAnnotation1 public InnerClass()
{
// TODO Auto-generated constructor stub
}
@MyAnnotation1
@MyAnnotation2 // ok - in variables config
void foo1() {}

@MyAnnotation1
@MyAnnotation2 // ok - in variables config
void foo2() {}
}

@MyAnnotation1
@MyAnnotation2 //warn
InnerClass anon = new InnerClass()
{
@MyAnnotation2 @MyAnnotation1 public int a;

@MyAnnotation1 public int b;

@MyAnnotation2
@MyAnnotation1
public int c;

@MyAnnotation1
public int d;

@MyAnnotation1
@MyAnnotation2 void foo1() {} // ok - in variables config

@MyAnnotation1
@MyAnnotation2 // ok - in variables config
void foo2() {}

@MyAnnotation1 void foo42() {}
};

}

@MyAnnotation1
@MyAnnotation2 // ok - in variables config
class FooVariables {}

@interface MyAnnotationVariables1 {}

@interface MyAnnotationVariables2 {}

@interface MyAnnotationVariables3 {}

@interface MyAnnotationVariables4 {}

@interface MyAnnotationWithParamVariables {

String value();}

0 comments on commit 4d1b3a2

Please sign in to comment.