    1   /***
    2    * BSD-style license; for more info see http://pmd.sourceforge.net/license.html
    3    */
    4   package test.net.sourceforge.pmd.rules.javabeans;
    5
    6   import net.sourceforge.pmd.PMD;
    7   import net.sourceforge.pmd.Rule;
    8   import test.net.sourceforge.pmd.testframework.SimpleAggregatorTst;
    9   import test.net.sourceforge.pmd.testframework.TestDescriptor;
    10
    11  public class MissingSerialVersionUIDTest extends SimpleAggregatorTst {
    12
    13      private Rule rule;
    14
    15      public void setUp() throws Exception {
    16          rule = findRule("javabeans", "MissingSerialVersionUID");
    17      }
    18
    19      public void testAll() {
    20          runTests(new TestDescriptor[]{
    21              new TestDescriptor(TEST1, "Happy case", 0, rule),
    22              new TestDescriptor(TEST2, "Simple failure case", 1, rule),
    23              new TestDescriptor(TEST3, "failure using java.io.Serializable", 1, rule),
    24              new TestDescriptor(TEST4, "implements Serializable and provides a serialVersionUID", 0, rule),
    25              new TestDescriptor(TEST5, "TEST5", 0, rule),
    26              new TestDescriptor(TEST6, "interface", 0, rule)
    27          });
    28      }
    29
    30      private static final String TEST1 =
    31              "public class Foo {" + PMD.EOL +
    32              "}";
    33
    34      private static final String TEST2 =
    35              "public class Foo implements Serializable {" + PMD.EOL +
    36              "}";
    37
    38      private static final String TEST3 =
    39              "public class Foo implements java.io.Serializable {" + PMD.EOL +
    40              "}";
    41
    42      private static final String TEST4 =
    43              "public class Foo implements Serializable {" + PMD.EOL +
    44              "public static final long serialVersionUID = 43L;" + PMD.EOL +
    45              "}";
    46
    47      private static final String TEST5 =
    48              "public class Foo implements java.io.Serializable {" + PMD.EOL +
    49              "public static final long serialVersionUID = 43L;" + PMD.EOL +
    50              "}";
    51
    52      private static final String TEST6 =
    53              "public interface Foo implements Bar{" + PMD.EOL +
    54              " void getName();" + PMD.EOL +
    55              "}";
    56  }