View Javadoc
1   package net.sourceforge.pmd.lang.java.ast;
2   
3   import static org.junit.Assert.assertFalse;
4   import static org.junit.Assert.assertTrue;
5   
6   import java.util.Set;
7   
8   import net.sourceforge.pmd.PMD;
9   import net.sourceforge.pmd.lang.java.ParserTst;
10  
11  import org.junit.Test;
12  
13  public class ASTBooleanLiteralTest extends ParserTst {
14  
15      @Test
16      public void testTrue() throws Throwable {
17          Set ops = getNodes(ASTBooleanLiteral.class, TEST1);
18          ASTBooleanLiteral b = (ASTBooleanLiteral) ops.iterator().next();
19          assertTrue(b.isTrue());
20      }
21  
22      @Test
23      public void testFalse() throws Throwable {
24          Set ops = getNodes(ASTBooleanLiteral.class, TEST2);
25          ASTBooleanLiteral b = (ASTBooleanLiteral) ops.iterator().next();
26          assertFalse(b.isTrue());
27      }
28  
29      private static final String TEST1 =
30              "class Foo { " + PMD.EOL +
31              " boolean bar = true; " + PMD.EOL +
32              "} ";
33  
34      private static final String TEST2 =
35              "class Foo { " + PMD.EOL +
36              " boolean bar = false; " + PMD.EOL +
37              "} ";
38  
39      public static junit.framework.Test suite() {
40          return new junit.framework.JUnit4TestAdapter(ASTBooleanLiteralTest.class);
41      }
42  }