    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 JUnitAssertionsShouldIncludeMessageTest extends SimpleAggregatorTst {
    13
    14      private Rule rule;
    15
    16      public void setUp() throws RuleSetNotFoundException {
    17          rule = findRule("junit", "JUnitAssertionsShouldIncludeMessage");
    18      }
    19
    20      public void testAll() {
    21          runTests(new TestDescriptor[]{
    22              new TestDescriptor(TEST1, "assertEquals ok", 0, rule),
    23              new TestDescriptor(TEST2, "assertEquals bad", 1, rule),
    24              new TestDescriptor(TEST3, "assertTrue ok", 0, rule),
    25              new TestDescriptor(TEST4, "assertTrue bad", 1, rule),
    26              new TestDescriptor(TEST5, "assertNull OK", 0, rule),
    27              new TestDescriptor(TEST6, "assertNull bad", 1, rule),
    28              new TestDescriptor(TEST7, "assertSame OK", 0, rule),
    29              new TestDescriptor(TEST8, "assertSame badd", 1, rule),
    30              new TestDescriptor(TEST9, "assertNotNull OK", 0, rule),
    31              new TestDescriptor(TEST10, "assertNotNull bad", 1, rule),
    32              new TestDescriptor(TEST11, "find that pesky bug", 0, rule),
    33              new TestDescriptor(TEST12, "assertFalse ok", 0, rule),
    34              new TestDescriptor(TEST13, "assertFalse bad", 1, rule),
    35          });
    36      }
    37
    38      private static final String TEST1 =
    39              "public class Foo {" + PMD.EOL +
    40              " public void test1() {" + PMD.EOL +
    41              "  assertEquals(\"1 == 1\", 1, 1);" + PMD.EOL +
    42              " }" + PMD.EOL +
    43              "}";
    44
    45      private static final String TEST2 =
    46              "public class Foo {" + PMD.EOL +
    47              " public void test1() {" + PMD.EOL +
    48              "  assertEquals(1, 1);" + PMD.EOL +
    49              " }" + PMD.EOL +
    50              "}";
    51
    52      private static final String TEST3 =
    53              "public class Foo {" + PMD.EOL +
    54              " public void test1() {" + PMD.EOL +
    55              "  assertTrue(\"foo\", \"foo\".equals(\"foo\"));" + PMD.EOL +
    56              " }" + PMD.EOL +
    57              "}";
    58
    59      private static final String TEST4 =
    60              "public class Foo {" + PMD.EOL +
    61              " public void test1() {" + PMD.EOL +
    62              "  assertTrue(\"foo\".equals(\"foo\"));" + PMD.EOL +
    63              " }" + PMD.EOL +
    64              "}";
    65
    66      private static final String TEST5 =
    67              "public class Foo {" + PMD.EOL +
    68              " public void test1() {" + PMD.EOL +
    69              "  assertNull(\"it's not null\", null);" + PMD.EOL +
    70              " }" + PMD.EOL +
    71              "}";
    72
    73      private static final String TEST6 =
    74              "public class Foo {" + PMD.EOL +
    75              " public void test1() {" + PMD.EOL +
    76              "  assertNull(null);" + PMD.EOL +
    77              " }" + PMD.EOL +
    78              "}";
    79
    80      private static final String TEST7 =
    81              "public class Foo {" + PMD.EOL +
    82              " public void test1() {" + PMD.EOL +
    83              "  assertSame(\"not same!\", null, null);" + PMD.EOL +
    84              " }" + PMD.EOL +
    85              "}";
    86
    87      private static final String TEST8 =
    88              "public class Foo {" + PMD.EOL +
    89              " public void test1() {" + PMD.EOL +
    90              "  assertSame(null, null);" + PMD.EOL +
    91              " }" + PMD.EOL +
    92              "}";
    93
    94      private static final String TEST9 =
    95              "public class Foo {" + PMD.EOL +
    96              " public void test1() {" + PMD.EOL +
    97              "  assertNotNull(\"foo\", null);" + PMD.EOL +
    98              " }" + PMD.EOL +
    99              "}";
    100
    101     private static final String TEST10 =
    102             "public class Foo {" + PMD.EOL +
    103             " public void test1() {" + PMD.EOL +
    104             "  assertNotNull(null);" + PMD.EOL +
    105             " }" + PMD.EOL +
    106             "}";
    107
    108     private static final String TEST11 =
    109             "public class Foo {" + PMD.EOL +
    110             " public void test1() {" + PMD.EOL +
    111             "  this.test1(\"foo\");" + PMD.EOL +
    112             " }" + PMD.EOL +
    113             "}";
    114
    115     private static final String TEST12 =
    116             "public class Foo {" + PMD.EOL +
    117             " public void testBar() {" + PMD.EOL +
    118             "  assertFalse(\"foo!\", \"foo\".equals(\"foo\"));" + PMD.EOL +
    119             " }" + PMD.EOL +
    120             "}";
    121
    122     private static final String TEST13 =
    123             "public class Foo {" + PMD.EOL +
    124             " public void testBar() {" + PMD.EOL +
    125             "  assertFalse(\"foo\".equals(\"foo\"));" + PMD.EOL +
    126             " }" + PMD.EOL +
    127             "}";
    128
    129 }