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