Cleanup PMD.EOL in tests

Instead, normalize line endings in parse method.
This makes sure test code snippets are portable
and readable. For now they're platform-specific,
and assume that the resource files are saved with
the platform-specific line separator. This may not
be the case, as eg a git file may be checked out
with CRLF on a unix system.
This commit is contained in:
Clément Fournier
2019-12-22 20:15:59 +01:00
parent 80534a7e69
commit a7c5a1f0be
20 changed files with 104 additions and 170 deletions

View File

@ -9,7 +9,6 @@ import static org.junit.Assert.assertEquals;
import org.junit.Test;
import net.sourceforge.pmd.FooRule;
import net.sourceforge.pmd.PMD;
import net.sourceforge.pmd.Report;
import net.sourceforge.pmd.lang.LanguageRegistry;
import net.sourceforge.pmd.lang.java.ast.ASTClassOrInterfaceDeclaration;
@ -177,59 +176,39 @@ public class SuppressWarningsTest extends RuleTst {
assertEquals(0, rpt.size());
}
private static final String TEST1 = "@SuppressWarnings(\"PMD\")" + PMD.EOL + "public class Foo {}";
private static final String TEST1 = "@SuppressWarnings(\"PMD\")\npublic class Foo {}";
private static final String TEST2 = "@SuppressWarnings(\"PMD\")" + PMD.EOL + "public class Foo {" + PMD.EOL
+ " void bar() {" + PMD.EOL + " int foo;" + PMD.EOL + " }" + PMD.EOL + "}";
private static final String TEST2 = "@SuppressWarnings(\"PMD\")\npublic class Foo {\n void bar() {\n int foo;\n }\n}";
private static final String TEST3 = "public class Baz {" + PMD.EOL + " @SuppressWarnings(\"PMD\")" + PMD.EOL
+ " public class Bar {" + PMD.EOL + " void bar() {" + PMD.EOL + " int foo;" + PMD.EOL + " }" + PMD.EOL
+ " }" + PMD.EOL + "}";
private static final String TEST3 = "public class Baz {\n @SuppressWarnings(\"PMD\")\n public class Bar {\n void bar() {\n int foo;\n }\n }\n}";
private static final String TEST4 = "public class Foo {" + PMD.EOL + " @SuppressWarnings(\"PMD\")" + PMD.EOL
+ " void bar() {" + PMD.EOL + " int foo;" + PMD.EOL + " }" + PMD.EOL + "}";
private static final String TEST4 = "public class Foo {\n @SuppressWarnings(\"PMD\")\n void bar() {\n int foo;\n }\n}";
private static final String TEST5 = "public class Bar {" + PMD.EOL + " @SuppressWarnings(\"PMD\")" + PMD.EOL
+ " public Bar() {" + PMD.EOL + " int foo;" + PMD.EOL + " }" + PMD.EOL + "}";
private static final String TEST5 = "public class Bar {\n @SuppressWarnings(\"PMD\")\n public Bar() {\n int foo;\n }\n}";
private static final String TEST6 = "public class Bar {" + PMD.EOL + " @SuppressWarnings(\"PMD\")" + PMD.EOL
+ " int foo;" + PMD.EOL + " void bar() {" + PMD.EOL + " int foo;" + PMD.EOL + " }" + PMD.EOL + "}";
private static final String TEST6 = "public class Bar {\n @SuppressWarnings(\"PMD\")\n int foo;\n void bar() {\n int foo;\n }\n}";
private static final String TEST7 = "public class Bar {" + PMD.EOL + " int foo;" + PMD.EOL
+ " void bar(@SuppressWarnings(\"PMD\") int foo) {}" + PMD.EOL + "}";
private static final String TEST7 = "public class Bar {\n int foo;\n void bar(@SuppressWarnings(\"PMD\") int foo) {}\n}";
private static final String TEST8 = "public class Bar {" + PMD.EOL + " int foo;" + PMD.EOL + " void bar() {"
+ PMD.EOL + " @SuppressWarnings(\"PMD\") int foo;" + PMD.EOL + " }" + PMD.EOL + "}";
private static final String TEST8 = "public class Bar {\n int foo;\n void bar() {\n @SuppressWarnings(\"PMD\") int foo;\n }\n}";
private static final String TEST9 = "public class Bar {" + PMD.EOL + " int foo;" + PMD.EOL + " void bar() {"
+ PMD.EOL + " @SuppressWarnings(\"PMD.NoFoo\") int foo;" + PMD.EOL + " }" + PMD.EOL + "}";
private static final String TEST9 = "public class Bar {\n int foo;\n void bar() {\n @SuppressWarnings(\"PMD.NoFoo\") int foo;\n }\n}";
private static final String TEST9_VALUE1 = "public class Bar {" + PMD.EOL + " int foo;" + PMD.EOL + " void bar() {"
+ PMD.EOL + " @SuppressWarnings(value = \"PMD.NoFoo\") int foo;" + PMD.EOL + " }" + PMD.EOL + "}";
private static final String TEST9_VALUE1 = "public class Bar {\n int foo;\n void bar() {\n @SuppressWarnings(value = \"PMD.NoFoo\") int foo;\n }\n}";
private static final String TEST9_VALUE2 = "public class Bar {" + PMD.EOL + " int foo;" + PMD.EOL + " void bar() {"
+ PMD.EOL + " @SuppressWarnings({\"PMD.NoFoo\"}) int foo;" + PMD.EOL + " }" + PMD.EOL + "}";
private static final String TEST9_VALUE2 = "public class Bar {\n int foo;\n void bar() {\n @SuppressWarnings({\"PMD.NoFoo\"}) int foo;\n }\n}";
private static final String TEST9_VALUE3 = "public class Bar {" + PMD.EOL + " int foo;" + PMD.EOL + " void bar() {"
+ PMD.EOL + " @SuppressWarnings(value = {\"PMD.NoFoo\"}) int foo;" + PMD.EOL + " }" + PMD.EOL + "}";
private static final String TEST9_VALUE3 = "public class Bar {\n int foo;\n void bar() {\n @SuppressWarnings(value = {\"PMD.NoFoo\"}) int foo;\n }\n}";
private static final String TEST9_MULTIPLE_VALUES_1 = "@SuppressWarnings({\"PMD.NoFoo\", \"PMD.NoBar\"})" + PMD.EOL
+ "public class Bar {" + PMD.EOL + " int foo;" + PMD.EOL + " void bar() {" + PMD.EOL + " int foo;"
+ PMD.EOL + " }" + PMD.EOL + "}";
private static final String TEST9_MULTIPLE_VALUES_1 = "@SuppressWarnings({\"PMD.NoFoo\", \"PMD.NoBar\"})\npublic class Bar {\n int foo;\n void bar() {\n int foo;\n }\n}";
private static final String TEST9_MULTIPLE_VALUES_2 = "@SuppressWarnings(value = {\"PMD.NoFoo\", \"PMD.NoBar\"})"
+ PMD.EOL + "public class Bar {" + PMD.EOL + " int foo;" + PMD.EOL + " void bar() {" + PMD.EOL
+ " int foo;" + PMD.EOL + " }" + PMD.EOL + "}";
private static final String TEST9_MULTIPLE_VALUES_2 = "@SuppressWarnings(value = {\"PMD.NoFoo\", \"PMD.NoBar\"})\npublic class Bar {\n int foo;\n void bar() {\n int foo;\n }\n}";
private static final String TEST10 = "public class Bar {" + PMD.EOL + " int foo;" + PMD.EOL + " void bar() {"
+ PMD.EOL + " @SuppressWarnings(\"\") int foo;" + PMD.EOL + " }" + PMD.EOL + "}";
private static final String TEST10 = "public class Bar {\n int foo;\n void bar() {\n @SuppressWarnings(\"\") int foo;\n }\n}";
private static final String TEST11 = "public class Bar {" + PMD.EOL + " int foo;" + PMD.EOL + " void bar() {"
+ PMD.EOL + " @SuppressWarnings(\"SomethingElse\") int foo;" + PMD.EOL + " }" + PMD.EOL + "}";
private static final String TEST11 = "public class Bar {\n int foo;\n void bar() {\n @SuppressWarnings(\"SomethingElse\") int foo;\n }\n}";
private static final String TEST12 = "public class Bar {" + PMD.EOL + " @SuppressWarnings(\"all\") int foo;"
+ PMD.EOL + "}";
private static final String TEST12 = "public class Bar {\n @SuppressWarnings(\"all\") int foo;\n}";
private static final String TEST13 = "@SuppressWarnings(\"PMD.NoBar\")" + PMD.EOL + "public class Bar {" + PMD.EOL
+ "}";
private static final String TEST13 = "@SuppressWarnings(\"PMD.NoBar\")\npublic class Bar {\n}";
}

View File

@ -6,8 +6,6 @@ package net.sourceforge.pmd.lang.java.ast;
import org.junit.Test;
import net.sourceforge.pmd.PMD;
public class ASTAnnotationTest extends BaseParserTest {
@Test
@ -25,6 +23,6 @@ public class ASTAnnotationTest extends BaseParserTest {
java.parse(TEST1, "1.5");
}
private static final String TEST1 = "public class Foo extends Buz {" + PMD.EOL + " @Override" + PMD.EOL
+ " void bar() {" + PMD.EOL + " // overrides a superclass method" + PMD.EOL + " }" + PMD.EOL + "}";
private static final String TEST1 =
"public class Foo extends Buz {\n @Override\n void bar() {\n // overrides a superclass method\n }\n}";
}

View File

@ -11,8 +11,6 @@ import java.util.List;
import org.junit.Test;
import net.sourceforge.pmd.PMD;
public class ASTAssignmentOperatorTest extends BaseParserTest {
@Test
@ -33,12 +31,9 @@ public class ASTAssignmentOperatorTest extends BaseParserTest {
assertTrue(ops.get(0).isCompound());
}
private static final String TEST1 = "public class Foo {" + PMD.EOL + " void bar() {" + PMD.EOL + " int x;"
+ PMD.EOL + " x=2;" + PMD.EOL + " }" + PMD.EOL + "}";
private static final String TEST1 = "public class Foo {\n void bar() {\n int x;\n x=2;\n }\n}";
private static final String TEST2 = "public class Foo {" + PMD.EOL + " void bar() {" + PMD.EOL + " int x;"
+ PMD.EOL + " x += 2;" + PMD.EOL + " }" + PMD.EOL + "}";
private static final String TEST2 = "public class Foo {\n void bar() {\n int x;\n x += 2;\n }\n}";
private static final String TEST3 = "public class Foo {" + PMD.EOL + " void bar() {" + PMD.EOL + " int x;"
+ PMD.EOL + " x *= 2;" + PMD.EOL + " }" + PMD.EOL + "}";
private static final String TEST3 = "public class Foo {\n void bar() {\n int x;\n x *= 2;\n }\n}";
}

View File

@ -11,8 +11,6 @@ import java.util.List;
import org.junit.Test;
import net.sourceforge.pmd.PMD;
public class ASTBooleanLiteralTest extends BaseParserTest {
@Test
@ -29,7 +27,7 @@ public class ASTBooleanLiteralTest extends BaseParserTest {
assertFalse(b.isTrue());
}
private static final String TEST1 = "class Foo { " + PMD.EOL + " boolean bar = true; " + PMD.EOL + "} ";
private static final String TEST1 = "class Foo { \n boolean bar = true; \n} ";
private static final String TEST2 = "class Foo { " + PMD.EOL + " boolean bar = false; " + PMD.EOL + "} ";
private static final String TEST2 = "class Foo { \n boolean bar = false; \n} ";
}

View File

@ -12,7 +12,6 @@ import java.util.List;
import org.junit.Test;
import net.sourceforge.pmd.PMD;
import net.sourceforge.pmd.lang.java.JavaParsingHelper;
import net.sourceforge.pmd.lang.java.ast.testdata.InterfaceWithNestedClass;
@ -61,16 +60,15 @@ public class ASTFieldDeclarationTest extends BaseParserTest {
assertTrue(node.isAnnotationMember());
}
private static final String TEST1 = "class Foo {" + PMD.EOL + " String[] foo;" + PMD.EOL + "}";
private static final String TEST1 = "class Foo {\n String[] foo;\n}";
private static final String TEST2 = "class Foo {" + PMD.EOL + " String[][][] foo;" + PMD.EOL + "}";
private static final String TEST2 = "class Foo {\n String[][][] foo;\n}";
private static final String TEST3 = "interface Foo {" + PMD.EOL + " int BAR = 6;" + PMD.EOL + "}";
private static final String TEST3 = "interface Foo {\n int BAR = 6;\n}";
private static final String TEST4 = "public enum Foo {" + PMD.EOL + " FOO(1);" + PMD.EOL + " private int x;"
+ PMD.EOL + "}";
private static final String TEST4 = "public enum Foo {\n FOO(1);\n private int x;\n}";
private static final String TEST5 = "public @interface Foo {" + PMD.EOL + " int BAR = 6;" + PMD.EOL + "}";
private static final String TEST5 = "public @interface Foo {\n int BAR = 6;\n}";
@Test
public void testGetVariableName() {

View File

@ -12,8 +12,6 @@ import java.util.List;
import org.junit.Test;
import net.sourceforge.pmd.PMD;
public class ASTFormalParameterTest extends BaseParserTest {
@Test
@ -38,5 +36,5 @@ public class ASTFormalParameterTest extends BaseParserTest {
assertEquals(1, nrOfNoVarArgs);
}
private static final String TEST1 = "class Foo {" + PMD.EOL + " void bar(int x, int... others) {}" + PMD.EOL + "}";
private static final String TEST1 = "class Foo {\n void bar(int x, int... others) {}\n}";
}

View File

@ -11,8 +11,6 @@ import java.util.List;
import org.junit.Test;
import net.sourceforge.pmd.PMD;
public class ASTImportDeclarationTest extends BaseParserTest {
@Test
@ -39,9 +37,9 @@ public class ASTImportDeclarationTest extends BaseParserTest {
java.parse(TEST3, "1.4");
}
private static final String TEST1 = "import foo.bar.*;" + PMD.EOL + "public class Foo {}";
private static final String TEST1 = "import foo.bar.*;\npublic class Foo {}";
private static final String TEST2 = "import foo.bar.Baz;" + PMD.EOL + "public class Foo {}";
private static final String TEST2 = "import foo.bar.Baz;\npublic class Foo {}";
private static final String TEST3 = "import static foo.bar.Baz;" + PMD.EOL + "public class Foo {}";
private static final String TEST3 = "import static foo.bar.Baz;\npublic class Foo {}";
}

View File

@ -6,8 +6,6 @@ package net.sourceforge.pmd.lang.java.ast;
import org.junit.Test;
import net.sourceforge.pmd.PMD;
public class ASTInitializerTest extends BaseParserTest {
@Test
@ -15,6 +13,5 @@ public class ASTInitializerTest extends BaseParserTest {
java.parse(TEST1);
}
private static final String TEST1 = "public class Foo {" + PMD.EOL + " {" + PMD.EOL + " x = 5;" + PMD.EOL + " }"
+ PMD.EOL + "}";
private static final String TEST1 = "public class Foo {\n {\n x = 5;\n }\n}";
}

View File

@ -12,8 +12,6 @@ import java.util.List;
import org.junit.Test;
import net.sourceforge.pmd.PMD;
public class ASTLiteralTest extends BaseParserTest {
@Test
@ -142,17 +140,17 @@ public class ASTLiteralTest extends BaseParserTest {
assertEquals("0", literal.getImage());
}
private static final String TEST1 = "public class Foo {" + PMD.EOL + " String x = \"foo\";" + PMD.EOL + "}";
private static final String TEST1 = "public class Foo {\n String x = \"foo\";\n}";
private static final String TEST2 = "public class Foo {" + PMD.EOL + " int x = 42;" + PMD.EOL + "}";
private static final String TEST2 = "public class Foo {\n int x = 42;\n}";
private static final String TEST3 = "public class Foo {" + PMD.EOL + " int x = 42;" + PMD.EOL + "}";
private static final String TEST3 = "public class Foo {\n int x = 42;\n}";
private static final String TEST4 = "public class Foo {" + PMD.EOL + " long x = 42L;" + PMD.EOL + "}";
private static final String TEST4 = "public class Foo {\n long x = 42L;\n}";
private static final String TEST5 = "public class Foo {" + PMD.EOL + " float x = 3.14159f;" + PMD.EOL + "}";
private static final String TEST5 = "public class Foo {\n float x = 3.14159f;\n}";
private static final String TEST6 = "public class Foo {" + PMD.EOL + " double x = 3.14159;" + PMD.EOL + "}";
private static final String TEST6 = "public class Foo {\n double x = 3.14159;\n}";
private static final String TEST7 = "public class Foo {" + PMD.EOL + " char x = 'x';" + PMD.EOL + "}";
private static final String TEST7 = "public class Foo {\n char x = 'x';\n}";
}

View File

@ -8,8 +8,6 @@ import static org.junit.Assert.assertEquals;
import org.junit.Test;
import net.sourceforge.pmd.PMD;
public class ASTLocalVariableDeclarationTest extends BaseParserTest {
@Test
@ -30,9 +28,9 @@ public class ASTLocalVariableDeclarationTest extends BaseParserTest {
assertEquals(3, node.getArrayDepth());
}
private static final String TEST1 = "class Foo {" + PMD.EOL + " void bar() {int x[] = null;}" + PMD.EOL + "}";
private static final String TEST1 = "class Foo {\n void bar() {int x[] = null;}\n}";
private static final String TEST2 = "class Foo {" + PMD.EOL + " void bar() {int x[][] = null;}" + PMD.EOL + "}";
private static final String TEST2 = "class Foo {\n void bar() {int x[][] = null;}\n}";
private static final String TEST3 = "class Foo {" + PMD.EOL + " void bar() {int[] x[][] = null;}" + PMD.EOL + "}";
private static final String TEST3 = "class Foo {\n void bar() {int[] x[][] = null;}\n}";
}

View File

@ -8,12 +8,9 @@ import static org.junit.Assert.assertEquals;
import org.junit.Test;
import net.sourceforge.pmd.PMD;
public class ASTPackageDeclarationTest extends BaseParserTest {
private static final String PACKAGE_INFO_ANNOTATED = "@Deprecated" + PMD.EOL + "package net.sourceforge.pmd.foobar;"
+ PMD.EOL;
private static final String PACKAGE_INFO_ANNOTATED = "@Deprecated\npackage net.sourceforge.pmd.foobar;\n";
/**
* Regression test for bug 3524607.

View File

@ -10,8 +10,6 @@ import java.util.List;
import org.junit.Test;
import net.sourceforge.pmd.PMD;
public class ASTPrimarySuffixTest extends BaseParserTest {
@Test
@ -26,7 +24,7 @@ public class ASTPrimarySuffixTest extends BaseParserTest {
assertTrue(ops.get(0).isArguments());
}
private static final String TEST1 = "public class Foo {" + PMD.EOL + " {x[0] = 2;}" + PMD.EOL + "}";
private static final String TEST1 = "public class Foo {\n {x[0] = 2;}\n}";
private static final String TEST2 = "public class Foo {" + PMD.EOL + " {foo(a);}" + PMD.EOL + "}";
private static final String TEST2 = "public class Foo {\n {foo(a);}\n}";
}

View File

@ -11,8 +11,6 @@ import java.util.List;
import org.junit.Test;
import net.sourceforge.pmd.PMD;
public class ASTSwitchLabelTest extends BaseParserTest {
@Test
@ -27,9 +25,7 @@ public class ASTSwitchLabelTest extends BaseParserTest {
assertTrue(ops.get(0).isDefault());
}
private static final String TEST1 = "public class Foo {" + PMD.EOL + " void bar() {" + PMD.EOL + " switch (x) {"
+ PMD.EOL + " case 1: y = 2;" + PMD.EOL + " }" + PMD.EOL + " }" + PMD.EOL + "}";
private static final String TEST1 = "public class Foo {\n void bar() {\n switch (x) {\n case 1: y = 2;\n }\n }\n}";
private static final String TEST2 = "public class Foo {" + PMD.EOL + " void bar() {" + PMD.EOL + " switch (x) {"
+ PMD.EOL + " default: y = 2;" + PMD.EOL + " }" + PMD.EOL + " }" + PMD.EOL + "}";
private static final String TEST2 = "public class Foo {\n void bar() {\n switch (x) {\n default: y = 2;\n }\n }\n}";
}

View File

@ -9,8 +9,6 @@ import static org.junit.Assert.assertNull;
import org.junit.Test;
import net.sourceforge.pmd.PMD;
/**
* Created on Jan 19, 2005
* @author mgriffa
@ -29,9 +27,7 @@ public class ASTThrowStatementTest extends BaseParserTest {
assertEquals("FooException", t.getFirstClassOrInterfaceTypeImage());
}
private static final String NULL_NAME = "public class Test {" + PMD.EOL + " void bar() {" + PMD.EOL + " throw e;"
+ PMD.EOL + " }" + PMD.EOL + "}";
private static final String NULL_NAME = "public class Test {\n void bar() {\n throw e;\n }\n}";
private static final String OK_NAME = "public class Test {" + PMD.EOL + " void bar() {" + PMD.EOL
+ " throw new FooException();" + PMD.EOL + " }" + PMD.EOL + "}";
private static final String OK_NAME = "public class Test {\n void bar() {\n throw new FooException();\n }\n}";
}

View File

@ -10,8 +10,6 @@ import static org.junit.Assert.assertTrue;
import org.junit.Test;
import net.sourceforge.pmd.PMD;
public class ASTVariableDeclaratorIdTest extends BaseParserTest {
@ -58,15 +56,13 @@ public class ASTVariableDeclaratorIdTest extends BaseParserTest {
assertNull(f.getTypeNameNode());
}
private static final String TYPE_NAME_NODE = "public class Test {" + PMD.EOL + " private String bar;" + PMD.EOL
+ "}";
private static final String TYPE_NAME_NODE = "public class Test {\n private String bar;\n}";
private static final String EXCEPTION_PARAMETER = "public class Test { { try {} catch(Exception ie) {} } }";
private static final String TEST_ANNOTATIONS = "public class Foo {" + PMD.EOL
+ " public void bar(@A1 @A2 String s) {}" + PMD.EOL + "}";
private static final String TEST_LAMBDA_WITH_TYPE = "public class Foo {\n" + " public void bar() {\n"
+ " FileFilter java = (File f) -> f.getName().endsWith(\".java\");\n" + " }\n" + "}\n";
private static final String TEST_LAMBDA_WITHOUT_TYPE = "public class Foo {\n" + " public void bar() {\n"
+ " FileFilter java2 = f -> f.getName().endsWith(\".java\");\n" + " }\n" + "}\n";
private static final String TEST_ANNOTATIONS = "public class Foo {\n public void bar(@A1 @A2 String s) {}\n}";
private static final String TEST_LAMBDA_WITH_TYPE =
"public class Foo {\n public void bar() {\n FileFilter java = (File f) -> f.getName().endsWith(\".java\");\n }\n}\n";
private static final String TEST_LAMBDA_WITHOUT_TYPE =
"public class Foo {\n public void bar() {\n FileFilter java2 = f -> f.getName().endsWith(\".java\");\n }\n}\n";
public static junit.framework.Test suite() {
return new junit.framework.JUnit4TestAdapter(ASTVariableDeclaratorIdTest.class);

View File

@ -8,8 +8,6 @@ import static org.junit.Assert.assertEquals;
import org.junit.Test;
import net.sourceforge.pmd.PMD;
public class EncodingTest extends BaseParserTest {
@Test
@ -19,6 +17,5 @@ public class EncodingTest extends BaseParserTest {
assertEquals("é", methodName);
}
private static final String TEST_UTF8 = "class Foo {" + PMD.EOL + " void é() {}" + PMD.EOL + " void fiddle() {}"
+ PMD.EOL + "}";
private static final String TEST_UTF8 = "class Foo {\n void é() {}\n void fiddle() {}\n}";
}

View File

@ -71,12 +71,12 @@ public class Java13Test {
ASTLiteral literal = literals.get(i);
Assert.assertTrue(literal.isTextBlock());
}
Assert.assertEquals("\"\"\"\r\n"
+ " <html>\r\n"
+ " <body>\r\n"
+ " <p>Hello, world</p>\r\n"
+ " </body>\r\n"
+ " </html>\r\n"
Assert.assertEquals("\"\"\"\n"
+ " <html>\n"
+ " <body>\n"
+ " <p>Hello, world</p>\n"
+ " </body>\n"
+ " </html>\n"
+ " \"\"\"",
literals.get(0).getImage());
Assert.assertFalse(literals.get(8).isTextBlock());

View File

@ -15,7 +15,6 @@ import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import net.sourceforge.pmd.PMD;
import net.sourceforge.pmd.lang.java.JavaParsingHelper;
import net.sourceforge.pmd.lang.symboltable.NameDeclaration;
import net.sourceforge.pmd.lang.symboltable.NameOccurrence;
@ -171,9 +170,9 @@ public class ParserCornersTest {
@Test
public void testBug206() {
java8.parse("public @interface Foo {" + PMD.EOL
+ "static final ThreadLocal<Interner<Integer>> interner =" + PMD.EOL
+ " ThreadLocal.withInitial(Interners::newStrongInterner);" + PMD.EOL
java8.parse("public @interface Foo {" + "\n"
+ "static final ThreadLocal<Interner<Integer>> interner =" + "\n"
+ " ThreadLocal.withInitial(Interners::newStrongInterner);" + "\n"
+ "}");
}
@ -184,13 +183,13 @@ public class ParserCornersTest {
@Test
public void testGitHubBug257NonExistingCast() {
String code = "public class Test {" + PMD.EOL
+ " public static void main(String[] args) {" + PMD.EOL
+ " double a = 4.0;" + PMD.EOL
+ " double b = 2.0;" + PMD.EOL
+ " double result = Math.sqrt((a) - b);" + PMD.EOL
+ " System.out.println(result);" + PMD.EOL
+ " }" + PMD.EOL
String code = "public class Test {" + "\n"
+ " public static void main(String[] args) {" + "\n"
+ " double a = 4.0;" + "\n"
+ " double b = 2.0;" + "\n"
+ " double result = Math.sqrt((a) - b);" + "\n"
+ " System.out.println(result);" + "\n"
+ " }" + "\n"
+ "}";
assertEquals("A cast was found when none expected",
@ -271,14 +270,17 @@ public class ParserCornersTest {
}
private static final String GENERICS_PROBLEM = "public class Test {" + PMD.EOL + " public void test() {" + PMD.EOL
+ " String o = super.<String> doStuff(\"\");" + PMD.EOL + " }" + PMD.EOL + "}";
private static final String GENERICS_PROBLEM =
"public class Test {\n public void test() {\n String o = super.<String> doStuff(\"\");\n }\n}";
private static final String ABSTRACT_METHOD_LEVEL_CLASS_DECL = "public class Test {" + PMD.EOL + " void bar() {"
+ PMD.EOL + " abstract class X { public abstract void f(); }" + PMD.EOL
+ " class Y extends X { public void f() {" + PMD.EOL + " new Y().f();" + PMD.EOL + " }}" + PMD.EOL
+ " }" + PMD.EOL + "}";
private static final String ABSTRACT_METHOD_LEVEL_CLASS_DECL =
"public class Test {\n"
+ " void bar() {\n"
+ " abstract class X { public abstract void f(); }\n"
+ " class Y extends X { public void f() { new Y().f(); } }\n"
+ " }\n"
+ "}";
private static final String CAST_LOOKAHEAD_PROBLEM = "public class BadClass {" + PMD.EOL + " public Class foo() {"
+ PMD.EOL + " return (byte[].class);" + PMD.EOL + " }" + PMD.EOL + "}";
private static final String CAST_LOOKAHEAD_PROBLEM =
"public class BadClass {\n public Class foo() {\n return (byte[].class);\n }\n}";
}

View File

@ -17,7 +17,6 @@ import org.jaxen.JaxenException;
import org.junit.Ignore;
import org.junit.Test;
import net.sourceforge.pmd.PMD;
import net.sourceforge.pmd.lang.ast.Node;
import net.sourceforge.pmd.lang.java.JavaParsingHelper;
@ -187,8 +186,7 @@ public class SimpleNodeTest extends BaseParserTest {
assertNull("getNthParent 8", d.getNthParent(8));
}
private static final String TEST1 = "public class Test {" + PMD.EOL + " void bar(String s) {" + PMD.EOL
+ " s = s.toLowerCase();" + PMD.EOL + " }" + PMD.EOL + "}";
private static final String TEST1 = "public class Test {\n void bar(String s) {\n s = s.toLowerCase();\n }\n}";
@Ignore
@Test
@ -286,32 +284,24 @@ public class SimpleNodeTest extends BaseParserTest {
private static final String NO_EXPLICIT_IMPLEMENTS = "public class Test {}";
private static final String METHOD_SAME_LINE = "public class Test {" + PMD.EOL + " public void foo() {}" + PMD.EOL
+ "}";
private static final String METHOD_SAME_LINE = "public class Test {\n public void foo() {}\n}";
private static final String QUALIFIED_NAME = "import java.io.File;" + PMD.EOL + "public class Foo{}";
private static final String QUALIFIED_NAME = "import java.io.File;\npublic class Foo{}";
private static final String BROKEN_LINE_IN_NAME = "import java.io." + PMD.EOL + "File;" + PMD.EOL
+ "public class Foo{}";
private static final String BROKEN_LINE_IN_NAME = "import java.io.\nFile;\npublic class Foo{}";
private static final String LINE_NUMBERS_ON_SIBLINGS = "public class Foo {" + PMD.EOL + " void bar() {" + PMD.EOL
+ " try {" + PMD.EOL + " } catch (Exception1 e) {" + PMD.EOL + " int x =2;" + PMD.EOL + " }" + PMD.EOL
+ " if (x != null) {}" + PMD.EOL + " }" + PMD.EOL + "}";
private static final String LINE_NUMBERS_ON_SIBLINGS =
"public class Foo {\n void bar() {\n try {\n } catch (Exception1 e) {\n int x =2;\n }\n if (x != null) {}\n }\n}";
private static final String NO_LOOKAHEAD = "public class Foo { }";
private static final String METHOD_DIFF_LINES = "public class Test {" + PMD.EOL + " public void foo() {" + PMD.EOL
+ " int x;" + PMD.EOL + " }" + PMD.EOL + "}";
private static final String METHOD_DIFF_LINES = "public class Test {\n public void foo() {\n int x;\n }\n}";
private static final String CONTAINS_CHILDREN_OF_TYPE = "public class Test {" + PMD.EOL + " int x;" + PMD.EOL
+ "}";
private static final String CONTAINS_CHILDREN_OF_TYPE = "public class Test {\n int x;\n}";
private static final String CONTAINS_NO_INNER = "public class Test {" + PMD.EOL + " public class Inner {" + PMD.EOL
+ " int foo;" + PMD.EOL + " }" + PMD.EOL + "}";
private static final String CONTAINS_NO_INNER = "public class Test {\n public class Inner {\n int foo;\n }\n}";
private static final String CONTAINS_NO_INNER_WITH_ANON_INNER = "public class Test {" + PMD.EOL + " void bar() {"
+ PMD.EOL + " foo(new Fuz() { int x = 2;});" + PMD.EOL + " }" + PMD.EOL + "}";
private static final String CONTAINS_NO_INNER_WITH_ANON_INNER = "public class Test {\n void bar() {\n foo(new Fuz() { int x = 2;});\n }\n}";
private static final String TEST_XPATH = "public class Test {" + PMD.EOL + " int x = 2;" + PMD.EOL
+ " int y = 42;" + PMD.EOL + "}";
private static final String TEST_XPATH = "public class Test {\n int x = 2;\n int y = 42;\n}";
}