View Javadoc
1 package test.net.sourceforge.pmd.rules.junit; 2 3 import net.sourceforge.pmd.PMD; 4 import net.sourceforge.pmd.Rule; 5 import net.sourceforge.pmd.rules.XPathRule; 6 import test.net.sourceforge.pmd.rules.RuleTst; 7 8 public class JUnitSpellingRuleTest extends RuleTst { 9 10 private static final String TEST1 = 11 "public class JUnitSpelling1 {" + PMD.EOL + 12 " // these should be 'setUp'" + PMD.EOL + 13 " public void setup() {}" + PMD.EOL + 14 " public void SetUp() {}" + PMD.EOL + 15 "}"; 16 17 private static final String TEST2 = 18 "public class JUnitSpelling2 {" + PMD.EOL + 19 " // these should be 'tearDown'" + PMD.EOL + 20 " public void TearDown() {}" + PMD.EOL + 21 " public void teardown() {}" + PMD.EOL + 22 "}"; 23 24 private static final String TEST3 = 25 "public class JUnitSpelling3 {" + PMD.EOL + 26 " // these are OK" + PMD.EOL + 27 " public void setUp() {}" + PMD.EOL + 28 " public void tearDown() {}" + PMD.EOL + 29 "}"; 30 31 private static final String TEST4 = 32 "public class JUnitSpelling4 {" + PMD.EOL + 33 " // these are OK" + PMD.EOL + 34 " public void utility() {}" + PMD.EOL + 35 " public void foobr() {}" + PMD.EOL + 36 "}"; 37 38 private static final String TEST5 = 39 "public class JUnitSpelling5 {" + PMD.EOL + 40 " public void setup(String x) {}" + PMD.EOL + 41 "}"; 42 43 private Rule rule; 44 45 public void setUp() { 46 rule = new XPathRule(); 47 rule.addProperty("xpath", "//MethodDeclarator[(not(@Image = 'setUp') and translate(@Image, 'SETuP', 'setUp') = 'setUp') or (not(@Image = 'tearDown') and translate(@Image, 'TEARdOWN', 'tearDown') = 'tearDown')][FormalParameters[count(*) = 0]]"); 48 } 49 50 public void testSetupMisspellings1() throws Throwable { 51 runTestFromString(TEST1, 2, rule); 52 } 53 public void testTeardownMisspellings() throws Throwable { 54 runTestFromString(TEST2, 2, rule); 55 } 56 public void testMethodsSpelledOK() throws Throwable { 57 runTestFromString(TEST3, 0, rule); 58 } 59 public void testUnrelatedMethods() throws Throwable { 60 runTestFromString(TEST4, 0, rule); 61 } 62 public void testMethodWithParams() throws Throwable { 63 runTestFromString(TEST5, 0, rule); 64 } 65 }

This page was automatically generated by Maven