Skip to content

Commit

Permalink
Issue #10548: Migrate to Inline Config Parser in Tests
Browse files Browse the repository at this point in the history
  • Loading branch information
shashwatj07 authored and romani committed Aug 19, 2021
1 parent 514cc2e commit 95d36da
Show file tree
Hide file tree
Showing 16 changed files with 103 additions and 85 deletions.
2 changes: 0 additions & 2 deletions pom.xml
Expand Up @@ -1783,7 +1783,6 @@

<exclude>**/ThrowsCountCheckTest.class</exclude>

<exclude>**/RequireThisCheckTest.class</exclude>

<exclude>**/FileLengthCheckTest.class</exclude>

Expand Down Expand Up @@ -1862,7 +1861,6 @@

<exclude>**/RecordComponentNameCheckTest.class</exclude>

<exclude>**/MultipleVariableDeclarationsCheckTest.class</exclude>


<exclude>**/TypeUseAnnotationsOnQualifiedTypesTest.class</exclude>
Expand Down
Expand Up @@ -52,7 +52,7 @@ public void testIt() throws Exception {
"42:44: " + getCheckMessage(MSG_MULTIPLE),
};

verify(checkConfig,
verifyWithInlineConfigParser(checkConfig,
getPath("InputMultipleVariableDeclarations.java"),
expected);
}
Expand Down
Expand Up @@ -44,7 +44,8 @@ public void testDefaultNoPackage() throws Exception {
"8:1: " + getCheckMessage(MSG_KEY_MISSING),
};

verify(checkConfig, getPath("InputPackageDeclarationNoPackage.java"), expected);
verifyWithInlineConfigParser(checkConfig,
getPath("InputPackageDeclarationNoPackage.java"), expected);
}

@Test
Expand All @@ -53,7 +54,8 @@ public void testDefaultWithPackage() throws Exception {

final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;

verify(checkConfig, getPath("InputPackageDeclarationPlain.java"), expected);
verifyWithInlineConfigParser(checkConfig,
getPath("InputPackageDeclarationPlain.java"), expected);
}

@Test
Expand All @@ -62,7 +64,8 @@ public void testOnFileWithCommentOnly() throws Exception {

final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;

verify(checkConfig, getPath("InputPackageDeclarationWithCommentOnly.java"), expected);
verifyWithInlineConfigParser(checkConfig,
getPath("InputPackageDeclarationWithCommentOnly.java"), expected);
}

@Test
Expand All @@ -73,7 +76,7 @@ public void testFileForDiffDirectoryMismatch() throws Exception {
"8:1: " + getCheckMessage(MSG_KEY_MISMATCH),
};

verify(checkConfig,
verifyWithInlineConfigParser(checkConfig,
getNonCompilablePath("InputPackageDeclarationDiffDirectory.java"), expected);
}

Expand All @@ -85,7 +88,7 @@ public void testFileForDirectoryMismatchAtParent() throws Exception {
"8:1: " + getCheckMessage(MSG_KEY_MISMATCH),
};

verify(checkConfig,
verifyWithInlineConfigParser(checkConfig,
getNonCompilablePath("InputPackageDeclarationDiffDirectoryAtParent.java"),
expected);
}
Expand All @@ -98,7 +101,7 @@ public void testFileForDirectoryMismatchAtSubpackage() throws Exception {
"8:1: " + getCheckMessage(MSG_KEY_MISMATCH),
};

verify(checkConfig,
verifyWithInlineConfigParser(checkConfig,
getNonCompilablePath("InputPackageDeclarationDiffDirectoryAtSubpackage.java"),
expected);
}
Expand All @@ -109,7 +112,8 @@ public void testFileIgnoreDiffDirectoryMismatch() throws Exception {
checkConfig.addProperty("matchDirectoryStructure", "false");
final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;

verify(checkConfig, getNonCompilablePath("InputPackageDeclarationDiffDirectory2.java"),
verifyWithInlineConfigParser(checkConfig,
getNonCompilablePath("InputPackageDeclarationDiffDirectory2.java"),
expected);
}

Expand All @@ -119,7 +123,7 @@ public void testFileIgnoreDirectoryMismatchAtParent() throws Exception {
checkConfig.addProperty("matchDirectoryStructure", "false");
final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;

verify(checkConfig,
verifyWithInlineConfigParser(checkConfig,
getNonCompilablePath("InputPackageDeclarationDiffDirectoryAtParent2.java"),
expected);
}
Expand All @@ -130,7 +134,7 @@ public void testFileIgnoreDirectoryMismatchAtSubpackage() throws Exception {
checkConfig.addProperty("matchDirectoryStructure", "false");
final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;

verify(checkConfig,
verifyWithInlineConfigParser(checkConfig,
getNonCompilablePath("InputPackageDeclarationDiffDirectoryAtSubpackage2.java"),
expected);
}
Expand All @@ -142,7 +146,7 @@ public void testNoPackage() throws Exception {
"9:1: " + getCheckMessage(MSG_KEY_MISSING),
};

verify(checkConfig,
verifyWithInlineConfigParser(checkConfig,
getNonCompilablePath("InputPackageDeclarationNoPackage.java"),
expected);
}
Expand Down
Expand Up @@ -76,7 +76,7 @@ public void testIt() throws Exception {
"183:20: " + getCheckMessage(MSG_VARIABLE, "b", ""),
"183:24: " + getCheckMessage(MSG_VARIABLE, "b", ""),
};
verify(checkConfig,
verifyWithInlineConfigParser(checkConfig,
getPath("InputRequireThisEnumInnerClassesAndBugs.java"),
expected);
}
Expand All @@ -93,7 +93,7 @@ public void testMethodsOnly() throws Exception {
"130:13: " + getCheckMessage(MSG_METHOD, "instanceMethod", "Issue22402."),
"143:9: " + getCheckMessage(MSG_METHOD, "foo", ""),
};
verify(checkConfig,
verifyWithInlineConfigParser(checkConfig,
getPath("InputRequireThisEnumInnerClassesAndBugs2.java"),
expected);
}
Expand All @@ -120,7 +120,7 @@ public void testFieldsOnly() throws Exception {
"185:20: " + getCheckMessage(MSG_VARIABLE, "b", ""),
"185:24: " + getCheckMessage(MSG_VARIABLE, "b", ""),
};
verify(checkConfig,
verifyWithInlineConfigParser(checkConfig,
getPath("InputRequireThisEnumInnerClassesAndBugs3.java"),
expected);
}
Expand Down Expand Up @@ -152,7 +152,7 @@ public void testFieldsInExpressions() throws Exception {
"35:31: " + getCheckMessage(MSG_VARIABLE, "b", ""),
"36:32: " + getCheckMessage(MSG_VARIABLE, "b", ""),
};
verify(checkConfig,
verifyWithInlineConfigParser(checkConfig,
getPath("InputRequireThisExpressions.java"),
expected);
}
Expand All @@ -163,7 +163,8 @@ public void testGenerics() throws Exception {
createModuleConfig(RequireThisCheck.class);
checkConfig.addProperty("validateOnlyOverlapping", "false");
final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
verify(checkConfig, getPath("InputRequireThis15Extensions.java"), expected);
verifyWithInlineConfigParser(checkConfig,
getPath("InputRequireThis15Extensions.java"), expected);
}

@Test
Expand All @@ -175,7 +176,7 @@ public void testGithubIssue41() throws Exception {
"16:19: " + getCheckMessage(MSG_VARIABLE, "number", ""),
"17:16: " + getCheckMessage(MSG_METHOD, "other", ""),
};
verify(checkConfig,
verifyWithInlineConfigParser(checkConfig,
getPath("InputRequireThisSimple.java"),
expected);
}
Expand All @@ -197,7 +198,7 @@ public void testWithAnonymousClass() throws Exception {
"32:24: " + getCheckMessage(MSG_VARIABLE, "bar", "InputRequireThisAnonymousEmpty."),
"55:17: " + getCheckMessage(MSG_VARIABLE, "foobar", ""),
};
verify(checkConfig,
verifyWithInlineConfigParser(checkConfig,
getPath("InputRequireThisAnonymousEmpty.java"),
expected);
}
Expand Down Expand Up @@ -266,7 +267,8 @@ public void testValidateOnlyOverlappingFalse() throws Exception {
"393:16: " + getCheckMessage(MSG_METHOD, "processAction", ""),
"499:22: " + getCheckMessage(MSG_VARIABLE, "add", ""),
};
verify(checkConfig, getPath("InputRequireThisValidateOnlyOverlappingFalse.java"), expected);
verifyWithInlineConfigParser(checkConfig,
getPath("InputRequireThisValidateOnlyOverlappingFalse.java"), expected);
}

@Test
Expand All @@ -286,30 +288,34 @@ public void testValidateOnlyOverlappingTrue() throws Exception {
"310:9: " + getCheckMessage(MSG_VARIABLE, "field1", ""),
"348:9: " + getCheckMessage(MSG_VARIABLE, "field1", ""),
};
verify(checkConfig, getPath("InputRequireThisValidateOnlyOverlappingTrue.java"), expected);
verifyWithInlineConfigParser(checkConfig,
getPath("InputRequireThisValidateOnlyOverlappingTrue.java"), expected);
}

@Test
public void testReceiverParameter() throws Exception {
final DefaultConfiguration checkConfig = createModuleConfig(RequireThisCheck.class);
final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
verify(checkConfig, getPath("InputRequireThisReceiver.java"), expected);
verifyWithInlineConfigParser(checkConfig,
getPath("InputRequireThisReceiver.java"), expected);
}

@Test
public void testBraceAlone() throws Exception {
final DefaultConfiguration checkConfig = createModuleConfig(RequireThisCheck.class);
checkConfig.addProperty("validateOnlyOverlapping", "false");
final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
verify(checkConfig, getPath("InputRequireThisBraceAlone.java"), expected);
verifyWithInlineConfigParser(checkConfig,
getPath("InputRequireThisBraceAlone.java"), expected);
}

@Test
public void testStatic() throws Exception {
final DefaultConfiguration checkConfig = createModuleConfig(RequireThisCheck.class);
checkConfig.addProperty("validateOnlyOverlapping", "false");
final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
verify(checkConfig, getPath("InputRequireThisStatic.java"), expected);
verifyWithInlineConfigParser(checkConfig,
getPath("InputRequireThisStatic.java"), expected);
}

@Test
Expand All @@ -318,7 +324,8 @@ public void testMethodReferences() throws Exception {
final String[] expected = {
"24:9: " + getCheckMessage(MSG_VARIABLE, "tags", ""),
};
verify(checkConfig, getPath("InputRequireThisMethodReferences.java"), expected);
verifyWithInlineConfigParser(checkConfig,
getPath("InputRequireThisMethodReferences.java"), expected);
}

@Test
Expand All @@ -334,7 +341,8 @@ public void testAllowLocalVars() throws Exception {
"50:9: " + getCheckMessage(MSG_VARIABLE, "s2", ""),
"51:16: " + getCheckMessage(MSG_VARIABLE, "s1", ""),
};
verify(checkConfig, getPath("InputRequireThisAllowLocalVars.java"), expected);
verifyWithInlineConfigParser(checkConfig,
getPath("InputRequireThisAllowLocalVars.java"), expected);
}

@Test
Expand All @@ -348,7 +356,8 @@ public void testAllowLambdaParameters() throws Exception {
"71:29: " + getCheckMessage(MSG_VARIABLE, "a", ""),
"71:34: " + getCheckMessage(MSG_VARIABLE, "b", ""),
};
verify(checkConfig, getPath("InputRequireThisAllowLambdaParameters.java"), expected);
verifyWithInlineConfigParser(checkConfig,
getPath("InputRequireThisAllowLambdaParameters.java"), expected);
}

@Test
Expand All @@ -358,23 +367,26 @@ public void testCatchVariables() throws Exception {
final String[] expected = {
"38:21: " + getCheckMessage(MSG_VARIABLE, "ex", ""),
};
verify(checkConfig, getPath("InputRequireThisCatchVariables.java"), expected);
verifyWithInlineConfigParser(checkConfig,
getPath("InputRequireThisCatchVariables.java"), expected);
}

@Test
public void testEnumConstant() throws Exception {
final DefaultConfiguration checkConfig = createModuleConfig(RequireThisCheck.class);
checkConfig.addProperty("validateOnlyOverlapping", "false");
final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
verify(checkConfig, getPath("InputRequireThisEnumConstant.java"), expected);
verifyWithInlineConfigParser(checkConfig,
getPath("InputRequireThisEnumConstant.java"), expected);
}

@Test
public void testAnnotationInterface() throws Exception {
final DefaultConfiguration checkConfig = createModuleConfig(RequireThisCheck.class);
checkConfig.addProperty("validateOnlyOverlapping", "false");
final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
verify(checkConfig, getPath("InputRequireThisAnnotationInterface.java"), expected);
verifyWithInlineConfigParser(checkConfig,
getPath("InputRequireThisAnnotationInterface.java"), expected);
}

@Test
Expand All @@ -385,7 +397,8 @@ public void testFor() throws Exception {
"22:13: " + getCheckMessage(MSG_VARIABLE, "bottom", ""),
"30:34: " + getCheckMessage(MSG_VARIABLE, "name", ""),
};
verify(checkConfig, getPath("InputRequireThisFor.java"), expected);
verifyWithInlineConfigParser(checkConfig,
getPath("InputRequireThisFor.java"), expected);
}

@Test
Expand All @@ -395,22 +408,25 @@ public void testFinalInstanceVariable() throws Exception {
"18:9: " + getCheckMessage(MSG_VARIABLE, "y", ""),
"19:9: " + getCheckMessage(MSG_VARIABLE, "z", ""),
};
verify(checkConfig, getPath("InputRequireThisFinalInstanceVariable.java"), expected);
verifyWithInlineConfigParser(checkConfig,
getPath("InputRequireThisFinalInstanceVariable.java"), expected);
}

@Test
public void test() throws Exception {
final DefaultConfiguration checkConfig = createModuleConfig(RequireThisCheck.class);
final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
verify(checkConfig, getPath("InputRequireThisCaseGroup.java"), expected);
verifyWithInlineConfigParser(checkConfig,
getPath("InputRequireThisCaseGroup.java"), expected);
}

@Test
public void testExtendedMethod() throws Exception {
final DefaultConfiguration checkConfig = createModuleConfig(RequireThisCheck.class);
checkConfig.addProperty("validateOnlyOverlapping", "false");
final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
verify(checkConfig, getPath("InputRequireThisExtendedMethod.java"), expected);
verifyWithInlineConfigParser(checkConfig,
getPath("InputRequireThisExtendedMethod.java"), expected);
}

@Test
Expand All @@ -428,7 +444,7 @@ public void testRecordsAndCompactCtors() throws Exception {
"58:13: " + getCheckMessage(MSG_METHOD, "method3", ""),
"68:13: " + getCheckMessage(MSG_METHOD, "method1", ""),
};
verify(checkConfig,
verifyWithInlineConfigParser(checkConfig,
getNonCompilablePath("InputRequireThisRecordsAndCompactCtors.java"),
expected);
}
Expand All @@ -438,7 +454,7 @@ public void testRecordCompactCtors() throws Exception {
final DefaultConfiguration checkConfig = createModuleConfig(RequireThisCheck.class);
checkConfig.addProperty("validateOnlyOverlapping", "false");
final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
verify(checkConfig,
verifyWithInlineConfigParser(checkConfig,
getNonCompilablePath("InputRequireThisRecordCompactCtors.java"),
expected);
}
Expand All @@ -457,7 +473,7 @@ public void testRecordsAsTopLevel() throws Exception {
"38:17: " + getCheckMessage(MSG_VARIABLE, "y", ""),
"45:9: " + getCheckMessage(MSG_METHOD, "method1", ""),
};
verify(checkConfig,
verifyWithInlineConfigParser(checkConfig,
getNonCompilablePath("InputRequireThisRecordAsTopLevel.java"),
expected);
}
Expand All @@ -468,7 +484,7 @@ public void testRecordsDefault() throws Exception {
final String[] expected = {
"26:9: " + getCheckMessage(MSG_VARIABLE, "x", ""),
};
verify(checkConfig,
verifyWithInlineConfigParser(checkConfig,
getNonCompilablePath("InputRequireThisRecordDefault.java"),
expected);
}
Expand Down
Expand Up @@ -39,7 +39,7 @@ void method2() {
}

void method3() {
java.lang.Object obj; Object obj1; Object obj2; Object obj3; // violation
java.lang.Object obj; Object obj1; Object obj2; Object obj3; // 3 violations
for (String s : new String[] {}) {}
}
}
Expand Up @@ -43,7 +43,7 @@ void methodInFirstLevel(int x) {
new String("y = " + y); // NO violation; y is a lambda parameter
new String("InputRequireThisAllowLambdaParameters.this.x = " +
InputRequireThisAllowLambdaParameters.this.x);
y=x+z++; // 1 violation for z; NO violation for y; y is a lambda parameter
y=x+z++; // 1 violation for z; NO violation for y; y is a lambda // violation
};
myConsumer.accept(x);
}
Expand Down

0 comments on commit 95d36da

Please sign in to comment.