pmd: cleanup design test cases
This commit is contained in:
1 parent
3bf8eb9d1f
commit
3ce242c179
5 files changed
+75
-150
No files matched your search
-87
@@ -1,87 +0,0 @@
|
||||
package net.sourceforge.pmd.lang.java.rule.design;
|
||||
|
||||
import net.sourceforge.pmd.testframework.SimpleAggregatorTst;
|
||||
|
||||
import org.junit.Before;
|
||||
|
||||
|
||||
public class ConfusingTernaryRuleTest extends SimpleAggregatorTst {
|
||||
|
||||
private static final String RULESET = "java-design";
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
addRule(RULESET, "ConfusingTernary");
|
||||
}
|
||||
|
||||
/*
|
||||
public class BadTernaries {
|
||||
public static void main(String[] args) {
|
||||
int i = 0;
|
||||
int j = 1;
|
||||
int k = 2;
|
||||
boolean x = true;
|
||||
boolean y = false;
|
||||
boolean z = true;
|
||||
|
||||
// flag all of these, lines 11 - 42:
|
||||
if (i != 11) {a();} else {b();}
|
||||
if (i != 12 && j != 0) {a();} else {b();}
|
||||
if (i != 13 || j != 0) {a();} else {b();}
|
||||
if (i != 14 && j != 0 && k != 0) {a();} else {b();}
|
||||
if (i != 15 || j != 0 || k != 0) {a();} else {b();}
|
||||
if (i != 16) {a();} else if (i != j) {b();} else{c();}
|
||||
if (i != 17) {a();} else if (i == j) {b();} else{c();}
|
||||
if (i == 18) {a();} else if (i != j) {b();} else{c();}
|
||||
x = (!y ? x : y);
|
||||
x = (!(x && y) ? y : z);
|
||||
x = (!(x || y) ? y : z);
|
||||
x = ((!x && !y) ? y : z);
|
||||
x = ((!x || !y) ? y : z);
|
||||
if (i != 24 && !x) {a();} else {b();}
|
||||
if (i != 25 || !x) {a();} else {b();}
|
||||
if (i != 26 && j != 0 && !y) {a();} else {b();}
|
||||
if (i != 27 || j != 0 || !y) {a();} else {b();}
|
||||
if (i != 28) {a();} else if (!x) {b();} else{c();}
|
||||
if (i != 29) {a();} else if (x) {b();} else{c();}
|
||||
if (i == 30) {a();} else if (!x) {b();} else{c();}
|
||||
x = !(c() == y) ? y : !z;
|
||||
if (!c()) {a();} else {b();}
|
||||
if (c() != x) {a();} else {b();}
|
||||
if (!c() != x) {a();} else {b();}
|
||||
if (!c() != !x) {a();} else {b();}
|
||||
if ((i != 36) || !(j == 0)) {a();} else {b();}
|
||||
if ((i != 37) || !(x ? y : z)) {a();} else {b();}
|
||||
if ((i != 38)) {a();} else {b();}
|
||||
if (i != 39 || (j != 0 || k != 0)) {a();} else {b();}
|
||||
if (i != 40 && (j != 0 && k != 0)) {a();} else {b();}
|
||||
if (!x && (j != 41 && k != 0)) {a();} else {b();}
|
||||
if (((x != y)) || !(x)) { a(); } else { b(); }
|
||||
|
||||
// don't flag these:
|
||||
if (i != 0) {a();}
|
||||
if (!x) {a();}
|
||||
if (i == 0) {a();} else {b();}
|
||||
if (i == 0 && j != 0) {a();} else {b();}
|
||||
if (i == 0 || j != 0) {a();} else {b();}
|
||||
if (i == 0 && !x) {a();} else {b();}
|
||||
if (x) {a();} else {b();}
|
||||
if (x ? y : !z) {a();} else {b();}
|
||||
if (c() == !x) {a();} else {b();}
|
||||
if (c() ? !x : !c()) {a();} else {b();}
|
||||
if (!x && d() instanceof String) {a();} else {b();}
|
||||
if (!x && (d() instanceof String)) {a();} else {b();}
|
||||
}
|
||||
|
||||
private static void a() { }
|
||||
private static void b() { }
|
||||
private static boolean c() { return true; }
|
||||
private static Object d() { return null; }
|
||||
}
|
||||
|
||||
*/
|
||||
|
||||
public static junit.framework.Test suite() {
|
||||
return new junit.framework.JUnit4TestAdapter(ConfusingTernaryRuleTest.class);
|
||||
}
|
||||
}
|
||||
-24
@@ -1,24 +0,0 @@
|
||||
/**
|
||||
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html
|
||||
*/
|
||||
package net.sourceforge.pmd.lang.java.rule.design;
|
||||
|
||||
import net.sourceforge.pmd.testframework.SimpleAggregatorTst;
|
||||
|
||||
import org.junit.Before;
|
||||
|
||||
|
||||
public class ConstructorCallsOverridableMethodTest extends SimpleAggregatorTst {
|
||||
|
||||
private static final String RULESET = "java-design";
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
addRule(RULESET, "ConstructorCallsOverridableMethod");
|
||||
}
|
||||
|
||||
public static junit.framework.Test suite() {
|
||||
return new junit.framework.JUnit4TestAdapter(
|
||||
ConstructorCallsOverridableMethodTest.class);
|
||||
}
|
||||
}
|
||||
@@ -28,11 +28,13 @@ public class DesignRulesTest extends SimpleAggregatorTst {
|
||||
addRule(RULESET, "ClassWithOnlyPrivateConstructorsShouldBeFinal");
|
||||
addRule(RULESET, "CloseResource");
|
||||
addRule(RULESET, "CompareObjectsWithEquals");
|
||||
addRule(RULESET, "ConfusingTernary");
|
||||
addRule(RULESET, "ConstructorCallsOverridableMethod");
|
||||
addRule(RULESET, "DefaultLabelNotLastInSwitchStmt");
|
||||
addRule(RULESET, "EmptyMethodInAbstractClassShouldBeAbstract");
|
||||
addRule(RULESET, "EqualsNull");
|
||||
addRule(RULESET, "FinalFieldCouldBeStatic");
|
||||
addRule(RULESET, "FieldDeclarationsShouldBeAtStartOfClass");
|
||||
addRule(RULESET, "FinalFieldCouldBeStatic");
|
||||
addRule(RULESET, "GodClass");
|
||||
addRule(RULESET, "IdempotentOperations");
|
||||
addRule(RULESET, "ImmutableField");
|
||||
@@ -44,6 +46,7 @@ public class DesignRulesTest extends SimpleAggregatorTst {
|
||||
addRule(RULESET, "NonStaticInitializer");
|
||||
addRule(RULESET, "NonThreadSafeSingleton");
|
||||
addRule(RULESET, "OptimizableToArrayCall");
|
||||
//addRule(RULESET, "PositionalIteratorRule"); This rule does not yes exist
|
||||
addRule(RULESET, "PositionLiteralsFirstInComparisons");
|
||||
addRule(RULESET, "PreserveStackTrace");
|
||||
addRule(RULESET, "ReturnEmptyArrayRatherThanNull");
|
||||
@@ -55,7 +58,8 @@ public class DesignRulesTest extends SimpleAggregatorTst {
|
||||
addRule(RULESET, "SwitchDensity");
|
||||
addRule(RULESET, "SwitchStmtsShouldHaveDefault");
|
||||
addRule(RULESET, "TooFewBranchesForASwitchStatement");
|
||||
// addRule(RULESET, "TooManyHttpFilter.xml");
|
||||
//addRule(RULESET, "TooManyHttpFilter"); This rule does not yet exist
|
||||
//addRule(RULESET, "UncommentedEmptyConstructor"); See UncommentedEmptyConstructorRuleTest.java
|
||||
addRule(RULESET, "UncommentedEmptyMethod");
|
||||
addRule(RULESET, "UnnecessaryLocalBeforeReturn");
|
||||
addRule(RULESET, "UnsynchronizedStaticDateFormatter");
|
||||
|
||||
-37
@@ -1,37 +0,0 @@
|
||||
/**
|
||||
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html
|
||||
*/
|
||||
package net.sourceforge.pmd.lang.java.rule.design;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import net.sourceforge.pmd.Rule;
|
||||
import net.sourceforge.pmd.testframework.SimpleAggregatorTst;
|
||||
import net.sourceforge.pmd.testframework.TestDescriptor;
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @author Romain PELISSE, belaran@gmail.com
|
||||
*
|
||||
*/
|
||||
public class TooManyHttpFilterTest extends SimpleAggregatorTst {
|
||||
|
||||
private Rule rule;
|
||||
private TestDescriptor[] tests;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
// rule = findRule("design", "TooManyHttpFilter");
|
||||
// tests = extractTestsFromXml(rule);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDefault() {
|
||||
// runTests(tests);
|
||||
}
|
||||
public static junit.framework.Test suite() {
|
||||
return new junit.framework.JUnit4TestAdapter(TooManyHttpFilterTest.class);
|
||||
}
|
||||
}
|
||||
+69
@@ -56,4 +56,73 @@ public class Foo {
|
||||
}
|
||||
]]></code>
|
||||
</test-code>
|
||||
<test-code>
|
||||
<description>A couple of bad and good cases</description>
|
||||
<expected-problems>34</expected-problems>
|
||||
<code><![CDATA[
|
||||
public class BadTernaries {
|
||||
public static void main(String[] args) {
|
||||
int i = 0;
|
||||
int j = 1;
|
||||
int k = 2;
|
||||
boolean x = true;
|
||||
boolean y = false;
|
||||
boolean z = true;
|
||||
|
||||
// flag all of these, lines 11 - 42:
|
||||
if (i != 11) {a();} else {b();}
|
||||
if (i != 12 && j != 0) {a();} else {b();}
|
||||
if (i != 13 || j != 0) {a();} else {b();}
|
||||
if (i != 14 && j != 0 && k != 0) {a();} else {b();}
|
||||
if (i != 15 || j != 0 || k != 0) {a();} else {b();}
|
||||
if (i != 16) {a();} else if (i != j) {b();} else{c();}
|
||||
if (i != 17) {a();} else if (i == j) {b();} else{c();}
|
||||
if (i == 18) {a();} else if (i != j) {b();} else{c();}
|
||||
x = (!y ? x : y);
|
||||
x = (!(x && y) ? y : z);
|
||||
x = (!(x || y) ? y : z);
|
||||
x = ((!x && !y) ? y : z);
|
||||
x = ((!x || !y) ? y : z);
|
||||
if (i != 24 && !x) {a();} else {b();}
|
||||
if (i != 25 || !x) {a();} else {b();}
|
||||
if (i != 26 && j != 0 && !y) {a();} else {b();}
|
||||
if (i != 27 || j != 0 || !y) {a();} else {b();}
|
||||
if (i != 28) {a();} else if (!x) {b();} else{c();}
|
||||
if (i != 29) {a();} else if (x) {b();} else{c();}
|
||||
if (i == 30) {a();} else if (!x) {b();} else{c();}
|
||||
x = !(c() == y) ? y : !z;
|
||||
if (!c()) {a();} else {b();}
|
||||
if (c() != x) {a();} else {b();}
|
||||
if (!c() != x) {a();} else {b();}
|
||||
if (!c() != !x) {a();} else {b();}
|
||||
if ((i != 36) || !(j == 0)) {a();} else {b();}
|
||||
if ((i != 37) || !(x ? y : z)) {a();} else {b();}
|
||||
if ((i != 38)) {a();} else {b();}
|
||||
if (i != 39 || (j != 0 || k != 0)) {a();} else {b();}
|
||||
if (i != 40 && (j != 0 && k != 0)) {a();} else {b();}
|
||||
if (!x && (j != 41 && k != 0)) {a();} else {b();}
|
||||
if (((x != y)) || !(x)) { a(); } else { b(); }
|
||||
|
||||
// don't flag these:
|
||||
if (i != 0) {a();}
|
||||
if (!x) {a();}
|
||||
if (i == 0) {a();} else {b();}
|
||||
if (i == 0 && j != 0) {a();} else {b();}
|
||||
if (i == 0 || j != 0) {a();} else {b();}
|
||||
if (i == 0 && !x) {a();} else {b();}
|
||||
if (x) {a();} else {b();}
|
||||
if (x ? y : !z) {a();} else {b();}
|
||||
if (c() == !x) {a();} else {b();}
|
||||
if (c() ? !x : !c()) {a();} else {b();}
|
||||
if (!x && d() instanceof String) {a();} else {b();}
|
||||
if (!x && (d() instanceof String)) {a();} else {b();}
|
||||
}
|
||||
|
||||
private static void a() { }
|
||||
private static void b() { }
|
||||
private static boolean c() { return true; }
|
||||
private static Object d() { return null; }
|
||||
}
|
||||
]]></code>
|
||||
</test-code>
|
||||
</test-data>
|
||||
Reference in new issue
Block a user