    1   /***
    2    * BSD-style license; for more info see http://pmd.sourceforge.net/license.html
    3    */
    4   package test.net.sourceforge.pmd.rules.junit;
    5
    6   import net.sourceforge.pmd.PMD;
    7   import net.sourceforge.pmd.Rule;
    8   import net.sourceforge.pmd.RuleSetNotFoundException;
    9   import test.net.sourceforge.pmd.testframework.SimpleAggregatorTst;
    10  import test.net.sourceforge.pmd.testframework.TestDescriptor;
    11
    12  public class UseAssertSameInsteadOfAssertTrueTest extends SimpleAggregatorTst {
    13      private Rule rule;
    14
    15      public void setUp() throws RuleSetNotFoundException {
    16          rule = findRule("junit", "UseAssertSameInsteadOfAssertTrue");
    17      }
    18
    19      public void testAll() throws Throwable {
    20
    21          runTests(new TestDescriptor[]{
    22              new TestDescriptor(TEST1, "assert true a == b", 1, rule),
    23              new TestDescriptor(TEST2, "assert true a != b", 1, rule),
    24              new TestDescriptor(TEST3, "assert false a == b", 1, rule),
    25              new TestDescriptor(TEST4, "assert false a != b", 1, rule),
    26              new TestDescriptor(TEST5, "skip assertTrue(x == null), UseAssertNullInsteadOfAssertTrue will pick those up", 0, rule),
    27          });
    28      }
    29
    30      private static final String TEST1 =
    31              "public class Foo {" + PMD.EOL +
    32              " public void test1() {" + PMD.EOL +
    33              "  assertTrue(a==b);" + PMD.EOL +
    34              " }" + PMD.EOL +
    35              "}";
    36
    37      private static final String TEST2 =
    38              "public class Foo {" + PMD.EOL +
    39              " public void test1() {" + PMD.EOL +
    40              "  assertTrue(a!=b);" + PMD.EOL +
    41              " }" + PMD.EOL +
    42              "}";
    43
    44      private static final String TEST3 =
    45              "public class Foo {" + PMD.EOL +
    46              " public void test1() {" + PMD.EOL +
    47              "  assertFalse(a==b);" + PMD.EOL +
    48              " }" + PMD.EOL +
    49              "}";
    50
    51      private static final String TEST4 =
    52              "public class Foo {" + PMD.EOL +
    53              " public void test1() {" + PMD.EOL +
    54              "  assertFalse(a!=b);" + PMD.EOL +
    55              " }" + PMD.EOL +
    56              "}";
    57
    58      private static final String TEST5 =
    59              "public class Foo {" + PMD.EOL +
    60              " public void test1() {" + PMD.EOL +
    61              "  assertFalse(a == null);" + PMD.EOL +
    62              " }" + PMD.EOL +
    63              "}";
    64
    65  }