1 package net.sourceforge.pmd.lang.java.rule.design;
2
3 import net.sourceforge.pmd.testframework.SimpleAggregatorTst;
4
5 import org.junit.Before;
6
7
8 public class ConfusingTernaryRuleTest extends SimpleAggregatorTst {
9
10 private static final String RULESET = "java-design";
11
12 @Before
13 public void setUp() {
14 addRule(RULESET, "ConfusingTernary");
15 }
16
17 /*
18 public class BadTernaries {
19 public static void main(String[] args) {
20 int i = 0;
21 int j = 1;
22 int k = 2;
23 boolean x = true;
24 boolean y = false;
25 boolean z = true;
26
27 // flag all of these, lines 11 - 42:
28 if (i != 11) {a();} else {b();}
29 if (i != 12 && j != 0) {a();} else {b();}
30 if (i != 13 || j != 0) {a();} else {b();}
31 if (i != 14 && j != 0 && k != 0) {a();} else {b();}
32 if (i != 15 || j != 0 || k != 0) {a();} else {b();}
33 if (i != 16) {a();} else if (i != j) {b();} else{c();}
34 if (i != 17) {a();} else if (i == j) {b();} else{c();}
35 if (i == 18) {a();} else if (i != j) {b();} else{c();}
36 x = (!y ? x : y);
37 x = (!(x && y) ? y : z);
38 x = (!(x || y) ? y : z);
39 x = ((!x && !y) ? y : z);
40 x = ((!x || !y) ? y : z);
41 if (i != 24 && !x) {a();} else {b();}
42 if (i != 25 || !x) {a();} else {b();}
43 if (i != 26 && j != 0 && !y) {a();} else {b();}
44 if (i != 27 || j != 0 || !y) {a();} else {b();}
45 if (i != 28) {a();} else if (!x) {b();} else{c();}
46 if (i != 29) {a();} else if (x) {b();} else{c();}
47 if (i == 30) {a();} else if (!x) {b();} else{c();}
48 x = !(c() == y) ? y : !z;
49 if (!c()) {a();} else {b();}
50 if (c() != x) {a();} else {b();}
51 if (!c() != x) {a();} else {b();}
52 if (!c() != !x) {a();} else {b();}
53 if ((i != 36) || !(j == 0)) {a();} else {b();}
54 if ((i != 37) || !(x ? y : z)) {a();} else {b();}
55 if ((i != 38)) {a();} else {b();}
56 if (i != 39 || (j != 0 || k != 0)) {a();} else {b();}
57 if (i != 40 && (j != 0 && k != 0)) {a();} else {b();}
58 if (!x && (j != 41 && k != 0)) {a();} else {b();}
59 if (((x != y)) || !(x)) { a(); } else { b(); }
60
61 // don't flag these:
62 if (i != 0) {a();}
63 if (!x) {a();}
64 if (i == 0) {a();} else {b();}
65 if (i == 0 && j != 0) {a();} else {b();}
66 if (i == 0 || j != 0) {a();} else {b();}
67 if (i == 0 && !x) {a();} else {b();}
68 if (x) {a();} else {b();}
69 if (x ? y : !z) {a();} else {b();}
70 if (c() == !x) {a();} else {b();}
71 if (c() ? !x : !c()) {a();} else {b();}
72 if (!x && d() instanceof String) {a();} else {b();}
73 if (!x && (d() instanceof String)) {a();} else {b();}
74 }
75
76 private static void a() { }
77 private static void b() { }
78 private static boolean c() { return true; }
79 private static Object d() { return null; }
80 }
81
82 */
83
84 public static junit.framework.Test suite() {
85 return new junit.framework.JUnit4TestAdapter(ConfusingTernaryRuleTest.class);
86 }
87 }