Skip to content

Commit

Permalink
Issue #9523: Update MissingOverrideCheckTest to use unique input file…
Browse files Browse the repository at this point in the history
…s in each test method
  • Loading branch information
bossever authored and romani committed Mar 28, 2021
1 parent e061b4e commit 16cd510
Show file tree
Hide file tree
Showing 15 changed files with 476 additions and 121 deletions.
14 changes: 0 additions & 14 deletions config/checkstyle_input_suppressions.xml
Original file line number Diff line number Diff line change
Expand Up @@ -78,20 +78,6 @@
files="annotation[\\/]missingdeprecated[\\/]InputMissingDeprecatedSingleComment.java"/>
<suppress id="ConfigCommentOnTopInputs"
files="annotation[\\/]missingdeprecated[\\/]InputMissingDeprecatedSpecialCase.java"/>
<suppress id="ConfigCommentOnTopInputs"
files="annotation[\\/]missingoverride[\\/]InputMissingOverrideBadAnnotation.java"/>
<suppress id="ConfigCommentOnTopInputs"
files="annotation[\\/]missingoverride[\\/]InputMissingOverrideBadOverrideFromObject.java"/>
<suppress id="ConfigCommentOnTopInputs"
files="annotation[\\/]missingoverride[\\/]InputMissingOverrideBadOverrideFromOther.java"/>
<suppress id="ConfigCommentOnTopInputs"
files="annotation[\\/]missingoverride[\\/]InputMissingOverrideGoodOverrideFromObject.java"/>
<suppress id="ConfigCommentOnTopInputs"
files="annotation[\\/]missingoverride[\\/]InputMissingOverrideGoodOverrideFromOther.java"/>
<suppress id="ConfigCommentOnTopInputs"
files="annotation[\\/]missingoverride[\\/]InputMissingOverrideGoodOverride.java"/>
<suppress id="ConfigCommentOnTopInputs"
files="annotation[\\/]missingoverride[\\/]InputMissingOverrideNotOverride.java"/>
<suppress id="ConfigCommentOnTopInputs"
files="annotation[\\/]packageannotation[\\/]InputPackageAnnotation2.java"/>
<suppress id="ConfigCommentOnTopInputs"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,10 @@ public void testBadOverrideFromObject() throws Exception {
checkConfig.addAttribute("javaFiveCompatibility", "false");

final String[] expected = {
"8:5: " + getCheckMessage(MSG_KEY_ANNOTATION_MISSING_OVERRIDE),
"30:9: " + getCheckMessage(MSG_KEY_ANNOTATION_MISSING_OVERRIDE),
"41:5: " + getCheckMessage(MSG_KEY_ANNOTATION_MISSING_OVERRIDE),
"50:5: " + getCheckMessage(MSG_KEY_ANNOTATION_MISSING_OVERRIDE),
"11:5: " + getCheckMessage(MSG_KEY_ANNOTATION_MISSING_OVERRIDE),
"31:9: " + getCheckMessage(MSG_KEY_ANNOTATION_MISSING_OVERRIDE),
"40:5: " + getCheckMessage(MSG_KEY_ANNOTATION_MISSING_OVERRIDE),
"49:5: " + getCheckMessage(MSG_KEY_ANNOTATION_MISSING_OVERRIDE),
};

verify(checkConfig, getPath("InputMissingOverrideBadOverrideFromObject.java"), expected);
Expand All @@ -67,13 +67,14 @@ public void testBadOverrideFromObjectJ5Compatible() throws Exception {
checkConfig.addAttribute("javaFiveCompatibility", "true");

final String[] expected = {
"8:5: " + getCheckMessage(MSG_KEY_ANNOTATION_MISSING_OVERRIDE),
"30:9: " + getCheckMessage(MSG_KEY_ANNOTATION_MISSING_OVERRIDE),
"41:5: " + getCheckMessage(MSG_KEY_ANNOTATION_MISSING_OVERRIDE),
"50:5: " + getCheckMessage(MSG_KEY_ANNOTATION_MISSING_OVERRIDE),
"11:5: " + getCheckMessage(MSG_KEY_ANNOTATION_MISSING_OVERRIDE),
"31:9: " + getCheckMessage(MSG_KEY_ANNOTATION_MISSING_OVERRIDE),
"40:5: " + getCheckMessage(MSG_KEY_ANNOTATION_MISSING_OVERRIDE),
"49:5: " + getCheckMessage(MSG_KEY_ANNOTATION_MISSING_OVERRIDE),
};

verify(checkConfig, getPath("InputMissingOverrideBadOverrideFromObject.java"), expected);
verify(checkConfig, getPath("InputMissingOverrideBadOverrideFromObjectJava5.java"),
expected);
}

/**
Expand All @@ -84,13 +85,13 @@ public void testBadOverrideFromObjectJ5Compatible() throws Exception {
public void testBadOverrideFromOther() throws Exception {
final DefaultConfiguration checkConfig = createModuleConfig(MissingOverrideCheck.class);
final String[] expected = {
"10:5: " + getCheckMessage(MSG_KEY_ANNOTATION_MISSING_OVERRIDE),
"26:5: " + getCheckMessage(MSG_KEY_ANNOTATION_MISSING_OVERRIDE),
"34:5: " + getCheckMessage(MSG_KEY_ANNOTATION_MISSING_OVERRIDE),
"40:5: " + getCheckMessage(MSG_KEY_ANNOTATION_MISSING_OVERRIDE),
"47:9: " + getCheckMessage(MSG_KEY_ANNOTATION_MISSING_OVERRIDE),
"53:9: " + getCheckMessage(MSG_KEY_ANNOTATION_MISSING_OVERRIDE),
"63:5: " + getCheckMessage(MSG_KEY_ANNOTATION_MISSING_OVERRIDE),
"13:5: " + getCheckMessage(MSG_KEY_ANNOTATION_MISSING_OVERRIDE),
"29:5: " + getCheckMessage(MSG_KEY_ANNOTATION_MISSING_OVERRIDE),
"37:5: " + getCheckMessage(MSG_KEY_ANNOTATION_MISSING_OVERRIDE),
"42:5: " + getCheckMessage(MSG_KEY_ANNOTATION_MISSING_OVERRIDE),
"49:9: " + getCheckMessage(MSG_KEY_ANNOTATION_MISSING_OVERRIDE),
"54:9: " + getCheckMessage(MSG_KEY_ANNOTATION_MISSING_OVERRIDE),
"64:5: " + getCheckMessage(MSG_KEY_ANNOTATION_MISSING_OVERRIDE),
};

verify(checkConfig, getPath("InputMissingOverrideBadOverrideFromOther.java"), expected);
Expand All @@ -107,7 +108,8 @@ public void testBadOverrideFromOtherJ5Compatible() throws Exception {

final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;

verify(checkConfig, getPath("InputMissingOverrideBadOverrideFromOther.java"), expected);
verify(checkConfig, getPath("InputMissingOverrideBadOverrideFromOtherJava5.java"),
expected);
}

/**
Expand All @@ -118,10 +120,10 @@ public void testBadOverrideFromOtherJ5Compatible() throws Exception {
public void testBadAnnotationOverride() throws Exception {
final DefaultConfiguration checkConfig = createModuleConfig(MissingOverrideCheck.class);
final String[] expected = {
"10:9: " + getCheckMessage(MSG_KEY_ANNOTATION_MISSING_OVERRIDE),
"16:17: " + getCheckMessage(MSG_KEY_ANNOTATION_MISSING_OVERRIDE),
"29:13: " + getCheckMessage(MSG_KEY_ANNOTATION_MISSING_OVERRIDE),
"35:21: " + getCheckMessage(MSG_KEY_ANNOTATION_MISSING_OVERRIDE),
"13:9: " + getCheckMessage(MSG_KEY_ANNOTATION_MISSING_OVERRIDE),
"19:17: " + getCheckMessage(MSG_KEY_ANNOTATION_MISSING_OVERRIDE),
"32:13: " + getCheckMessage(MSG_KEY_ANNOTATION_MISSING_OVERRIDE),
"38:21: " + getCheckMessage(MSG_KEY_ANNOTATION_MISSING_OVERRIDE),
};

verify(checkConfig, getPath("InputMissingOverrideBadAnnotation.java"), expected);
Expand All @@ -137,7 +139,7 @@ public void testBadAnnotationOverrideJ5Compatible() throws Exception {
checkConfig.addAttribute("javaFiveCompatibility", "true");
final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;

verify(checkConfig, getPath("InputMissingOverrideBadAnnotation.java"), expected);
verify(checkConfig, getPath("InputMissingOverrideBadAnnotationJava5.java"), expected);
}

/**
Expand All @@ -147,8 +149,8 @@ public void testBadAnnotationOverrideJ5Compatible() throws Exception {
public void testNotOverride() throws Exception {
final DefaultConfiguration checkConfig = createModuleConfig(MissingOverrideCheck.class);
final String[] expected = {
"8:5: " + getCheckMessage(MSG_KEY_TAG_NOT_VALID_ON, "{@inheritDoc}"),
"15:5: " + getCheckMessage(MSG_KEY_TAG_NOT_VALID_ON, "{@inheritDoc}"),
"11:5: " + getCheckMessage(MSG_KEY_TAG_NOT_VALID_ON, "{@inheritDoc}"),
"16:5: " + getCheckMessage(MSG_KEY_TAG_NOT_VALID_ON, "{@inheritDoc}"),
};

verify(checkConfig, getPath("InputMissingOverrideNotOverride.java"), expected);
Expand Down Expand Up @@ -179,7 +181,8 @@ public void testGoodOverrideFromObjectJ5Compatible() throws Exception {

final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;

verify(checkConfig, getPath("InputMissingOverrideGoodOverrideFromObject.java"), expected);
verify(checkConfig, getPath("InputMissingOverrideGoodOverrideFromObjectJava5.java"),
expected);
}

/**
Expand All @@ -205,7 +208,8 @@ public void testGoodOverrideFromOtherJ5Compatible() throws Exception {

final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;

verify(checkConfig, getPath("InputMissingOverrideGoodOverrideFromOther.java"), expected);
verify(checkConfig, getPath("InputMissingOverrideGoodOverrideFromOtherJava5.java"),
expected);
}

/**
Expand All @@ -230,7 +234,7 @@ public void testGoodAnnotationOverrideJ5Compatible() throws Exception {
checkConfig.addAttribute("javaFiveCompatibility", "true");
final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;

verify(checkConfig, getPath("InputMissingOverrideGoodOverride.java"), expected);
verify(checkConfig, getPath("InputMissingOverrideGoodOverrideJava5.java"), expected);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
package com.puppycrawl.tools.checkstyle.checks.annotation.missingoverride;

/* Config:
* javaFiveCompatibility = "false"
*/
public class InputMissingOverrideBadAnnotation
{
Runnable r = new Runnable() {

/**
* {@inheritDoc}
*/
public void run() {
public void run() { // ok
Throwable t = new Throwable() {

/**
* {@inheritDoc}
*/
public String toString() {
public String toString() { // ok
return "junk";
}
};
Expand All @@ -26,13 +29,13 @@ void doFoo(Runnable r) {
/**
* {@inheritDoc}
*/
public void run() {
public void run() { // ok
Throwable t = new Throwable() {

/**
* {@inheritDoc}
*/
public String toString() {
public String toString() { // ok
return "junk";
}
};
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package com.puppycrawl.tools.checkstyle.checks.annotation.missingoverride;

/* Config:
* javaFiveCompatibility = "true"
*/
public class InputMissingOverrideBadAnnotationJava5
{
Runnable r = new Runnable() {

/**
* {@inheritDoc}
*/
public void run() { // ok
Throwable t = new Throwable() {

/**
* {@inheritDoc}
*/
public String toString() { // ok
return "junk";
}
};
}
};

void doFoo(Runnable r) {
doFoo(new Runnable() {

/**
* {@inheritDoc}
*/
public void run() { // ok
Throwable t = new Throwable() {

/**
* {@inheritDoc}
*/
public String toString() { // ok
return "junk";
}
};
}
});
}
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
package com.puppycrawl.tools.checkstyle.checks.annotation.missingoverride;

/* Config:
* javaFiveCompatibility = "false"
*/
public class InputMissingOverrideBadOverrideFromObject
{
/**
* {@inheritDoc}
*/
public boolean equals(Object obj)
{
public boolean equals(Object obj) { // violation
return false;
}

Expand All @@ -17,8 +19,7 @@ public boolean equals(Object obj)
*
* {@inheritDoc
*/
public int hashCode()
{
public int hashCode() {
return 1;
}

Expand All @@ -27,9 +28,7 @@ class Junk {
/**
* {@inheritDoc}
*/
protected void finalize() throws Throwable
{
}
protected void finalize() throws Throwable {} // violation
}
}

Expand All @@ -38,16 +37,16 @@ interface HashEq2 {
/**
* {@inheritDoc}
*/
public int hashCode();
public int hashCode(); // violation
}

enum Bleh3 {
enum enum3 {
B;

/**
* {@inheritDoc}
*/
public String toString() {
public String toString() { // violation
return "B";
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package com.puppycrawl.tools.checkstyle.checks.annotation.missingoverride;

/* Config:
* javaFiveCompatibility = "true"
*/
public class InputMissingOverrideBadOverrideFromObjectJava5
{
/**
* {@inheritDoc}
*/
public boolean equals(Object obj) { // violation
return false;
}

/**
* {@inheritDoc no violation}
*
* @inheritDocs}
*
* {@inheritDoc
*/
public int hashCode() {
return 1;
}

class Junk {

/**
* {@inheritDoc}
*/
protected void finalize() throws Throwable {} // violation
}
}

interface HashEq2Java5 {

/**
* {@inheritDoc}
*/
public int hashCode(); // violation
}

enum enum3Java5 {
B;

/**
* {@inheritDoc}
*/
public String toString() { // violation
return "B";
}

private static void test() {}
}
Loading

0 comments on commit 16cd510

Please sign in to comment.