Issue #2161: unify test input locations for annotation package

This commit is contained in:
rnveach 2015-10-15 21:56:17 -04:00 committed by Roman Ivanov
parent aee8f8230b
commit 5d9f7028d7
15 changed files with 97 additions and 51 deletions

View File

@ -109,6 +109,7 @@ public class OuterTypeFilenameCheckTest extends BaseCheckTestSupport {
final String[] expected = ArrayUtils.EMPTY_STRING_ARRAY;
verify(checkConfig, getPath("annotation" + File.separator + "package-info.java"), expected);
verify(checkConfig, new File("src/test/resources-noncompilable/com/puppycrawl/tools/"
+ "checkstyle/checks/package-info.java").getCanonicalPath(), expected);
}
}

View File

@ -20,6 +20,7 @@
package com.puppycrawl.tools.checkstyle.checks.annotation;
import java.io.File;
import java.io.IOException;
import org.apache.commons.lang3.ArrayUtils;
import org.junit.Assert;
@ -30,6 +31,18 @@ import com.puppycrawl.tools.checkstyle.DefaultConfiguration;
import com.puppycrawl.tools.checkstyle.api.TokenTypes;
public class PackageAnnotationTest extends BaseCheckTestSupport {
@Override
protected String getPath(String filename) throws IOException {
return super.getPath("checks" + File.separator
+ "annotation" + File.separator + filename);
}
@Override
protected String getNonCompilablePath(String filename) throws IOException {
return super.getNonCompilablePath("checks" + File.separator
+ "annotation" + File.separator + filename);
}
/**
* This tests a package annotation that is in the package-info.java file.
*/
@ -39,7 +52,7 @@ public class PackageAnnotationTest extends BaseCheckTestSupport {
final String[] expected = ArrayUtils.EMPTY_STRING_ARRAY;
verify(checkConfig, getPath("annotation" + File.separator + "package-info.java"), expected);
verify(checkConfig, getNonCompilablePath("package-info.java"), expected);
}
@Test
@ -56,7 +69,7 @@ public class PackageAnnotationTest extends BaseCheckTestSupport {
final String[] expected = ArrayUtils.EMPTY_STRING_ARRAY;
verify(checkConfig, getPath("annotation" + File.separator + "InputPackageAnnotationCheckTest.java"), expected);
verify(checkConfig, getPath("InputPackageAnnotationCheckTest.java"), expected);
}
@Test
@ -67,6 +80,6 @@ public class PackageAnnotationTest extends BaseCheckTestSupport {
"0: Package annotations must be in the package-info.java info.",
};
verify(checkConfig, new File("src/test/resources-noncompilable/com/puppycrawl/tools/checkstyle/annotation/InputPackageAnnotationCheckTest2.java").getCanonicalPath(), expected);
verify(checkConfig, getNonCompilablePath("InputPackageAnnotationCheckTest2.java"), expected);
}
}

View File

@ -22,6 +22,7 @@ package com.puppycrawl.tools.checkstyle.checks.annotation;
import static com.puppycrawl.tools.checkstyle.checks.annotation.SuppressWarningsCheck.MSG_KEY_SUPPRESSED_WARNING_NOT_ALLOWED;
import java.io.File;
import java.io.IOException;
import org.apache.commons.lang3.ArrayUtils;
import org.junit.Test;
@ -30,6 +31,12 @@ import com.puppycrawl.tools.checkstyle.BaseCheckTestSupport;
import com.puppycrawl.tools.checkstyle.DefaultConfiguration;
public class SuppressWarningsCheckTest extends BaseCheckTestSupport {
@Override
protected String getPath(String filename) throws IOException {
return super.getPath("checks" + File.separator
+ "annotation" + File.separator + filename);
}
/**
* Tests SuppressWarnings with default regex.
*/
@ -49,7 +56,7 @@ public class SuppressWarningsCheckTest extends BaseCheckTestSupport {
"82:106: " + getCheckMessage(MSG_KEY_SUPPRESSED_WARNING_NOT_ALLOWED, " "),
};
verify(checkConfig, getPath("annotation" + File.separator + "SuppressWarningsSingle.java"), expected);
verify(checkConfig, getPath("SuppressWarningsSingle.java"), expected);
}
/**
@ -91,7 +98,7 @@ public class SuppressWarningsCheckTest extends BaseCheckTestSupport {
"82:115: " + getCheckMessage(MSG_KEY_SUPPRESSED_WARNING_NOT_ALLOWED, "unused"),
};
verify(checkConfig, getPath("annotation" + File.separator + "SuppressWarningsSingle.java"), expected);
verify(checkConfig, getPath("SuppressWarningsSingle.java"), expected);
}
/**
@ -115,7 +122,7 @@ public class SuppressWarningsCheckTest extends BaseCheckTestSupport {
"82:47: " + getCheckMessage(MSG_KEY_SUPPRESSED_WARNING_NOT_ALLOWED, "unchecked"),
};
verify(checkConfig, getPath("annotation" + File.separator + "SuppressWarningsSingle.java"), expected);
verify(checkConfig, getPath("SuppressWarningsSingle.java"), expected);
}
/**
@ -137,7 +144,7 @@ public class SuppressWarningsCheckTest extends BaseCheckTestSupport {
"82:47: " + getCheckMessage(MSG_KEY_SUPPRESSED_WARNING_NOT_ALLOWED, "unchecked"),
};
verify(checkConfig, getPath("annotation" + File.separator + "SuppressWarningsSingle.java"), expected);
verify(checkConfig, getPath("SuppressWarningsSingle.java"), expected);
}
/**
@ -170,7 +177,7 @@ public class SuppressWarningsCheckTest extends BaseCheckTestSupport {
"82:115: " + getCheckMessage(MSG_KEY_SUPPRESSED_WARNING_NOT_ALLOWED, "unused"),
};
verify(checkConfig, getPath("annotation" + File.separator + "SuppressWarningsSingle.java"), expected);
verify(checkConfig, getPath("SuppressWarningsSingle.java"), expected);
}
/**
@ -200,7 +207,7 @@ public class SuppressWarningsCheckTest extends BaseCheckTestSupport {
"82:115: " + getCheckMessage(MSG_KEY_SUPPRESSED_WARNING_NOT_ALLOWED, "unused"),
};
verify(checkConfig, getPath("annotation" + File.separator + "SuppressWarningsSingle.java"), expected);
verify(checkConfig, getPath("SuppressWarningsSingle.java"), expected);
}
/**
@ -242,7 +249,7 @@ public class SuppressWarningsCheckTest extends BaseCheckTestSupport {
"82:115: " + getCheckMessage(MSG_KEY_SUPPRESSED_WARNING_NOT_ALLOWED, "unused"),
};
verify(checkConfig, getPath("annotation" + File.separator + "SuppressWarningsSingle.java"), expected);
verify(checkConfig, getPath("SuppressWarningsSingle.java"), expected);
}
/**
@ -271,7 +278,7 @@ public class SuppressWarningsCheckTest extends BaseCheckTestSupport {
"82:194: " + getCheckMessage(MSG_KEY_SUPPRESSED_WARNING_NOT_ALLOWED, " "),
};
verify(checkConfig, getPath("annotation" + File.separator + "SuppressWarningsCompact.java"), expected);
verify(checkConfig, getPath("SuppressWarningsCompact.java"), expected);
}
/**
@ -332,7 +339,7 @@ public class SuppressWarningsCheckTest extends BaseCheckTestSupport {
"82:202: " + getCheckMessage(MSG_KEY_SUPPRESSED_WARNING_NOT_ALLOWED, "unused"),
};
verify(checkConfig, getPath("annotation" + File.separator + "SuppressWarningsCompact.java"), expected);
verify(checkConfig, getPath("SuppressWarningsCompact.java"), expected);
}
/**
@ -359,7 +366,7 @@ public class SuppressWarningsCheckTest extends BaseCheckTestSupport {
"82:135: " + getCheckMessage(MSG_KEY_SUPPRESSED_WARNING_NOT_ALLOWED, "unchecked"),
};
verify(checkConfig, getPath("annotation" + File.separator + "SuppressWarningsCompact.java"), expected);
verify(checkConfig, getPath("SuppressWarningsCompact.java"), expected);
}
@ -379,7 +386,7 @@ public class SuppressWarningsCheckTest extends BaseCheckTestSupport {
"64:62: " + getCheckMessage(MSG_KEY_SUPPRESSED_WARNING_NOT_ALLOWED, "unchecked"),
};
verify(checkConfig, getPath("annotation" + File.separator + "SuppressWarningsCompact.java"), expected);
verify(checkConfig, getPath("SuppressWarningsCompact.java"), expected);
}
/**
@ -421,7 +428,7 @@ public class SuppressWarningsCheckTest extends BaseCheckTestSupport {
"82:202: " + getCheckMessage(MSG_KEY_SUPPRESSED_WARNING_NOT_ALLOWED, "unused"),
};
verify(checkConfig, getPath("annotation" + File.separator + "SuppressWarningsCompact.java"), expected);
verify(checkConfig, getPath("SuppressWarningsCompact.java"), expected);
}
/**
@ -457,7 +464,7 @@ public class SuppressWarningsCheckTest extends BaseCheckTestSupport {
"82:202: " + getCheckMessage(MSG_KEY_SUPPRESSED_WARNING_NOT_ALLOWED, "unused"),
};
verify(checkConfig, getPath("annotation" + File.separator + "SuppressWarningsCompact.java"), expected);
verify(checkConfig, getPath("SuppressWarningsCompact.java"), expected);
}
/**
@ -518,7 +525,7 @@ public class SuppressWarningsCheckTest extends BaseCheckTestSupport {
"82:202: " + getCheckMessage(MSG_KEY_SUPPRESSED_WARNING_NOT_ALLOWED, "unused"),
};
verify(checkConfig, getPath("annotation" + File.separator + "SuppressWarningsCompact.java"), expected);
verify(checkConfig, getPath("SuppressWarningsCompact.java"), expected);
}
/**
@ -545,7 +552,7 @@ public class SuppressWarningsCheckTest extends BaseCheckTestSupport {
"82:200: " + getCheckMessage(MSG_KEY_SUPPRESSED_WARNING_NOT_ALLOWED, " "),
};
verify(checkConfig, getPath("annotation" + File.separator + "SuppressWarningsExpanded.java"), expected);
verify(checkConfig, getPath("SuppressWarningsExpanded.java"), expected);
}
/**
@ -603,7 +610,7 @@ public class SuppressWarningsCheckTest extends BaseCheckTestSupport {
};
verify(checkConfig, getPath("annotation" + File.separator + "SuppressWarningsExpanded.java"), expected);
verify(checkConfig, getPath("SuppressWarningsExpanded.java"), expected);
}
/**
@ -631,7 +638,7 @@ public class SuppressWarningsCheckTest extends BaseCheckTestSupport {
"82:141: " + getCheckMessage(MSG_KEY_SUPPRESSED_WARNING_NOT_ALLOWED, "unchecked"),
};
verify(checkConfig, getPath("annotation" + File.separator + "SuppressWarningsExpanded.java"), expected);
verify(checkConfig, getPath("SuppressWarningsExpanded.java"), expected);
}
/**
@ -650,7 +657,7 @@ public class SuppressWarningsCheckTest extends BaseCheckTestSupport {
"64:68: " + getCheckMessage(MSG_KEY_SUPPRESSED_WARNING_NOT_ALLOWED, "unchecked"),
};
verify(checkConfig, getPath("annotation" + File.separator + "SuppressWarningsExpanded.java"), expected);
verify(checkConfig, getPath("SuppressWarningsExpanded.java"), expected);
}
/**
@ -688,7 +695,7 @@ public class SuppressWarningsCheckTest extends BaseCheckTestSupport {
"82:208: " + getCheckMessage(MSG_KEY_SUPPRESSED_WARNING_NOT_ALLOWED, "unused"),
};
verify(checkConfig, getPath("annotation" + File.separator + "SuppressWarningsExpanded.java"), expected);
verify(checkConfig, getPath("SuppressWarningsExpanded.java"), expected);
}
/**
@ -725,7 +732,7 @@ public class SuppressWarningsCheckTest extends BaseCheckTestSupport {
"82:208: " + getCheckMessage(MSG_KEY_SUPPRESSED_WARNING_NOT_ALLOWED, "unused"),
};
verify(checkConfig, getPath("annotation" + File.separator + "SuppressWarningsExpanded.java"), expected);
verify(checkConfig, getPath("SuppressWarningsExpanded.java"), expected);
}
/**
@ -782,7 +789,7 @@ public class SuppressWarningsCheckTest extends BaseCheckTestSupport {
"82:208: " + getCheckMessage(MSG_KEY_SUPPRESSED_WARNING_NOT_ALLOWED, "unused"),
};
verify(checkConfig, getPath("annotation" + File.separator + "SuppressWarningsExpanded.java"), expected);
verify(checkConfig, getPath("SuppressWarningsExpanded.java"), expected);
}
@Test
@ -791,8 +798,7 @@ public class SuppressWarningsCheckTest extends BaseCheckTestSupport {
String[] expected = ArrayUtils.EMPTY_STRING_ARRAY;
verify(checkConfig, getPath("annotation" + File.separator
+ "SuppressWarningsConstants.java"), expected);
verify(checkConfig, getPath("SuppressWarningsConstants.java"), expected);
}
@Test
@ -801,8 +807,7 @@ public class SuppressWarningsCheckTest extends BaseCheckTestSupport {
String[] expected = ArrayUtils.EMPTY_STRING_ARRAY;
verify(checkConfig, getPath("annotation" + File.separator
+ "SuppressWarningsValuePair.java"), expected);
verify(checkConfig, getPath("SuppressWarningsValuePair.java"), expected);
}
@Test

View File

@ -1,5 +1,5 @@
@Deprecated
package com.puppycrawl.tools.checkstyle.annotation;
package com.puppycrawl.tools.checkstyle.checks.annotation;
public class InputPackageAnnotationCheckTest2 {

View File

@ -0,0 +1,3 @@
@Deprecated
package com.puppycrawl.tools.checkstyle.checks.annotation;

View File

@ -0,0 +1,3 @@
@Deprecated
package com.puppycrawl.tools.checkstyle.checks;

View File

@ -1,12 +0,0 @@
package com.puppycrawl.tools.checkstyle.annotation;
public class InputAnnotationLocationCheckTest3 {
@interface MyAnnotation1 {
String value();
}
// @MyAnnotation1
}

View File

@ -1,3 +0,0 @@
@Deprecated
package com.puppycrawl.tools.checkstyle.annotation;

View File

@ -1,4 +1,4 @@
package com.puppycrawl.tools.checkstyle.annotation;
package com.puppycrawl.tools.checkstyle.checks.annotation;
@Deprecated
public class InputPackageAnnotationCheckTest {

View File

@ -0,0 +1,36 @@
package com.puppycrawl.tools.checkstyle.checks.annotation;
public class InputSuppressWarningsHolder {
static final String UNUSED = "unused";
@SuppressWarnings(UNUSED)
int a;
@SuppressWarnings(InputSuppressWarningsHolder.UNUSED)
int b;
@SuppressWarnings(com.puppycrawl.tools.checkstyle.checks.annotation.InputSuppressWarningsHolder.UNUSED)
int c;
@SuppressWarnings(value = UNUSED)
int d;
@SuppressWarnings(value = InputSuppressWarningsHolder.UNUSED)
int e;
@SuppressWarnings(value = com.puppycrawl.tools.checkstyle.checks.annotation.InputSuppressWarningsHolder.UNUSED)
int f;
@SuppressWarnings((1 != 1) ? "" : "unused")
int g;
@SuppressWarnings("un" + "used")
int h;
@SuppressWarnings((String) "unused")
int i;
@SuppressWarnings({})
int j;
@SuppressWarnings({UNUSED})
int k;
@SuppressWarnings({"unused", true ? "unused" : ""})
int l;
}
class CustomSuppressWarnings {
@SuppressWarnings
private @interface SuppressWarnings {
}
}

View File

@ -1,4 +1,4 @@
package com.puppycrawl.tools.checkstyle.annotation;
package com.puppycrawl.tools.checkstyle.checks.annotation;
import java.lang.annotation.Documented;

View File

@ -1,4 +1,4 @@
package com.puppycrawl.tools.checkstyle.annotation;
package com.puppycrawl.tools.checkstyle.checks.annotation;
import java.util.List;
import java.util.ArrayList;

View File

@ -1,4 +1,4 @@
package com.puppycrawl.tools.checkstyle.annotation;
package com.puppycrawl.tools.checkstyle.checks.annotation;
import java.lang.annotation.Documented;

View File

@ -1,4 +1,4 @@
package com.puppycrawl.tools.checkstyle.annotation;
package com.puppycrawl.tools.checkstyle.checks.annotation;
import java.lang.annotation.Documented;

View File

@ -1,4 +1,4 @@
package com.puppycrawl.tools.checkstyle.annotation;
package com.puppycrawl.tools.checkstyle.checks.annotation;
import java.util.ArrayList;
import java.util.List;