Issue #2161: unify test input locations for modifier package
This commit is contained in:
parent
8ee05486c1
commit
4533cef695
|
|
@ -24,6 +24,7 @@ import static com.puppycrawl.tools.checkstyle.checks.modifier.ModifierOrderCheck
|
|||
import static org.junit.Assert.assertArrayEquals;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
import org.apache.commons.lang3.ArrayUtils;
|
||||
import org.junit.Assert;
|
||||
|
|
@ -35,6 +36,17 @@ import com.puppycrawl.tools.checkstyle.api.TokenTypes;
|
|||
|
||||
public class ModifierOrderCheckTest
|
||||
extends BaseCheckTestSupport {
|
||||
@Override
|
||||
protected String getPath(String filename) throws IOException {
|
||||
return super.getPath("checks" + File.separator
|
||||
+ "modifier" + File.separator + filename);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getNonCompilablePath(String filename) throws IOException {
|
||||
return super.getNonCompilablePath("checks" + File.separator
|
||||
+ "modifier" + File.separator + filename);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetRequiredTokens() {
|
||||
|
|
@ -64,8 +76,7 @@ public class ModifierOrderCheckTest
|
|||
final DefaultConfiguration checkConfig =
|
||||
createCheckConfig(ModifierOrderCheck.class);
|
||||
final String[] expected = ArrayUtils.EMPTY_STRING_ARRAY;
|
||||
verify(checkConfig, new File("src/test/resources-noncompilable/com/puppycrawl/tools"
|
||||
+ "/checkstyle/InputModifier2.java").getCanonicalPath(), expected);
|
||||
verify(checkConfig, getNonCompilablePath("InputModifier2.java"), expected);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
|||
|
|
@ -22,6 +22,7 @@ package com.puppycrawl.tools.checkstyle.checks.modifier;
|
|||
import static com.puppycrawl.tools.checkstyle.checks.modifier.RedundantModifierCheck.MSG_KEY;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
import org.apache.commons.lang3.ArrayUtils;
|
||||
import org.junit.Assert;
|
||||
|
|
@ -33,6 +34,17 @@ import com.puppycrawl.tools.checkstyle.api.TokenTypes;
|
|||
|
||||
public class RedundantModifierTest
|
||||
extends BaseCheckTestSupport {
|
||||
@Override
|
||||
protected String getPath(String filename) throws IOException {
|
||||
return super.getPath("checks" + File.separator
|
||||
+ "modifier" + File.separator + filename);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getNonCompilablePath(String filename) throws IOException {
|
||||
return super.getNonCompilablePath("checks" + File.separator
|
||||
+ "modifier" + File.separator + filename);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testClassesInsideOfInterfaces() throws Exception {
|
||||
|
|
@ -76,10 +88,7 @@ public class RedundantModifierTest
|
|||
final DefaultConfiguration checkConfig =
|
||||
createCheckConfig(RedundantModifierCheck.class);
|
||||
final String[] expected = ArrayUtils.EMPTY_STRING_ARRAY;
|
||||
verify(checkConfig,
|
||||
new File("src/test/resources-noncompilable/com/puppycrawl/tools/"
|
||||
+ "checkstyle/InputStaticModifierInInterface.java").getCanonicalPath(),
|
||||
expected);
|
||||
verify(checkConfig, getNonCompilablePath("InputStaticModifierInInterface.java"), expected);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -90,10 +99,7 @@ public class RedundantModifierTest
|
|||
final String[] expected = {
|
||||
"3:9: " + getCheckMessage(MSG_KEY, "final"),
|
||||
};
|
||||
verify(checkConfig,
|
||||
new File("src/test/resources-noncompilable/com/puppycrawl/tools/"
|
||||
+ "checkstyle/InputFinalInDefaultMethods.java").getCanonicalPath(),
|
||||
expected);
|
||||
verify(checkConfig, getNonCompilablePath("InputFinalInDefaultMethods.java"), expected);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -114,7 +120,8 @@ public class RedundantModifierTest
|
|||
"8:5: " + getCheckMessage(MSG_KEY, "static"),
|
||||
"12:5: " + getCheckMessage(MSG_KEY, "static"),
|
||||
};
|
||||
verify(checkConfig, getPath("InputRedundantStaticModifierInInnerTypeOfInterface.java"), expected);
|
||||
verify(checkConfig, getPath("InputRedundantStaticModifierInInnerTypeOfInterface.java"),
|
||||
expected);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -178,7 +185,6 @@ public class RedundantModifierTest
|
|||
"8:9: " + getCheckMessage(MSG_KEY, "static"),
|
||||
"12:9: " + getCheckMessage(MSG_KEY, "static"),
|
||||
};
|
||||
verify(checkConfig, getPath("InputRedundantStatic"
|
||||
+ "ModifierInNestedEnum.java"), expected);
|
||||
verify(checkConfig, getPath("InputRedundantStaticModifierInNestedEnum.java"), expected);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
//Compilable with Java8
|
||||
package com.puppycrawl.tools.checkstyle;
|
||||
package com.puppycrawl.tools.checkstyle.checks.modifier;
|
||||
import java.util.Comparator;
|
||||
public interface InputModifier2 extends Comparator<Integer> {
|
||||
@Override
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
//Compilable with Java8
|
||||
public interface InputStaticModifierInInterface
|
||||
{
|
||||
static int f()
|
||||
{
|
||||
int someName = 5;
|
||||
return someName;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,139 @@
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Test case file for checkstyle.
|
||||
// Created: 2001
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
package com.puppycrawl.tools.checkstyle.checks.modifier;
|
||||
|
||||
/**
|
||||
* Test case for Modifier checks:
|
||||
* - order of modifiers
|
||||
* - use of 'public' in interface definition
|
||||
* @author lkuehne
|
||||
*/
|
||||
strictfp final class InputModifier // illegal order of modifiers for class
|
||||
{
|
||||
|
||||
/** Illegal order of modifiers for variables */
|
||||
static private boolean sModifierOrderVar = false;
|
||||
|
||||
/**
|
||||
* Illegal order of modifiers for methods. Make sure that the
|
||||
* first and last modifier from the JLS sequence is used.
|
||||
*/
|
||||
strictfp private void doStuff()
|
||||
{
|
||||
}
|
||||
|
||||
/** Single annotation without other modifiers */
|
||||
@MyAnnotation2 void someMethod()
|
||||
{
|
||||
}
|
||||
|
||||
/** Illegal order of annotation - must come first */
|
||||
private @MyAnnotation2 void someMethod2()
|
||||
{
|
||||
}
|
||||
|
||||
/** Annotation in middle of other modifiers otherwise in correct order */
|
||||
private @MyAnnotation2 strictfp void someMethod3()
|
||||
{
|
||||
}
|
||||
|
||||
/** Correct order */
|
||||
@MyAnnotation2 private strictfp void someMethod4()
|
||||
{
|
||||
}
|
||||
|
||||
/** Annotation in middle of other modifiers otherwise in correct order */
|
||||
@MyAnnotation2 private static @MyAnnotation4 strictfp void someMethod5()
|
||||
{
|
||||
}
|
||||
|
||||
/** holder for redundant 'public' modifier check. */
|
||||
public static interface InputRedundantPublicModifier // violation
|
||||
{
|
||||
/** redundant 'public' modifier */
|
||||
public void a(); // violation
|
||||
|
||||
/** all OK */
|
||||
void b();
|
||||
|
||||
/** redundant abstract modifier */
|
||||
abstract void c(); // violation
|
||||
|
||||
/** redundant 'public' modifier */
|
||||
public float PI_PUBLIC = (float) 3.14; // violation
|
||||
|
||||
/** redundant 'abstract' modifier (field can not be abstract) */
|
||||
// abstract float PI_ABSTRACT = (float) 3.14;
|
||||
|
||||
/** redundant 'final' modifier */
|
||||
final float PI_FINAL = (float) 3.14; // violation
|
||||
|
||||
/** all OK */
|
||||
float PI_OK = (float) 3.14;
|
||||
}
|
||||
|
||||
/** redundant 'final' modifier */
|
||||
private final void method() // violation
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
/** Holder for redundant 'final' check. */
|
||||
final class RedundantFinalClass
|
||||
{
|
||||
/** redundant 'final' modifier */
|
||||
public final void finalMethod() // violation
|
||||
{
|
||||
}
|
||||
|
||||
/** OK */
|
||||
public void method()
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
/** Holder for redundant modifiers of inner implementation */
|
||||
abstract interface InnerImplementation // violation
|
||||
{
|
||||
InnerImplementation inner =
|
||||
new InnerImplementation()
|
||||
{
|
||||
/** compiler requires 'public' modifier */
|
||||
public void method()
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
void method();
|
||||
}
|
||||
|
||||
/** Holder for redundant modifiers of annotation fields/variables */
|
||||
@interface Annotation
|
||||
{
|
||||
public String s1 = ""; // violation
|
||||
final String s2 = ""; // violation
|
||||
static String s3 = ""; // violation
|
||||
String s4 = "";
|
||||
public String blah(); // violation
|
||||
abstract String blah2(); // violation
|
||||
}
|
||||
|
||||
@interface MyAnnotation2 {
|
||||
}
|
||||
|
||||
@interface MyAnnotation4 {
|
||||
}
|
||||
|
||||
class SafeVarargsUsage {
|
||||
@Deprecated
|
||||
@SafeVarargs
|
||||
private final void foo(int... k) {}
|
||||
|
||||
@Deprecated
|
||||
@SafeVarargs
|
||||
@SuppressWarnings("")
|
||||
private final void foo1(Object... obj) {}
|
||||
}
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package com.puppycrawl.tools.checkstyle;
|
||||
package com.puppycrawl.tools.checkstyle.checks.modifier;
|
||||
|
||||
public interface InputModifierClassesInsideOfInterfaces {
|
||||
|
||||
|
|
@ -2,7 +2,7 @@
|
|||
// Test case file for checkstyle.
|
||||
// Created: 2015
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
package com.puppycrawl.tools.checkstyle;
|
||||
package com.puppycrawl.tools.checkstyle.checks.modifier;
|
||||
|
||||
public interface InputNestedClassInPublicInterfaceRedundantModifiers {
|
||||
interface PublicInnerInterface {
|
||||
|
|
@ -2,7 +2,7 @@
|
|||
// Test case file for checkstyle.
|
||||
// Created: 2015
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
package com.puppycrawl.tools.checkstyle;
|
||||
package com.puppycrawl.tools.checkstyle.checks.modifier;
|
||||
|
||||
public enum InputRedundantConstructorModifier {
|
||||
VAL1, VAL2;
|
||||
|
|
@ -2,7 +2,7 @@
|
|||
// Test case file for checkstyle.
|
||||
// Created: 2015
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
package com.puppycrawl.tools.checkstyle;
|
||||
package com.puppycrawl.tools.checkstyle.checks.modifier;
|
||||
|
||||
public class InputRedundantPublicModifierInNotPublicClass {
|
||||
public InputRedundantPublicModifierInNotPublicClass() { }
|
||||
|
|
@ -2,7 +2,7 @@
|
|||
// Test case file for checkstyle.
|
||||
// Created: 2015
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
package com.puppycrawl.tools.checkstyle;
|
||||
package com.puppycrawl.tools.checkstyle.checks.modifier;
|
||||
|
||||
public interface InputRedundantStaticModifierInInnerTypeOfInterface {
|
||||
static class MyInnerClass { } // violation
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package com.puppycrawl.tools.checkstyle;
|
||||
package com.puppycrawl.tools.checkstyle.checks.modifier;
|
||||
|
||||
public class InputRedundantStaticModifierInNestedEnum {
|
||||
static enum NestedEnumWithRedundantStatic {} // violation
|
||||
Loading…
Reference in New Issue