    1   package test.net.sourceforge.pmd.rules.junit;
    2
    3   import net.sourceforge.pmd.PMD;
    4   import net.sourceforge.pmd.Rule;
    5   import test.net.sourceforge.pmd.testframework.SimpleAggregatorTst;
    6   import test.net.sourceforge.pmd.testframework.TestDescriptor;
    7
    8   public class SimplifyBooleanAssertionTest extends SimpleAggregatorTst {
    9
    10      private Rule rule;
    11
    12      public void setUp() {
    13          rule = findRule("junit", "SimplifyBooleanAssertion");
    14      }
    15
    16      public void testAll() {
    17          runTests(new TestDescriptor[]{
    18              new TestDescriptor(TEST1, "assertFalse(!)", 1, rule),
    19              new TestDescriptor(TEST2, "assertTrue(!)", 1, rule),
    20              new TestDescriptor(TEST3, "ok", 0, rule),
    21          });
    22      }
    23
    24      private static final String TEST1 =
    25      "public class Foo {" + PMD.EOL +
    26      "   void testBar() { " + PMD.EOL +
    27      "    boolean bar; " + PMD.EOL +
    28      "    assertFalse(!bar);" + PMD.EOL +
    29      "   } " + PMD.EOL +
    30      "}";
    31
    32      private static final String TEST2 =
    33      "public class Foo {" + PMD.EOL +
    34      "   void testBar() { " + PMD.EOL +
    35      "    boolean bar; " + PMD.EOL +
    36      "    assertTrue(!bar);" + PMD.EOL +
    37      "   } " + PMD.EOL +
    38      "}";
    39
    40      private static final String TEST3 =
    41      "public class Foo {" + PMD.EOL +
    42      "   void testBar() { " + PMD.EOL +
    43      "    boolean bar; " + PMD.EOL +
    44      "    assertTrue(bar);" + PMD.EOL +
    45      "    assertFalse(bar);" + PMD.EOL +
    46      "   } " + PMD.EOL +
    47      "}";
    48  }