View Javadoc
1 /*** 2 * BSD-style license; for more info see http://pmd.sourceforge.net/license.html 3 */ 4 package test.net.sourceforge.pmd.ast; 5 6 import junit.framework.TestCase; 7 import net.sourceforge.pmd.PMD; 8 import net.sourceforge.pmd.ast.JavaParser; 9 import net.sourceforge.pmd.ast.ParseException; 10 11 import java.io.StringReader; 12 13 public class AssertTest extends TestCase { 14 15 public void testAssertAsKeywordVariantsSucceedWith1_4() { 16 new JavaParser(new StringReader(TEST1)).CompilationUnit(); 17 new JavaParser(new StringReader(TEST2)).CompilationUnit(); 18 new JavaParser(new StringReader(TEST3)).CompilationUnit(); 19 new JavaParser(new StringReader(TEST4)).CompilationUnit(); 20 } 21 22 public void testAssertAsVariableDeclIdentifierFailsWith1_4() { 23 try { 24 new JavaParser(new StringReader(TEST5)).CompilationUnit(); 25 throw new RuntimeException("Usage of assert as identifier should have failed with 1.4"); 26 } catch (ParseException pe) { 27 // cool 28 } 29 } 30 31 public void testAssertAsMethodNameIdentifierFailsWith1_4() { 32 try { 33 new JavaParser(new StringReader(TEST7)).CompilationUnit(); 34 throw new RuntimeException("Usage of assert as identifier should have failed with 1.4"); 35 } catch (ParseException pe) { 36 // cool 37 } 38 } 39 40 public void testAssertAsIdentifierSucceedsWith1_3() { 41 JavaParser jp = new JavaParser(new StringReader(TEST5)); 42 jp.setAssertAsIdentifier(); 43 jp.CompilationUnit(); 44 } 45 46 public void testAssertAsKeywordFailsWith1_3() { 47 try { 48 JavaParser jp = new JavaParser(new StringReader(TEST6)); 49 jp.setAssertAsIdentifier(); 50 jp.CompilationUnit(); 51 throw new RuntimeException("Usage of assert as keyword should have failed with 1.3"); 52 } catch (ParseException pe) { 53 // cool 54 } 55 } 56 57 private static final String TEST1 = 58 "public class Foo {" + PMD.EOL + 59 " void bar() {" + PMD.EOL + 60 " assert x>2;" + PMD.EOL + 61 " }" + PMD.EOL + 62 "}"; 63 64 private static final String TEST2 = 65 "public class Foo {" + PMD.EOL + 66 " void bar() {" + PMD.EOL + 67 " assert (x>2);" + PMD.EOL + 68 " }" + PMD.EOL + 69 "}"; 70 71 private static final String TEST3 = 72 "public class Foo {" + PMD.EOL + 73 " void bar() {" + PMD.EOL + 74 " assert x>2 : \"hi!\";" + PMD.EOL + 75 " }" + PMD.EOL + 76 "}"; 77 78 private static final String TEST4 = 79 "public class Foo {" + PMD.EOL + 80 " void bar() {" + PMD.EOL + 81 " assert (x>2) : \"hi!\";" + PMD.EOL + 82 " }" + PMD.EOL + 83 "}"; 84 85 private static final String TEST5 = 86 "public class Foo {" + PMD.EOL + 87 " int assert = 2;" + PMD.EOL + 88 "}"; 89 90 private static final String TEST6 = 91 "public class Foo {" + PMD.EOL + 92 " void foo() {" + PMD.EOL + 93 " assert (x>2) : \"hi!\";" + PMD.EOL + 94 " }" + PMD.EOL + 95 "}"; 96 97 private static final String TEST7 = 98 "public class Foo {" + PMD.EOL + 99 " void assert() {}" + PMD.EOL + 100 "}"; 101 102 103 }

This page was automatically generated by Maven