1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.commons.collections4.functors;
18
19 import static org.apache.commons.collections4.functors.AllPredicate.allPredicate;
20 import static org.junit.jupiter.api.Assertions.assertFalse;
21 import static org.junit.jupiter.api.Assertions.assertTrue;
22
23 import java.util.Collection;
24 import java.util.Collections;
25
26 import org.apache.commons.collections4.Predicate;
27 import org.junit.jupiter.api.Test;
28
29
30
31
32 @SuppressWarnings("boxing")
33 public class AllPredicateTest extends AbstractAnyAllOnePredicateTest<Integer> {
34
35
36
37
38 public AllPredicateTest() {
39 super(42);
40 }
41
42
43
44
45 @Override
46 protected final Predicate<Integer> getPredicateInstance(final Collection<Predicate<Integer>> predicates) {
47 return AllPredicate.allPredicate(predicates);
48 }
49
50
51
52
53 @Override
54 protected final Predicate<Integer> getPredicateInstance(final Predicate<? super Integer>... predicates) {
55 return AllPredicate.allPredicate(predicates);
56 }
57
58
59
60
61 @Test
62 public void testAllTrue() {
63 assertTrue(getPredicateInstance(true, true).evaluate(getTestValue()),
64 "multiple true predicates evaluated to false");
65 assertTrue(getPredicateInstance(true, true, true).evaluate(getTestValue()),
66 "multiple true predicates evaluated to false");
67 }
68
69
70
71
72 @SuppressWarnings({"unchecked"})
73 @Test
74 public void testEmptyArrayToGetInstance() {
75 assertTrue(getPredicateInstance(new Predicate[] {}).evaluate(null), "empty array not true");
76 }
77
78
79
80
81 @Test
82 public void testEmptyCollectionToGetInstance() {
83 final Predicate<Integer> allPredicate = getPredicateInstance(
84 Collections.<Predicate<Integer>>emptyList());
85 assertTrue(allPredicate.evaluate(getTestValue()), "empty collection not true");
86 }
87
88
89
90
91 @SuppressWarnings("unchecked")
92 @Test
93 public void testOneFalsePredicate() {
94
95
96 final Predicate<Integer> predicate = createMockPredicate(false);
97 assertFalse(allPredicate(predicate).evaluate(getTestValue()),
98 "single false predicate evaluated to true");
99 }
100
101
102
103
104 @SuppressWarnings("unchecked")
105 @Test
106 public void testOneTruePredicate() {
107
108
109 final Predicate<Integer> predicate = createMockPredicate(true);
110
111 assertTrue(allPredicate(predicate).evaluate(getTestValue()), "single true predicate evaluated to false");
112 }
113
114
115
116
117
118 @Test
119 public void testTrueAndFalseCombined() {
120 assertFalse(getPredicateInstance(false, null).evaluate(getTestValue()),
121 "false predicate evaluated to true");
122 assertFalse(getPredicateInstance(false, null, null).evaluate(getTestValue()),
123 "false predicate evaluated to true");
124 assertFalse(getPredicateInstance(true, false, null).evaluate(getTestValue()),
125 "false predicate evaluated to true");
126 assertFalse(getPredicateInstance(true, true, false).evaluate(getTestValue()),
127 "false predicate evaluated to true");
128 assertFalse(getPredicateInstance(true, true, false, null).evaluate(getTestValue()),
129 "false predicate evaluated to true");
130 }
131 }