1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package ch.elca.el4j.tests.util.codingsupport;
19
20 import static org.junit.Assert.fail;
21
22 import java.util.ArrayList;
23 import java.util.Collection;
24 import java.util.List;
25
26 import org.junit.Test;
27
28 import ch.elca.el4j.util.codingsupport.Reject;
29 import ch.elca.el4j.util.codingsupport.annotations.FindBugsSuppressWarnings;
30
31
32
33
34
35
36
37
38
39
40
41 public class RejectTest {
42
43
44
45
46 @Test
47 public void testIfNull() {
48 try {
49 Reject.ifNull(null);
50 fail("Bad implementatino of Reject.isNull(null)");
51 } catch (Exception e) { }
52 try {
53 Reject.ifNull(new Object());
54 } catch (Exception e) {
55 fail("Bad implementatino of Reject.isNull(new Object())");
56 }
57 }
58
59
60
61
62
63 @Test
64 public void testIfNull2() {
65 try {
66 Reject.ifNull(null, IllegalArgumentException.class, "My String");
67 fail("Bad implementation of Reject.isNull()");
68 } catch (IllegalArgumentException e) { }
69 try {
70 Reject.ifEmpty("", IllegalArgumentException.class, "My String");
71 fail("Bad implementation of Reject.isEmpty()");
72 } catch (IllegalArgumentException e) { }
73 try {
74 Reject.ifCondition(true, IllegalArgumentException.class,
75 "My String");
76 fail("Bad implementation of Reject.ifCondition()");
77 } catch (IllegalArgumentException e) { }
78
79 try {
80 Reject.ifNull(new Object(), IllegalArgumentException.class, "");
81 } catch (IllegalArgumentException e) {
82 fail("Bad implementation of Reject.isNull(new Object())");
83 }
84 }
85
86
87
88
89 @Test
90 @SuppressWarnings("unchecked")
91 @FindBugsSuppressWarnings(value = "DE_MIGHT_IGNORE",
92 justification = "Exception handling not important as test is supposed to fail.")
93 public void testIfEmptyCollection() {
94 try {
95 Reject.ifEmpty((List) null);
96 fail("Bad implementatino of Reject.isEmpty((List) null)");
97 } catch (Exception e) { }
98 ArrayList list = new ArrayList();
99 try {
100 Reject.ifEmpty(list);
101 fail("Bad implementatino of Reject.isEmpty(new ArrayList())");
102 } catch (Exception e) { }
103 try {
104 list.add(new Object());
105 Reject.ifEmpty(list);
106 } catch (Exception e) {
107 fail("Bad implementatino of Reject.isEmpty('nonempty list')");
108 }
109 }
110
111
112
113
114 @Test
115 public void testIfEmptyString() {
116 try {
117 Reject.ifEmpty((String) null);
118 fail("Bad implementatino of Reject.isEmpty((String) null)");
119 } catch (Exception e) { }
120 try {
121 Reject.ifEmpty(" ");
122 fail("Bad implementatino of Reject.isEmpty(\" \")");
123 } catch (Exception e) { }
124 try {
125 Reject.ifEmpty(" test");
126 } catch (Exception e) {
127 fail("Bad implementatino of Reject.isEmpty(\" test\")");
128 }
129 }
130 }
131