mirror of
https://github.com/apache/commons-collections.git
synced 2025-02-14 22:16:37 +00:00
Simplify several assertions in CollectionUtilsTest.
Also remove use of Integer constructor as it has been deprecated since Java 9.
This commit is contained in:
parent
4d4caa6a92
commit
e22691f810
@ -19,6 +19,7 @@ package org.apache.commons.collections4;
|
|||||||
import static org.apache.commons.collections4.functors.EqualPredicate.equalPredicate;
|
import static org.apache.commons.collections4.functors.EqualPredicate.equalPredicate;
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertFalse;
|
import static org.junit.Assert.assertFalse;
|
||||||
|
import static org.junit.Assert.assertNotSame;
|
||||||
import static org.junit.Assert.assertNull;
|
import static org.junit.Assert.assertNull;
|
||||||
import static org.junit.Assert.assertSame;
|
import static org.junit.Assert.assertSame;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
@ -304,19 +305,19 @@ public class CollectionUtilsTest extends MockTestCase {
|
|||||||
multiples.add("3");
|
multiples.add("3");
|
||||||
multiples.add("1");
|
multiples.add("1");
|
||||||
|
|
||||||
assertTrue("containsAll({1},{1,3}) should return false.", !CollectionUtils.containsAll(one, odds));
|
assertFalse("containsAll({1},{1,3}) should return false.", CollectionUtils.containsAll(one, odds));
|
||||||
assertTrue("containsAll({1,3},{1}) should return true.", CollectionUtils.containsAll(odds, one));
|
assertTrue("containsAll({1,3},{1}) should return true.", CollectionUtils.containsAll(odds, one));
|
||||||
assertTrue("containsAll({3},{1,3}) should return false.", !CollectionUtils.containsAll(three, odds));
|
assertFalse("containsAll({3},{1,3}) should return false.", CollectionUtils.containsAll(three, odds));
|
||||||
assertTrue("containsAll({1,3},{3}) should return true.", CollectionUtils.containsAll(odds, three));
|
assertTrue("containsAll({1,3},{3}) should return true.", CollectionUtils.containsAll(odds, three));
|
||||||
assertTrue("containsAll({2},{2}) should return true.", CollectionUtils.containsAll(two, two));
|
assertTrue("containsAll({2},{2}) should return true.", CollectionUtils.containsAll(two, two));
|
||||||
assertTrue("containsAll({1,3},{1,3}) should return true.", CollectionUtils.containsAll(odds, odds));
|
assertTrue("containsAll({1,3},{1,3}) should return true.", CollectionUtils.containsAll(odds, odds));
|
||||||
|
|
||||||
assertTrue("containsAll({2},{1,3}) should return false.", !CollectionUtils.containsAll(two, odds));
|
assertFalse("containsAll({2},{1,3}) should return false.", CollectionUtils.containsAll(two, odds));
|
||||||
assertTrue("containsAll({1,3},{2}) should return false.", !CollectionUtils.containsAll(odds, two));
|
assertFalse("containsAll({1,3},{2}) should return false.", CollectionUtils.containsAll(odds, two));
|
||||||
assertTrue("containsAll({1},{3}) should return false.", !CollectionUtils.containsAll(one, three));
|
assertFalse("containsAll({1},{3}) should return false.", CollectionUtils.containsAll(one, three));
|
||||||
assertTrue("containsAll({3},{1}) should return false.", !CollectionUtils.containsAll(three, one));
|
assertFalse("containsAll({3},{1}) should return false.", CollectionUtils.containsAll(three, one));
|
||||||
assertTrue("containsAll({1,3},{}) should return true.", CollectionUtils.containsAll(odds, empty));
|
assertTrue("containsAll({1,3},{}) should return true.", CollectionUtils.containsAll(odds, empty));
|
||||||
assertTrue("containsAll({},{1,3}) should return false.", !CollectionUtils.containsAll(empty, odds));
|
assertFalse("containsAll({},{1,3}) should return false.", CollectionUtils.containsAll(empty, odds));
|
||||||
assertTrue("containsAll({},{}) should return true.", CollectionUtils.containsAll(empty, empty));
|
assertTrue("containsAll({},{}) should return true.", CollectionUtils.containsAll(empty, empty));
|
||||||
|
|
||||||
assertTrue("containsAll({1,3},{1,3,1}) should return true.", CollectionUtils.containsAll(odds, multiples));
|
assertTrue("containsAll({1,3},{1,3,1}) should return true.", CollectionUtils.containsAll(odds, multiples));
|
||||||
@ -343,13 +344,13 @@ public class CollectionUtilsTest extends MockTestCase {
|
|||||||
assertTrue("containsAny({2},{2}) should return true.", CollectionUtils.containsAny(two, two));
|
assertTrue("containsAny({2},{2}) should return true.", CollectionUtils.containsAny(two, two));
|
||||||
assertTrue("containsAny({1,3},{1,3}) should return true.", CollectionUtils.containsAny(odds, odds));
|
assertTrue("containsAny({1,3},{1,3}) should return true.", CollectionUtils.containsAny(odds, odds));
|
||||||
|
|
||||||
assertTrue("containsAny({2},{1,3}) should return false.", !CollectionUtils.containsAny(two, odds));
|
assertFalse("containsAny({2},{1,3}) should return false.", CollectionUtils.containsAny(two, odds));
|
||||||
assertTrue("containsAny({1,3},{2}) should return false.", !CollectionUtils.containsAny(odds, two));
|
assertFalse("containsAny({1,3},{2}) should return false.", CollectionUtils.containsAny(odds, two));
|
||||||
assertTrue("containsAny({1},{3}) should return false.", !CollectionUtils.containsAny(one, three));
|
assertFalse("containsAny({1},{3}) should return false.", CollectionUtils.containsAny(one, three));
|
||||||
assertTrue("containsAny({3},{1}) should return false.", !CollectionUtils.containsAny(three, one));
|
assertFalse("containsAny({3},{1}) should return false.", CollectionUtils.containsAny(three, one));
|
||||||
assertTrue("containsAny({1,3},{}) should return false.", !CollectionUtils.containsAny(odds, empty));
|
assertFalse("containsAny({1,3},{}) should return false.", CollectionUtils.containsAny(odds, empty));
|
||||||
assertTrue("containsAny({},{1,3}) should return false.", !CollectionUtils.containsAny(empty, odds));
|
assertFalse("containsAny({},{1,3}) should return false.", CollectionUtils.containsAny(empty, odds));
|
||||||
assertTrue("containsAny({},{}) should return false.", !CollectionUtils.containsAny(empty, empty));
|
assertFalse("containsAny({},{}) should return false.", CollectionUtils.containsAny(empty, empty));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = NullPointerException.class)
|
@Test(expected = NullPointerException.class)
|
||||||
@ -400,13 +401,13 @@ public class CollectionUtilsTest extends MockTestCase {
|
|||||||
assertTrue("containsAny({2},{2}) should return true.", CollectionUtils.containsAny(two, twoArr));
|
assertTrue("containsAny({2},{2}) should return true.", CollectionUtils.containsAny(two, twoArr));
|
||||||
assertTrue("containsAny({1,3},{1,3}) should return true.", CollectionUtils.containsAny(odds, oddsArr));
|
assertTrue("containsAny({1,3},{1,3}) should return true.", CollectionUtils.containsAny(odds, oddsArr));
|
||||||
|
|
||||||
assertTrue("containsAny({2},{1,3}) should return false.", !CollectionUtils.containsAny(two, oddsArr));
|
assertFalse("containsAny({2},{1,3}) should return false.", CollectionUtils.containsAny(two, oddsArr));
|
||||||
assertTrue("containsAny({1,3},{2}) should return false.", !CollectionUtils.containsAny(odds, twoArr));
|
assertFalse("containsAny({1,3},{2}) should return false.", CollectionUtils.containsAny(odds, twoArr));
|
||||||
assertTrue("containsAny({1},{3}) should return false.", !CollectionUtils.containsAny(one, threeArr));
|
assertFalse("containsAny({1},{3}) should return false.", CollectionUtils.containsAny(one, threeArr));
|
||||||
assertTrue("containsAny({3},{1}) should return false.", !CollectionUtils.containsAny(three, oneArr));
|
assertFalse("containsAny({3},{1}) should return false.", CollectionUtils.containsAny(three, oneArr));
|
||||||
assertTrue("containsAny({1,3},{}) should return false.", !CollectionUtils.containsAny(odds, emptyArr));
|
assertFalse("containsAny({1,3},{}) should return false.", CollectionUtils.containsAny(odds, emptyArr));
|
||||||
assertTrue("containsAny({},{1,3}) should return false.", !CollectionUtils.containsAny(empty, oddsArr));
|
assertFalse("containsAny({},{1,3}) should return false.", CollectionUtils.containsAny(empty, oddsArr));
|
||||||
assertTrue("containsAny({},{}) should return false.", !CollectionUtils.containsAny(empty, emptyArr));
|
assertFalse("containsAny({},{}) should return false.", CollectionUtils.containsAny(empty, emptyArr));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = NullPointerException.class)
|
@Test(expected = NullPointerException.class)
|
||||||
@ -601,47 +602,47 @@ public class CollectionUtilsTest extends MockTestCase {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testIsSubCollection() {
|
public void testIsSubCollection() {
|
||||||
assertTrue(!CollectionUtils.isSubCollection(collectionA, collectionC));
|
assertFalse(CollectionUtils.isSubCollection(collectionA, collectionC));
|
||||||
assertTrue(!CollectionUtils.isSubCollection(collectionC, collectionA));
|
assertFalse(CollectionUtils.isSubCollection(collectionC, collectionA));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testIsSubCollection2() {
|
public void testIsSubCollection2() {
|
||||||
final Collection<Integer> c = new ArrayList<>();
|
final Collection<Integer> c = new ArrayList<>();
|
||||||
assertTrue(CollectionUtils.isSubCollection(c, collectionA));
|
assertTrue(CollectionUtils.isSubCollection(c, collectionA));
|
||||||
assertTrue(!CollectionUtils.isSubCollection(collectionA, c));
|
assertFalse(CollectionUtils.isSubCollection(collectionA, c));
|
||||||
c.add(1);
|
c.add(1);
|
||||||
assertTrue(CollectionUtils.isSubCollection(c, collectionA));
|
assertTrue(CollectionUtils.isSubCollection(c, collectionA));
|
||||||
assertTrue(!CollectionUtils.isSubCollection(collectionA, c));
|
assertFalse(CollectionUtils.isSubCollection(collectionA, c));
|
||||||
c.add(2);
|
c.add(2);
|
||||||
assertTrue(CollectionUtils.isSubCollection(c, collectionA));
|
assertTrue(CollectionUtils.isSubCollection(c, collectionA));
|
||||||
assertTrue(!CollectionUtils.isSubCollection(collectionA, c));
|
assertFalse(CollectionUtils.isSubCollection(collectionA, c));
|
||||||
c.add(2);
|
c.add(2);
|
||||||
assertTrue(CollectionUtils.isSubCollection(c, collectionA));
|
assertTrue(CollectionUtils.isSubCollection(c, collectionA));
|
||||||
assertTrue(!CollectionUtils.isSubCollection(collectionA, c));
|
assertFalse(CollectionUtils.isSubCollection(collectionA, c));
|
||||||
c.add(3);
|
c.add(3);
|
||||||
assertTrue(CollectionUtils.isSubCollection(c, collectionA));
|
assertTrue(CollectionUtils.isSubCollection(c, collectionA));
|
||||||
assertTrue(!CollectionUtils.isSubCollection(collectionA, c));
|
assertFalse(CollectionUtils.isSubCollection(collectionA, c));
|
||||||
c.add(3);
|
c.add(3);
|
||||||
assertTrue(CollectionUtils.isSubCollection(c, collectionA));
|
assertTrue(CollectionUtils.isSubCollection(c, collectionA));
|
||||||
assertTrue(!CollectionUtils.isSubCollection(collectionA, c));
|
assertFalse(CollectionUtils.isSubCollection(collectionA, c));
|
||||||
c.add(3);
|
c.add(3);
|
||||||
assertTrue(CollectionUtils.isSubCollection(c, collectionA));
|
assertTrue(CollectionUtils.isSubCollection(c, collectionA));
|
||||||
assertTrue(!CollectionUtils.isSubCollection(collectionA, c));
|
assertFalse(CollectionUtils.isSubCollection(collectionA, c));
|
||||||
c.add(4);
|
c.add(4);
|
||||||
assertTrue(CollectionUtils.isSubCollection(c, collectionA));
|
assertTrue(CollectionUtils.isSubCollection(c, collectionA));
|
||||||
assertTrue(!CollectionUtils.isSubCollection(collectionA, c));
|
assertFalse(CollectionUtils.isSubCollection(collectionA, c));
|
||||||
c.add(4);
|
c.add(4);
|
||||||
assertTrue(CollectionUtils.isSubCollection(c, collectionA));
|
assertTrue(CollectionUtils.isSubCollection(c, collectionA));
|
||||||
assertTrue(!CollectionUtils.isSubCollection(collectionA, c));
|
assertFalse(CollectionUtils.isSubCollection(collectionA, c));
|
||||||
c.add(4);
|
c.add(4);
|
||||||
assertTrue(CollectionUtils.isSubCollection(c, collectionA));
|
assertTrue(CollectionUtils.isSubCollection(c, collectionA));
|
||||||
assertTrue(!CollectionUtils.isSubCollection(collectionA, c));
|
assertFalse(CollectionUtils.isSubCollection(collectionA, c));
|
||||||
c.add(4);
|
c.add(4);
|
||||||
assertTrue(CollectionUtils.isSubCollection(c, collectionA));
|
assertTrue(CollectionUtils.isSubCollection(c, collectionA));
|
||||||
assertTrue(CollectionUtils.isSubCollection(collectionA, c));
|
assertTrue(CollectionUtils.isSubCollection(collectionA, c));
|
||||||
c.add(5);
|
c.add(5);
|
||||||
assertTrue(!CollectionUtils.isSubCollection(c, collectionA));
|
assertFalse(CollectionUtils.isSubCollection(c, collectionA));
|
||||||
assertTrue(CollectionUtils.isSubCollection(collectionA, c));
|
assertTrue(CollectionUtils.isSubCollection(collectionA, c));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -667,8 +668,8 @@ public class CollectionUtilsTest extends MockTestCase {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testIsEqualCollection() {
|
public void testIsEqualCollection() {
|
||||||
assertTrue(!CollectionUtils.isEqualCollection(collectionA, collectionC));
|
assertFalse(CollectionUtils.isEqualCollection(collectionA, collectionC));
|
||||||
assertTrue(!CollectionUtils.isEqualCollection(collectionC, collectionA));
|
assertFalse(CollectionUtils.isEqualCollection(collectionC, collectionA));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -688,20 +689,20 @@ public class CollectionUtilsTest extends MockTestCase {
|
|||||||
assertTrue(CollectionUtils.isEqualCollection(a, b));
|
assertTrue(CollectionUtils.isEqualCollection(a, b));
|
||||||
assertTrue(CollectionUtils.isEqualCollection(b, a));
|
assertTrue(CollectionUtils.isEqualCollection(b, a));
|
||||||
a.add("1");
|
a.add("1");
|
||||||
assertTrue(!CollectionUtils.isEqualCollection(a, b));
|
assertFalse(CollectionUtils.isEqualCollection(a, b));
|
||||||
assertTrue(!CollectionUtils.isEqualCollection(b, a));
|
assertFalse(CollectionUtils.isEqualCollection(b, a));
|
||||||
b.add("1");
|
b.add("1");
|
||||||
assertTrue(CollectionUtils.isEqualCollection(a, b));
|
assertTrue(CollectionUtils.isEqualCollection(a, b));
|
||||||
assertTrue(CollectionUtils.isEqualCollection(b, a));
|
assertTrue(CollectionUtils.isEqualCollection(b, a));
|
||||||
a.add("2");
|
a.add("2");
|
||||||
assertTrue(!CollectionUtils.isEqualCollection(a, b));
|
assertFalse(CollectionUtils.isEqualCollection(a, b));
|
||||||
assertTrue(!CollectionUtils.isEqualCollection(b, a));
|
assertFalse(CollectionUtils.isEqualCollection(b, a));
|
||||||
b.add("2");
|
b.add("2");
|
||||||
assertTrue(CollectionUtils.isEqualCollection(a, b));
|
assertTrue(CollectionUtils.isEqualCollection(a, b));
|
||||||
assertTrue(CollectionUtils.isEqualCollection(b, a));
|
assertTrue(CollectionUtils.isEqualCollection(b, a));
|
||||||
a.add("1");
|
a.add("1");
|
||||||
assertTrue(!CollectionUtils.isEqualCollection(a, b));
|
assertFalse(CollectionUtils.isEqualCollection(a, b));
|
||||||
assertTrue(!CollectionUtils.isEqualCollection(b, a));
|
assertFalse(CollectionUtils.isEqualCollection(b, a));
|
||||||
b.add("1");
|
b.add("1");
|
||||||
assertTrue(CollectionUtils.isEqualCollection(a, b));
|
assertTrue(CollectionUtils.isEqualCollection(a, b));
|
||||||
assertTrue(CollectionUtils.isEqualCollection(b, a));
|
assertTrue(CollectionUtils.isEqualCollection(b, a));
|
||||||
@ -791,22 +792,22 @@ public class CollectionUtilsTest extends MockTestCase {
|
|||||||
public void testIsProperSubCollection() {
|
public void testIsProperSubCollection() {
|
||||||
final Collection<String> a = new ArrayList<>();
|
final Collection<String> a = new ArrayList<>();
|
||||||
final Collection<String> b = new ArrayList<>();
|
final Collection<String> b = new ArrayList<>();
|
||||||
assertTrue(!CollectionUtils.isProperSubCollection(a, b));
|
assertFalse(CollectionUtils.isProperSubCollection(a, b));
|
||||||
b.add("1");
|
b.add("1");
|
||||||
assertTrue(CollectionUtils.isProperSubCollection(a, b));
|
assertTrue(CollectionUtils.isProperSubCollection(a, b));
|
||||||
assertTrue(!CollectionUtils.isProperSubCollection(b, a));
|
assertFalse(CollectionUtils.isProperSubCollection(b, a));
|
||||||
assertTrue(!CollectionUtils.isProperSubCollection(b, b));
|
assertFalse(CollectionUtils.isProperSubCollection(b, b));
|
||||||
assertTrue(!CollectionUtils.isProperSubCollection(a, a));
|
assertFalse(CollectionUtils.isProperSubCollection(a, a));
|
||||||
a.add("1");
|
a.add("1");
|
||||||
a.add("2");
|
a.add("2");
|
||||||
b.add("2");
|
b.add("2");
|
||||||
assertTrue(!CollectionUtils.isProperSubCollection(b, a));
|
assertFalse(CollectionUtils.isProperSubCollection(b, a));
|
||||||
assertTrue(!CollectionUtils.isProperSubCollection(a, b));
|
assertFalse(CollectionUtils.isProperSubCollection(a, b));
|
||||||
a.add("1");
|
a.add("1");
|
||||||
assertTrue(CollectionUtils.isProperSubCollection(b, a));
|
assertTrue(CollectionUtils.isProperSubCollection(b, a));
|
||||||
assertTrue(CollectionUtils.isProperSubCollection(CollectionUtils.intersection(collectionA, collectionC), collectionA));
|
assertTrue(CollectionUtils.isProperSubCollection(CollectionUtils.intersection(collectionA, collectionC), collectionA));
|
||||||
assertTrue(CollectionUtils.isProperSubCollection(CollectionUtils.subtract(a, b), a));
|
assertTrue(CollectionUtils.isProperSubCollection(CollectionUtils.subtract(a, b), a));
|
||||||
assertTrue(!CollectionUtils.isProperSubCollection(a, CollectionUtils.subtract(a, b)));
|
assertFalse(CollectionUtils.isProperSubCollection(a, CollectionUtils.subtract(a, b)));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = NullPointerException.class)
|
@Test(expected = NullPointerException.class)
|
||||||
@ -828,10 +829,10 @@ public class CollectionUtilsTest extends MockTestCase {
|
|||||||
public void find() {
|
public void find() {
|
||||||
Predicate<Number> testPredicate = equalPredicate((Number) 4);
|
Predicate<Number> testPredicate = equalPredicate((Number) 4);
|
||||||
Integer test = CollectionUtils.find(collectionA, testPredicate);
|
Integer test = CollectionUtils.find(collectionA, testPredicate);
|
||||||
assertTrue(test.equals(4));
|
assertEquals(4, (int) test);
|
||||||
testPredicate = equalPredicate((Number) 45);
|
testPredicate = equalPredicate((Number) 45);
|
||||||
test = CollectionUtils.find(collectionA, testPredicate);
|
test = CollectionUtils.find(collectionA, testPredicate);
|
||||||
assertTrue(test == null);
|
assertNull(test);
|
||||||
assertNull(CollectionUtils.find(null, testPredicate));
|
assertNull(CollectionUtils.find(null, testPredicate));
|
||||||
assertNull(CollectionUtils.find(collectionA, null));
|
assertNull(CollectionUtils.find(collectionA, null));
|
||||||
}
|
}
|
||||||
@ -900,7 +901,7 @@ public class CollectionUtilsTest extends MockTestCase {
|
|||||||
col.add(collectionB);
|
col.add(collectionB);
|
||||||
lastElement = CollectionUtils.forAllButLastDo(col, testClosure);
|
lastElement = CollectionUtils.forAllButLastDo(col, testClosure);
|
||||||
assertSame(lastElement, collectionB);
|
assertSame(lastElement, collectionB);
|
||||||
assertTrue(!collectionB.isEmpty() );
|
assertFalse(collectionB.isEmpty());
|
||||||
|
|
||||||
col.clear();
|
col.clear();
|
||||||
lastElement = CollectionUtils.forAllButLastDo(col, testClosure);
|
lastElement = CollectionUtils.forAllButLastDo(col, testClosure);
|
||||||
@ -1008,7 +1009,7 @@ public class CollectionUtilsTest extends MockTestCase {
|
|||||||
} catch (final IndexOutOfBoundsException e) {
|
} catch (final IndexOutOfBoundsException e) {
|
||||||
// expected
|
// expected
|
||||||
}
|
}
|
||||||
assertTrue(!iterator.hasNext());
|
assertFalse(iterator.hasNext());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -1030,7 +1031,7 @@ public class CollectionUtilsTest extends MockTestCase {
|
|||||||
} catch (final IndexOutOfBoundsException e) {
|
} catch (final IndexOutOfBoundsException e) {
|
||||||
// expected
|
// expected
|
||||||
}
|
}
|
||||||
assertTrue(!en.hasMoreElements());
|
assertFalse(en.hasMoreElements());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = IndexOutOfBoundsException.class)
|
@Test(expected = IndexOutOfBoundsException.class)
|
||||||
@ -1157,15 +1158,15 @@ public class CollectionUtilsTest extends MockTestCase {
|
|||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
@Test
|
@Test
|
||||||
public void testSizeIsEmpty_Null() {
|
public void testSizeIsEmpty_Null() {
|
||||||
assertEquals(true, CollectionUtils.sizeIsEmpty(null));
|
assertTrue(CollectionUtils.sizeIsEmpty(null));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSizeIsEmpty_List() {
|
public void testSizeIsEmpty_List() {
|
||||||
final List<String> list = new ArrayList<>();
|
final List<String> list = new ArrayList<>();
|
||||||
assertEquals(true, CollectionUtils.sizeIsEmpty(list));
|
assertTrue(CollectionUtils.sizeIsEmpty(list));
|
||||||
list.add("a");
|
list.add("a");
|
||||||
assertEquals(false, CollectionUtils.sizeIsEmpty(list));
|
assertFalse(CollectionUtils.sizeIsEmpty(list));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -1179,49 +1180,49 @@ public class CollectionUtilsTest extends MockTestCase {
|
|||||||
@Test
|
@Test
|
||||||
public void testSizeIsEmpty_Array() {
|
public void testSizeIsEmpty_Array() {
|
||||||
final Object[] objectArray = new Object[0];
|
final Object[] objectArray = new Object[0];
|
||||||
assertEquals(true, CollectionUtils.sizeIsEmpty(objectArray));
|
assertTrue(CollectionUtils.sizeIsEmpty(objectArray));
|
||||||
|
|
||||||
final String[] stringArray = new String[3];
|
final String[] stringArray = new String[3];
|
||||||
assertEquals(false, CollectionUtils.sizeIsEmpty(stringArray));
|
assertFalse(CollectionUtils.sizeIsEmpty(stringArray));
|
||||||
stringArray[0] = "a";
|
stringArray[0] = "a";
|
||||||
stringArray[1] = "b";
|
stringArray[1] = "b";
|
||||||
stringArray[2] = "c";
|
stringArray[2] = "c";
|
||||||
assertEquals(false, CollectionUtils.sizeIsEmpty(stringArray));
|
assertFalse(CollectionUtils.sizeIsEmpty(stringArray));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSizeIsEmpty_PrimitiveArray() {
|
public void testSizeIsEmpty_PrimitiveArray() {
|
||||||
final int[] intArray = new int[0];
|
final int[] intArray = new int[0];
|
||||||
assertEquals(true, CollectionUtils.sizeIsEmpty(intArray));
|
assertTrue(CollectionUtils.sizeIsEmpty(intArray));
|
||||||
|
|
||||||
final double[] doubleArray = new double[3];
|
final double[] doubleArray = new double[3];
|
||||||
assertEquals(false, CollectionUtils.sizeIsEmpty(doubleArray));
|
assertFalse(CollectionUtils.sizeIsEmpty(doubleArray));
|
||||||
doubleArray[0] = 0.0d;
|
doubleArray[0] = 0.0d;
|
||||||
doubleArray[1] = 1.0d;
|
doubleArray[1] = 1.0d;
|
||||||
doubleArray[2] = 2.5d;
|
doubleArray[2] = 2.5d;
|
||||||
assertEquals(false, CollectionUtils.sizeIsEmpty(doubleArray));
|
assertFalse(CollectionUtils.sizeIsEmpty(doubleArray));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSizeIsEmpty_Enumeration() {
|
public void testSizeIsEmpty_Enumeration() {
|
||||||
final Vector<String> list = new Vector<>();
|
final Vector<String> list = new Vector<>();
|
||||||
assertEquals(true, CollectionUtils.sizeIsEmpty(list.elements()));
|
assertTrue(CollectionUtils.sizeIsEmpty(list.elements()));
|
||||||
list.add("a");
|
list.add("a");
|
||||||
assertEquals(false, CollectionUtils.sizeIsEmpty(list.elements()));
|
assertFalse(CollectionUtils.sizeIsEmpty(list.elements()));
|
||||||
final Enumeration<String> en = list.elements();
|
final Enumeration<String> en = list.elements();
|
||||||
en.nextElement();
|
en.nextElement();
|
||||||
assertEquals(true, CollectionUtils.sizeIsEmpty(en));
|
assertTrue(CollectionUtils.sizeIsEmpty(en));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSizeIsEmpty_Iterator() {
|
public void testSizeIsEmpty_Iterator() {
|
||||||
final List<String> list = new ArrayList<>();
|
final List<String> list = new ArrayList<>();
|
||||||
assertEquals(true, CollectionUtils.sizeIsEmpty(list.iterator()));
|
assertTrue(CollectionUtils.sizeIsEmpty(list.iterator()));
|
||||||
list.add("a");
|
list.add("a");
|
||||||
assertEquals(false, CollectionUtils.sizeIsEmpty(list.iterator()));
|
assertFalse(CollectionUtils.sizeIsEmpty(list.iterator()));
|
||||||
final Iterator<String> it = list.iterator();
|
final Iterator<String> it = list.iterator();
|
||||||
it.next();
|
it.next();
|
||||||
assertEquals(true, CollectionUtils.sizeIsEmpty(it));
|
assertTrue(CollectionUtils.sizeIsEmpty(it));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -1236,40 +1237,32 @@ public class CollectionUtilsTest extends MockTestCase {
|
|||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
@Test
|
@Test
|
||||||
public void testIsEmptyWithEmptyCollection() {
|
public void testIsEmptyWithEmptyCollection() {
|
||||||
final Collection<Object> coll = new ArrayList<>();
|
assertTrue(CollectionUtils.isEmpty(new ArrayList<>()));
|
||||||
assertEquals(true, CollectionUtils.isEmpty(coll));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testIsEmptyWithNonEmptyCollection() {
|
public void testIsEmptyWithNonEmptyCollection() {
|
||||||
final Collection<String> coll = new ArrayList<>();
|
assertFalse(CollectionUtils.isEmpty(Collections.singletonList("item")));
|
||||||
coll.add("item");
|
|
||||||
assertEquals(false, CollectionUtils.isEmpty(coll));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testIsEmptyWithNull() {
|
public void testIsEmptyWithNull() {
|
||||||
final Collection<?> coll = null;
|
assertTrue(CollectionUtils.isEmpty(null));
|
||||||
assertEquals(true, CollectionUtils.isEmpty(coll));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testIsNotEmptyWithEmptyCollection() {
|
public void testIsNotEmptyWithEmptyCollection() {
|
||||||
final Collection<Object> coll = new ArrayList<>();
|
assertFalse(CollectionUtils.isNotEmpty(new ArrayList<>()));
|
||||||
assertEquals(false, CollectionUtils.isNotEmpty(coll));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testIsNotEmptyWithNonEmptyCollection() {
|
public void testIsNotEmptyWithNonEmptyCollection() {
|
||||||
final Collection<String> coll = new ArrayList<>();
|
assertTrue(CollectionUtils.isNotEmpty(Collections.singletonList("item")));
|
||||||
coll.add("item");
|
|
||||||
assertEquals(true, CollectionUtils.isNotEmpty(coll));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testIsNotEmptyWithNull() {
|
public void testIsNotEmptyWithNull() {
|
||||||
final Collection<?> coll = null;
|
assertFalse(CollectionUtils.isNotEmpty(null));
|
||||||
assertEquals(false, CollectionUtils.isNotEmpty(coll));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
@ -1349,7 +1342,7 @@ public class CollectionUtilsTest extends MockTestCase {
|
|||||||
assertFalse(CollectionUtils.exists(list, EQUALS_TWO));
|
assertFalse(CollectionUtils.exists(list, EQUALS_TWO));
|
||||||
|
|
||||||
list.add(2);
|
list.add(2);
|
||||||
assertEquals(true, CollectionUtils.exists(list, EQUALS_TWO));
|
assertTrue(CollectionUtils.exists(list, EQUALS_TWO));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -1504,9 +1497,9 @@ public class CollectionUtilsTest extends MockTestCase {
|
|||||||
assertEquals(3, set.size());
|
assertEquals(3, set.size());
|
||||||
assertFalse(CollectionUtils.addIgnoreNull(set, "1"));
|
assertFalse(CollectionUtils.addIgnoreNull(set, "1"));
|
||||||
assertEquals(3, set.size());
|
assertEquals(3, set.size());
|
||||||
assertEquals(true, CollectionUtils.addIgnoreNull(set, "4"));
|
assertTrue(CollectionUtils.addIgnoreNull(set, "4"));
|
||||||
assertEquals(4, set.size());
|
assertEquals(4, set.size());
|
||||||
assertEquals(true, set.contains("4"));
|
assertTrue(set.contains("4"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = NullPointerException.class)
|
@Test(expected = NullPointerException.class)
|
||||||
@ -1543,11 +1536,11 @@ public class CollectionUtilsTest extends MockTestCase {
|
|||||||
assertFalse(CollectionUtils.isFull(set));
|
assertFalse(CollectionUtils.isFull(set));
|
||||||
|
|
||||||
final CircularFifoQueue<String> buf = new CircularFifoQueue<>(set);
|
final CircularFifoQueue<String> buf = new CircularFifoQueue<>(set);
|
||||||
assertEquals(false, CollectionUtils.isFull(buf));
|
assertFalse(CollectionUtils.isFull(buf));
|
||||||
buf.remove("2");
|
buf.remove("2");
|
||||||
assertFalse(CollectionUtils.isFull(buf));
|
assertFalse(CollectionUtils.isFull(buf));
|
||||||
buf.add("2");
|
buf.add("2");
|
||||||
assertEquals(false, CollectionUtils.isFull(buf));
|
assertFalse(CollectionUtils.isFull(buf));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = NullPointerException.class)
|
@Test(expected = NullPointerException.class)
|
||||||
@ -1585,15 +1578,11 @@ public class CollectionUtilsTest extends MockTestCase {
|
|||||||
@Test
|
@Test
|
||||||
public void intersectionUsesMethodEquals() {
|
public void intersectionUsesMethodEquals() {
|
||||||
// Let elta and eltb be objects...
|
// Let elta and eltb be objects...
|
||||||
final Integer elta = new Integer(17); // Cannot use valueOf here
|
final Integer elta = 17;
|
||||||
final Integer eltb = new Integer(17);
|
final Integer eltb = 17;
|
||||||
|
|
||||||
// ...which are equal...
|
// ...which are the same (==)
|
||||||
assertEquals(elta, eltb);
|
assertSame(elta, eltb);
|
||||||
assertEquals(eltb, elta);
|
|
||||||
|
|
||||||
// ...but not the same (==).
|
|
||||||
assertTrue(elta != eltb);
|
|
||||||
|
|
||||||
// Let cola and colb be collections...
|
// Let cola and colb be collections...
|
||||||
final Collection<Number> cola = new ArrayList<>();
|
final Collection<Number> cola = new ArrayList<>();
|
||||||
@ -1613,7 +1602,7 @@ public class CollectionUtilsTest extends MockTestCase {
|
|||||||
// or eltb, although this isn't strictly part of the
|
// or eltb, although this isn't strictly part of the
|
||||||
// contract.
|
// contract.
|
||||||
final Object eltc = intersection.iterator().next();
|
final Object eltc = intersection.iterator().next();
|
||||||
assertTrue(eltc == elta && eltc != eltb || eltc != elta && eltc == eltb);
|
assertTrue(eltc == elta && eltc == eltb);
|
||||||
|
|
||||||
// In any event, this element remains equal,
|
// In any event, this element remains equal,
|
||||||
// to both elta and eltb.
|
// to both elta and eltb.
|
||||||
@ -1638,17 +1627,17 @@ public class CollectionUtilsTest extends MockTestCase {
|
|||||||
|
|
||||||
final Collection<String> result = CollectionUtils.retainAll(base, sub);
|
final Collection<String> result = CollectionUtils.retainAll(base, sub);
|
||||||
assertEquals(2, result.size());
|
assertEquals(2, result.size());
|
||||||
assertEquals(true, result.contains("A"));
|
assertTrue(result.contains("A"));
|
||||||
assertFalse(result.contains("B"));
|
assertFalse(result.contains("B"));
|
||||||
assertEquals(true, result.contains("C"));
|
assertTrue(result.contains("C"));
|
||||||
assertEquals(3, base.size());
|
assertEquals(3, base.size());
|
||||||
assertEquals(true, base.contains("A"));
|
assertTrue(base.contains("A"));
|
||||||
assertEquals(true, base.contains("B"));
|
assertTrue(base.contains("B"));
|
||||||
assertEquals(true, base.contains("C"));
|
assertTrue(base.contains("C"));
|
||||||
assertEquals(3, sub.size());
|
assertEquals(3, sub.size());
|
||||||
assertEquals(true, sub.contains("A"));
|
assertTrue(sub.contains("A"));
|
||||||
assertEquals(true, sub.contains("C"));
|
assertTrue(sub.contains("C"));
|
||||||
assertEquals(true, sub.contains("X"));
|
assertTrue(sub.contains("X"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = NullPointerException.class)
|
@Test(expected = NullPointerException.class)
|
||||||
@ -1788,16 +1777,16 @@ public class CollectionUtilsTest extends MockTestCase {
|
|||||||
final Collection<String> result = CollectionUtils.removeAll(base, sub);
|
final Collection<String> result = CollectionUtils.removeAll(base, sub);
|
||||||
assertEquals(1, result.size());
|
assertEquals(1, result.size());
|
||||||
assertFalse(result.contains("A"));
|
assertFalse(result.contains("A"));
|
||||||
assertEquals(true, result.contains("B"));
|
assertTrue(result.contains("B"));
|
||||||
assertFalse(result.contains("C"));
|
assertFalse(result.contains("C"));
|
||||||
assertEquals(3, base.size());
|
assertEquals(3, base.size());
|
||||||
assertEquals(true, base.contains("A"));
|
assertTrue(base.contains("A"));
|
||||||
assertEquals(true, base.contains("B"));
|
assertTrue(base.contains("B"));
|
||||||
assertEquals(true, base.contains("C"));
|
assertTrue(base.contains("C"));
|
||||||
assertEquals(3, sub.size());
|
assertEquals(3, sub.size());
|
||||||
assertEquals(true, sub.contains("A"));
|
assertTrue(sub.contains("A"));
|
||||||
assertEquals(true, sub.contains("C"));
|
assertTrue(sub.contains("C"));
|
||||||
assertEquals(true, sub.contains("X"));
|
assertTrue(sub.contains("X"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = NullPointerException.class)
|
@Test(expected = NullPointerException.class)
|
||||||
@ -1841,9 +1830,9 @@ public class CollectionUtilsTest extends MockTestCase {
|
|||||||
list.add("2");
|
list.add("2");
|
||||||
list.add("3");
|
list.add("3");
|
||||||
final Collection<Object> result = CollectionUtils.transformingCollection(list, TRANSFORM_TO_INTEGER);
|
final Collection<Object> result = CollectionUtils.transformingCollection(list, TRANSFORM_TO_INTEGER);
|
||||||
assertEquals(true, result.contains("1")); // untransformed
|
assertTrue(result.contains("1")); // untransformed
|
||||||
assertEquals(true, result.contains("2")); // untransformed
|
assertTrue(result.contains("2")); // untransformed
|
||||||
assertEquals(true, result.contains("3")); // untransformed
|
assertTrue(result.contains("3")); // untransformed
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -2196,13 +2185,13 @@ public class CollectionUtilsTest extends MockTestCase {
|
|||||||
assertTrue(result.contains("BB"));
|
assertTrue(result.contains("BB"));
|
||||||
assertFalse(result.contains("CA"));
|
assertFalse(result.contains("CA"));
|
||||||
assertEquals(3, base.size());
|
assertEquals(3, base.size());
|
||||||
assertEquals(true, base.contains("AC"));
|
assertTrue(base.contains("AC"));
|
||||||
assertEquals(true, base.contains("BB"));
|
assertTrue(base.contains("BB"));
|
||||||
assertEquals(true, base.contains("CA"));
|
assertTrue(base.contains("CA"));
|
||||||
assertEquals(3, remove.size());
|
assertEquals(3, remove.size());
|
||||||
assertEquals(true, remove.contains("AA"));
|
assertTrue(remove.contains("AA"));
|
||||||
assertEquals(true, remove.contains("CX"));
|
assertTrue(remove.contains("CX"));
|
||||||
assertEquals(true, remove.contains("XZ"));
|
assertTrue(remove.contains("XZ"));
|
||||||
|
|
||||||
try {
|
try {
|
||||||
CollectionUtils.removeAll(null, null, DefaultEquator.defaultEquator());
|
CollectionUtils.removeAll(null, null, DefaultEquator.defaultEquator());
|
||||||
|
@ -29,17 +29,16 @@ import org.junit.Test;
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class ComparatorUtilsTest {
|
public class ComparatorUtilsTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void booleanComparator() {
|
public void booleanComparator() {
|
||||||
Comparator<Boolean> comp = ComparatorUtils.booleanComparator(true);
|
Comparator<Boolean> comp = ComparatorUtils.booleanComparator(true);
|
||||||
assertTrue(comp.compare(Boolean.TRUE, Boolean.FALSE) < 0);
|
assertTrue(comp.compare(Boolean.TRUE, Boolean.FALSE) < 0);
|
||||||
assertTrue(comp.compare(Boolean.TRUE, Boolean.TRUE) == 0);
|
assertEquals(0, comp.compare(Boolean.TRUE, Boolean.TRUE));
|
||||||
assertTrue(comp.compare(Boolean.FALSE, Boolean.TRUE) > 0);
|
assertTrue(comp.compare(Boolean.FALSE, Boolean.TRUE) > 0);
|
||||||
|
|
||||||
comp = ComparatorUtils.booleanComparator(false);
|
comp = ComparatorUtils.booleanComparator(false);
|
||||||
assertTrue(comp.compare(Boolean.TRUE, Boolean.FALSE) > 0);
|
assertTrue(comp.compare(Boolean.TRUE, Boolean.FALSE) > 0);
|
||||||
assertTrue(comp.compare(Boolean.TRUE, Boolean.TRUE) == 0);
|
assertEquals(0, comp.compare(Boolean.TRUE, Boolean.TRUE));
|
||||||
assertTrue(comp.compare(Boolean.FALSE, Boolean.TRUE) < 0);
|
assertTrue(comp.compare(Boolean.FALSE, Boolean.TRUE) < 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -47,9 +46,9 @@ public class ComparatorUtilsTest {
|
|||||||
public void chainedComparator() {
|
public void chainedComparator() {
|
||||||
// simple test: chain 2 natural comparators
|
// simple test: chain 2 natural comparators
|
||||||
final Comparator<Integer> comp = ComparatorUtils.chainedComparator(ComparatorUtils.<Integer>naturalComparator(),
|
final Comparator<Integer> comp = ComparatorUtils.chainedComparator(ComparatorUtils.<Integer>naturalComparator(),
|
||||||
ComparatorUtils.<Integer>naturalComparator());
|
ComparatorUtils.naturalComparator());
|
||||||
assertTrue(comp.compare(1, 2) < 0);
|
assertTrue(comp.compare(1, 2) < 0);
|
||||||
assertTrue(comp.compare(1, 1) == 0);
|
assertEquals(0, comp.compare(1, 1));
|
||||||
assertTrue(comp.compare(2, 1) > 0);
|
assertTrue(comp.compare(2, 1) > 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -109,7 +108,7 @@ public class ComparatorUtilsTest {
|
|||||||
public void nullLowComparator() {
|
public void nullLowComparator() {
|
||||||
final Comparator<Integer> comp = ComparatorUtils.nullLowComparator(null);
|
final Comparator<Integer> comp = ComparatorUtils.nullLowComparator(null);
|
||||||
assertTrue(comp.compare(null, 10) < 0);
|
assertTrue(comp.compare(null, 10) < 0);
|
||||||
assertTrue(comp.compare(null, null) == 0);
|
assertEquals(0, comp.compare(null, null));
|
||||||
assertTrue(comp.compare(10, null) > 0);
|
assertTrue(comp.compare(10, null) > 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -117,8 +116,7 @@ public class ComparatorUtilsTest {
|
|||||||
public void nullHighComparator() {
|
public void nullHighComparator() {
|
||||||
final Comparator<Integer> comp = ComparatorUtils.nullHighComparator(null);
|
final Comparator<Integer> comp = ComparatorUtils.nullHighComparator(null);
|
||||||
assertTrue(comp.compare(null, 10) > 0);
|
assertTrue(comp.compare(null, 10) > 0);
|
||||||
assertTrue(comp.compare(null, null) == 0);
|
assertEquals(0, comp.compare(null, null));
|
||||||
assertTrue(comp.compare(10, null) < 0);
|
assertTrue(comp.compare(10, null) < 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -18,6 +18,7 @@ package org.apache.commons.collections4;
|
|||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertNotNull;
|
import static org.junit.Assert.assertNotNull;
|
||||||
|
import static org.junit.Assert.assertNotSame;
|
||||||
import static org.junit.Assert.assertNull;
|
import static org.junit.Assert.assertNull;
|
||||||
import static org.junit.Assert.assertSame;
|
import static org.junit.Assert.assertSame;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
@ -103,7 +104,7 @@ public class FactoryUtilsTest {
|
|||||||
final Factory<Date> factory = FactoryUtils.prototypeFactory(proto);
|
final Factory<Date> factory = FactoryUtils.prototypeFactory(proto);
|
||||||
assertNotNull(factory);
|
assertNotNull(factory);
|
||||||
final Date created = factory.create();
|
final Date created = factory.create();
|
||||||
assertTrue(proto != created);
|
assertNotSame(proto, created);
|
||||||
assertEquals(proto, created);
|
assertEquals(proto, created);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -113,17 +114,17 @@ public class FactoryUtilsTest {
|
|||||||
final Factory<Object> factory = FactoryUtils.<Object>prototypeFactory(proto);
|
final Factory<Object> factory = FactoryUtils.<Object>prototypeFactory(proto);
|
||||||
assertNotNull(factory);
|
assertNotNull(factory);
|
||||||
final Object created = factory.create();
|
final Object created = factory.create();
|
||||||
assertTrue(proto != created);
|
assertNotSame(proto, created);
|
||||||
assertEquals(proto, created);
|
assertEquals(proto, created);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testPrototypeFactoryPublicSerialization() throws Exception {
|
public void testPrototypeFactoryPublicSerialization() throws Exception {
|
||||||
final Integer proto = Integer.valueOf(9);
|
final Integer proto = 9;
|
||||||
final Factory<Integer> factory = FactoryUtils.prototypeFactory(proto);
|
final Factory<Integer> factory = FactoryUtils.prototypeFactory(proto);
|
||||||
assertNotNull(factory);
|
assertNotNull(factory);
|
||||||
final Integer created = factory.create();
|
final Integer created = factory.create();
|
||||||
assertTrue(proto != created);
|
assertNotSame(proto, created);
|
||||||
assertEquals(proto, created);
|
assertEquals(proto, created);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -266,12 +266,12 @@ public class IterableUtilsTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void find() {
|
public void find() {
|
||||||
Predicate<Number> testPredicate = equalPredicate((Number) 4);
|
Predicate<Number> testPredicate = equalPredicate(4);
|
||||||
Integer test = IterableUtils.find(iterableA, testPredicate);
|
Integer test = IterableUtils.find(iterableA, testPredicate);
|
||||||
assertTrue(test.equals(4));
|
assertEquals(4, (int) test);
|
||||||
testPredicate = equalPredicate((Number) 45);
|
testPredicate = equalPredicate(45);
|
||||||
test = IterableUtils.find(iterableA, testPredicate);
|
test = IterableUtils.find(iterableA, testPredicate);
|
||||||
assertTrue(test == null);
|
assertNull(test);
|
||||||
assertNull(IterableUtils.find(null, testPredicate));
|
assertNull(IterableUtils.find(null, testPredicate));
|
||||||
try {
|
try {
|
||||||
IterableUtils.find(iterableA, null);
|
IterableUtils.find(iterableA, null);
|
||||||
@ -344,7 +344,7 @@ public class IterableUtilsTest {
|
|||||||
assertFalse(IterableUtils.matchesAny(list, EQUALS_TWO));
|
assertFalse(IterableUtils.matchesAny(list, EQUALS_TWO));
|
||||||
|
|
||||||
list.add(2);
|
list.add(2);
|
||||||
assertEquals(true, IterableUtils.matchesAny(list, EQUALS_TWO));
|
assertTrue(IterableUtils.matchesAny(list, EQUALS_TWO));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -22,7 +22,9 @@ import static org.junit.Assert.assertNull;
|
|||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
import static org.junit.Assert.fail;
|
import static org.junit.Assert.fail;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
@ -70,61 +72,54 @@ public class MultiMapUtilsTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testIsEmptyWithEmptyMap() {
|
public void testIsEmptyWithEmptyMap() {
|
||||||
final MultiValuedMap<Object, Object> map = new ArrayListValuedHashMap<>();
|
assertTrue(MultiMapUtils.isEmpty(new ArrayListValuedHashMap<>()));
|
||||||
assertEquals(true, MultiMapUtils.isEmpty(map));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testIsEmptyWithNonEmptyMap() {
|
public void testIsEmptyWithNonEmptyMap() {
|
||||||
final MultiValuedMap<String, String> map = new ArrayListValuedHashMap<>();
|
final MultiValuedMap<String, String> map = new ArrayListValuedHashMap<>();
|
||||||
map.put("item", "value");
|
map.put("item", "value");
|
||||||
assertEquals(false, MultiMapUtils.isEmpty(map));
|
assertFalse(MultiMapUtils.isEmpty(map));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testIsEmptyWithNull() {
|
public void testIsEmptyWithNull() {
|
||||||
final MultiValuedMap<Object, Object> map = null;
|
assertTrue(MultiMapUtils.isEmpty(null));
|
||||||
assertEquals(true, MultiMapUtils.isEmpty(map));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetCollection() {
|
public void testGetCollection() {
|
||||||
assertNull(MultiMapUtils.getCollection(null, "key1"));
|
assertNull(MultiMapUtils.getCollection(null, "key1"));
|
||||||
|
|
||||||
final String values[] = { "v1", "v2", "v3" };
|
final String[] values = { "v1", "v2", "v3" };
|
||||||
final MultiValuedMap<String, String> map = new ArrayListValuedHashMap<>();
|
final MultiValuedMap<String, String> map = new ArrayListValuedHashMap<>();
|
||||||
for (final String val : values) {
|
for (final String val : values) {
|
||||||
map.put("key1", val);
|
map.put("key1", val);
|
||||||
}
|
}
|
||||||
|
|
||||||
final Collection<String> col = MultiMapUtils.getCollection(map, "key1");
|
final Collection<String> col = MultiMapUtils.getCollection(map, "key1");
|
||||||
for (final String val : values) {
|
assertEquals(Arrays.asList(values), col);
|
||||||
assertTrue(col.contains(val));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetValuesAsList() {
|
public void testGetValuesAsList() {
|
||||||
assertNull(MultiMapUtils.getValuesAsList(null, "key1"));
|
assertNull(MultiMapUtils.getValuesAsList(null, "key1"));
|
||||||
|
|
||||||
final String values[] = { "v1", "v2", "v3" };
|
final String[] values = { "v1", "v2", "v3" };
|
||||||
final MultiValuedMap<String, String> map = new ArrayListValuedHashMap<>();
|
final MultiValuedMap<String, String> map = new ArrayListValuedHashMap<>();
|
||||||
for (final String val : values) {
|
for (final String val : values) {
|
||||||
map.put("key1", val);
|
map.put("key1", val);
|
||||||
}
|
}
|
||||||
|
|
||||||
final List<String> list = MultiMapUtils.getValuesAsList(map, "key1");
|
final List<String> list = MultiMapUtils.getValuesAsList(map, "key1");
|
||||||
int i = 0;
|
assertEquals(Arrays.asList(values), list);
|
||||||
for (final String val : list) {
|
|
||||||
assertTrue(val.equals(values[i++]));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetValuesAsSet() {
|
public void testGetValuesAsSet() {
|
||||||
assertNull(MultiMapUtils.getValuesAsList(null, "key1"));
|
assertNull(MultiMapUtils.getValuesAsList(null, "key1"));
|
||||||
|
|
||||||
final String values[] = { "v1", "v2", "v3" };
|
final String[] values = { "v1", "v2", "v3" };
|
||||||
final MultiValuedMap<String, String> map = new ArrayListValuedHashMap<>();
|
final MultiValuedMap<String, String> map = new ArrayListValuedHashMap<>();
|
||||||
for (final String val : values) {
|
for (final String val : values) {
|
||||||
map.put("key1", val);
|
map.put("key1", val);
|
||||||
@ -132,10 +127,7 @@ public class MultiMapUtilsTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
final Set<String> set = MultiMapUtils.getValuesAsSet(map, "key1");
|
final Set<String> set = MultiMapUtils.getValuesAsSet(map, "key1");
|
||||||
assertEquals(3, set.size());
|
assertEquals(new HashSet<>(Arrays.asList(values)), set);
|
||||||
for (final String val : values) {
|
|
||||||
assertTrue(set.contains(val));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -21,6 +21,7 @@ import static org.apache.commons.collections4.functors.TruePredicate.*;
|
|||||||
import static org.junit.Assert.*;
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
@ -71,10 +72,10 @@ public class PredicateUtilsTest extends AbstractPredicateTest {
|
|||||||
public void testIsNotNullPredicate() {
|
public void testIsNotNullPredicate() {
|
||||||
assertNotNull(PredicateUtils.notNullPredicate());
|
assertNotNull(PredicateUtils.notNullPredicate());
|
||||||
assertSame(PredicateUtils.notNullPredicate(), PredicateUtils.notNullPredicate());
|
assertSame(PredicateUtils.notNullPredicate(), PredicateUtils.notNullPredicate());
|
||||||
assertEquals(false, PredicateUtils.notNullPredicate().evaluate(null));
|
assertFalse(PredicateUtils.notNullPredicate().evaluate(null));
|
||||||
assertEquals(true, PredicateUtils.notNullPredicate().evaluate(cObject));
|
assertTrue(PredicateUtils.notNullPredicate().evaluate(cObject));
|
||||||
assertEquals(true, PredicateUtils.notNullPredicate().evaluate(cString));
|
assertTrue(PredicateUtils.notNullPredicate().evaluate(cString));
|
||||||
assertEquals(true, PredicateUtils.notNullPredicate().evaluate(cInteger));
|
assertTrue(PredicateUtils.notNullPredicate().evaluate(cInteger));
|
||||||
}
|
}
|
||||||
|
|
||||||
// identityPredicate
|
// identityPredicate
|
||||||
@ -83,12 +84,12 @@ public class PredicateUtilsTest extends AbstractPredicateTest {
|
|||||||
@Test
|
@Test
|
||||||
public void testIdentityPredicate() {
|
public void testIdentityPredicate() {
|
||||||
assertSame(nullPredicate(), PredicateUtils.identityPredicate(null));
|
assertSame(nullPredicate(), PredicateUtils.identityPredicate(null));
|
||||||
assertNotNull(PredicateUtils.identityPredicate(Integer.valueOf(6)));
|
assertNotNull(PredicateUtils.identityPredicate(6));
|
||||||
assertEquals(false, PredicateUtils.identityPredicate(Integer.valueOf(6)).evaluate(null));
|
assertFalse(PredicateUtils.identityPredicate(6).evaluate(null));
|
||||||
assertEquals(false, PredicateUtils.<Object>identityPredicate(Integer.valueOf(6)).evaluate(cObject));
|
assertFalse(PredicateUtils.<Object>identityPredicate(6).evaluate(cObject));
|
||||||
assertEquals(false, PredicateUtils.<Object>identityPredicate(Integer.valueOf(6)).evaluate(cString));
|
assertFalse(PredicateUtils.<Object>identityPredicate(6).evaluate(cString));
|
||||||
assertEquals(false, PredicateUtils.identityPredicate(new Integer(6)).evaluate(cInteger)); // Cannot use valueOf here
|
assertTrue(PredicateUtils.identityPredicate(6).evaluate(cInteger)); // Cannot use valueOf here
|
||||||
assertEquals(true, PredicateUtils.identityPredicate(cInteger).evaluate(cInteger));
|
assertTrue(PredicateUtils.identityPredicate(cInteger).evaluate(cInteger));
|
||||||
}
|
}
|
||||||
|
|
||||||
// truePredicate
|
// truePredicate
|
||||||
@ -98,10 +99,10 @@ public class PredicateUtilsTest extends AbstractPredicateTest {
|
|||||||
public void testTruePredicate() {
|
public void testTruePredicate() {
|
||||||
assertNotNull(TruePredicate.truePredicate());
|
assertNotNull(TruePredicate.truePredicate());
|
||||||
assertSame(TruePredicate.truePredicate(), TruePredicate.truePredicate());
|
assertSame(TruePredicate.truePredicate(), TruePredicate.truePredicate());
|
||||||
assertEquals(true, TruePredicate.truePredicate().evaluate(null));
|
assertTrue(truePredicate().evaluate(null));
|
||||||
assertEquals(true, TruePredicate.truePredicate().evaluate(cObject));
|
assertTrue(truePredicate().evaluate(cObject));
|
||||||
assertEquals(true, TruePredicate.truePredicate().evaluate(cString));
|
assertTrue(truePredicate().evaluate(cString));
|
||||||
assertEquals(true, TruePredicate.truePredicate().evaluate(cInteger));
|
assertTrue(truePredicate().evaluate(cInteger));
|
||||||
}
|
}
|
||||||
|
|
||||||
// falsePredicate
|
// falsePredicate
|
||||||
@ -111,10 +112,10 @@ public class PredicateUtilsTest extends AbstractPredicateTest {
|
|||||||
public void testFalsePredicate() {
|
public void testFalsePredicate() {
|
||||||
assertNotNull(FalsePredicate.falsePredicate());
|
assertNotNull(FalsePredicate.falsePredicate());
|
||||||
assertSame(FalsePredicate.falsePredicate(), FalsePredicate.falsePredicate());
|
assertSame(FalsePredicate.falsePredicate(), FalsePredicate.falsePredicate());
|
||||||
assertEquals(false, FalsePredicate.falsePredicate().evaluate(null));
|
assertFalse(FalsePredicate.falsePredicate().evaluate(null));
|
||||||
assertEquals(false, FalsePredicate.falsePredicate().evaluate(cObject));
|
assertFalse(FalsePredicate.falsePredicate().evaluate(cObject));
|
||||||
assertEquals(false, FalsePredicate.falsePredicate().evaluate(cString));
|
assertFalse(FalsePredicate.falsePredicate().evaluate(cString));
|
||||||
assertEquals(false, FalsePredicate.falsePredicate().evaluate(cInteger));
|
assertFalse(FalsePredicate.falsePredicate().evaluate(cInteger));
|
||||||
}
|
}
|
||||||
|
|
||||||
// notPredicate
|
// notPredicate
|
||||||
@ -123,10 +124,10 @@ public class PredicateUtilsTest extends AbstractPredicateTest {
|
|||||||
@Test
|
@Test
|
||||||
public void testNotPredicate() {
|
public void testNotPredicate() {
|
||||||
assertNotNull(PredicateUtils.notPredicate(TruePredicate.truePredicate()));
|
assertNotNull(PredicateUtils.notPredicate(TruePredicate.truePredicate()));
|
||||||
assertEquals(false, PredicateUtils.notPredicate(TruePredicate.truePredicate()).evaluate(null));
|
assertFalse(PredicateUtils.notPredicate(truePredicate()).evaluate(null));
|
||||||
assertEquals(false, PredicateUtils.notPredicate(TruePredicate.truePredicate()).evaluate(cObject));
|
assertFalse(PredicateUtils.notPredicate(truePredicate()).evaluate(cObject));
|
||||||
assertEquals(false, PredicateUtils.notPredicate(TruePredicate.truePredicate()).evaluate(cString));
|
assertFalse(PredicateUtils.notPredicate(truePredicate()).evaluate(cString));
|
||||||
assertEquals(false, PredicateUtils.notPredicate(TruePredicate.truePredicate()).evaluate(cInteger));
|
assertFalse(PredicateUtils.notPredicate(truePredicate()).evaluate(cInteger));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected=NullPointerException.class)
|
@Test(expected=NullPointerException.class)
|
||||||
@ -139,10 +140,10 @@ public class PredicateUtilsTest extends AbstractPredicateTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testAndPredicate() {
|
public void testAndPredicate() {
|
||||||
assertEquals(true, PredicateUtils.andPredicate(TruePredicate.truePredicate(), TruePredicate.truePredicate()).evaluate(null));
|
assertTrue(PredicateUtils.andPredicate(truePredicate(), truePredicate()).evaluate(null));
|
||||||
assertEquals(false, PredicateUtils.andPredicate(TruePredicate.truePredicate(), FalsePredicate.falsePredicate()).evaluate(null));
|
assertFalse(PredicateUtils.andPredicate(truePredicate(), FalsePredicate.falsePredicate()).evaluate(null));
|
||||||
assertEquals(false, PredicateUtils.andPredicate(FalsePredicate.falsePredicate(), TruePredicate.truePredicate()).evaluate(null));
|
assertFalse(PredicateUtils.andPredicate(FalsePredicate.falsePredicate(), truePredicate()).evaluate(null));
|
||||||
assertEquals(false, PredicateUtils.andPredicate(FalsePredicate.falsePredicate(), FalsePredicate.falsePredicate()).evaluate(null));
|
assertFalse(PredicateUtils.andPredicate(FalsePredicate.falsePredicate(), FalsePredicate.falsePredicate()).evaluate(null));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected=NullPointerException.class)
|
@Test(expected=NullPointerException.class)
|
||||||
@ -156,43 +157,39 @@ public class PredicateUtilsTest extends AbstractPredicateTest {
|
|||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
@Test
|
@Test
|
||||||
public void testAllPredicate() {
|
public void testAllPredicate() {
|
||||||
assertTrue(AllPredicate.allPredicate(new Predicate[] {}), null);
|
assertPredicateTrue(AllPredicate.allPredicate(), null);
|
||||||
assertEquals(true, AllPredicate.allPredicate(new Predicate[] {
|
assertTrue(AllPredicate.allPredicate(truePredicate(), truePredicate(), truePredicate()).evaluate(null));
|
||||||
TruePredicate.truePredicate(), TruePredicate.truePredicate(), TruePredicate.truePredicate()}).evaluate(null));
|
assertFalse(AllPredicate.allPredicate(truePredicate(), FalsePredicate.falsePredicate(), truePredicate()).evaluate(null));
|
||||||
assertEquals(false, AllPredicate.allPredicate(new Predicate[] {
|
assertFalse(AllPredicate.allPredicate(FalsePredicate.falsePredicate(), FalsePredicate.falsePredicate(), truePredicate()).evaluate(null));
|
||||||
TruePredicate.truePredicate(), FalsePredicate.falsePredicate(), TruePredicate.truePredicate()}).evaluate(null));
|
assertFalse(AllPredicate.allPredicate(FalsePredicate.falsePredicate(), FalsePredicate.falsePredicate(), FalsePredicate.falsePredicate()).evaluate(null));
|
||||||
assertEquals(false, AllPredicate.allPredicate(new Predicate[] {
|
|
||||||
FalsePredicate.falsePredicate(), FalsePredicate.falsePredicate(), TruePredicate.truePredicate()}).evaluate(null));
|
|
||||||
assertEquals(false, AllPredicate.allPredicate(new Predicate[] {
|
|
||||||
FalsePredicate.falsePredicate(), FalsePredicate.falsePredicate(), FalsePredicate.falsePredicate()}).evaluate(null));
|
|
||||||
final Collection<Predicate<Object>> coll = new ArrayList<>();
|
final Collection<Predicate<Object>> coll = new ArrayList<>();
|
||||||
coll.add(TruePredicate.truePredicate());
|
coll.add(TruePredicate.truePredicate());
|
||||||
coll.add(TruePredicate.truePredicate());
|
coll.add(TruePredicate.truePredicate());
|
||||||
coll.add(TruePredicate.truePredicate());
|
coll.add(TruePredicate.truePredicate());
|
||||||
assertEquals(true, AllPredicate.allPredicate(coll).evaluate(null));
|
assertTrue(AllPredicate.allPredicate(coll).evaluate(null));
|
||||||
coll.clear();
|
coll.clear();
|
||||||
coll.add(TruePredicate.truePredicate());
|
coll.add(TruePredicate.truePredicate());
|
||||||
coll.add(FalsePredicate.falsePredicate());
|
coll.add(FalsePredicate.falsePredicate());
|
||||||
coll.add(TruePredicate.truePredicate());
|
coll.add(TruePredicate.truePredicate());
|
||||||
assertEquals(false, AllPredicate.allPredicate(coll).evaluate(null));
|
assertFalse(AllPredicate.allPredicate(coll).evaluate(null));
|
||||||
coll.clear();
|
coll.clear();
|
||||||
coll.add(FalsePredicate.falsePredicate());
|
coll.add(FalsePredicate.falsePredicate());
|
||||||
coll.add(FalsePredicate.falsePredicate());
|
coll.add(FalsePredicate.falsePredicate());
|
||||||
coll.add(TruePredicate.truePredicate());
|
coll.add(TruePredicate.truePredicate());
|
||||||
assertEquals(false, AllPredicate.allPredicate(coll).evaluate(null));
|
assertFalse(AllPredicate.allPredicate(coll).evaluate(null));
|
||||||
coll.clear();
|
coll.clear();
|
||||||
coll.add(FalsePredicate.falsePredicate());
|
coll.add(FalsePredicate.falsePredicate());
|
||||||
coll.add(FalsePredicate.falsePredicate());
|
coll.add(FalsePredicate.falsePredicate());
|
||||||
coll.add(FalsePredicate.falsePredicate());
|
coll.add(FalsePredicate.falsePredicate());
|
||||||
assertEquals(false, AllPredicate.allPredicate(coll).evaluate(null));
|
assertFalse(AllPredicate.allPredicate(coll).evaluate(null));
|
||||||
coll.clear();
|
coll.clear();
|
||||||
coll.add(FalsePredicate.falsePredicate());
|
coll.add(FalsePredicate.falsePredicate());
|
||||||
assertFalse(AllPredicate.allPredicate(coll), null);
|
assertPredicateFalse(AllPredicate.allPredicate(coll), null);
|
||||||
coll.clear();
|
coll.clear();
|
||||||
coll.add(TruePredicate.truePredicate());
|
coll.add(TruePredicate.truePredicate());
|
||||||
assertTrue(AllPredicate.allPredicate(coll), null);
|
assertPredicateTrue(AllPredicate.allPredicate(coll), null);
|
||||||
coll.clear();
|
coll.clear();
|
||||||
assertTrue(AllPredicate.allPredicate(coll), null);
|
assertPredicateTrue(AllPredicate.allPredicate(coll), null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected=NullPointerException.class)
|
@Test(expected=NullPointerException.class)
|
||||||
@ -206,10 +203,9 @@ public class PredicateUtilsTest extends AbstractPredicateTest {
|
|||||||
AllPredicate.<Object>allPredicate(new Predicate[] { null });
|
AllPredicate.<Object>allPredicate(new Predicate[] { null });
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
@Test(expected=NullPointerException.class)
|
@Test(expected=NullPointerException.class)
|
||||||
public void testAllPredicateEx3() {
|
public void testAllPredicateEx3() {
|
||||||
AllPredicate.allPredicate(new Predicate[] { null, null });
|
AllPredicate.allPredicate(null, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected=NullPointerException.class)
|
@Test(expected=NullPointerException.class)
|
||||||
@ -219,7 +215,7 @@ public class PredicateUtilsTest extends AbstractPredicateTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testAllPredicateEx5() {
|
public void testAllPredicateEx5() {
|
||||||
AllPredicate.allPredicate(Collections.<Predicate<Object>>emptyList());
|
AllPredicate.allPredicate(Collections.emptyList());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected=NullPointerException.class)
|
@Test(expected=NullPointerException.class)
|
||||||
@ -235,10 +231,10 @@ public class PredicateUtilsTest extends AbstractPredicateTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testOrPredicate() {
|
public void testOrPredicate() {
|
||||||
assertEquals(true, PredicateUtils.orPredicate(TruePredicate.truePredicate(), TruePredicate.truePredicate()).evaluate(null));
|
assertTrue(PredicateUtils.orPredicate(truePredicate(), truePredicate()).evaluate(null));
|
||||||
assertEquals(true, PredicateUtils.orPredicate(TruePredicate.truePredicate(), FalsePredicate.falsePredicate()).evaluate(null));
|
assertTrue(PredicateUtils.orPredicate(truePredicate(), FalsePredicate.falsePredicate()).evaluate(null));
|
||||||
assertEquals(true, PredicateUtils.orPredicate(FalsePredicate.falsePredicate(), TruePredicate.truePredicate()).evaluate(null));
|
assertTrue(PredicateUtils.orPredicate(FalsePredicate.falsePredicate(), truePredicate()).evaluate(null));
|
||||||
assertEquals(false, PredicateUtils.orPredicate(FalsePredicate.falsePredicate(), FalsePredicate.falsePredicate()).evaluate(null));
|
assertFalse(PredicateUtils.orPredicate(FalsePredicate.falsePredicate(), FalsePredicate.falsePredicate()).evaluate(null));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected=NullPointerException.class)
|
@Test(expected=NullPointerException.class)
|
||||||
@ -252,44 +248,40 @@ public class PredicateUtilsTest extends AbstractPredicateTest {
|
|||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
@Test
|
@Test
|
||||||
public void testAnyPredicate() {
|
public void testAnyPredicate() {
|
||||||
assertFalse(PredicateUtils.anyPredicate(new Predicate[] {}), null);
|
assertPredicateFalse(PredicateUtils.anyPredicate(), null);
|
||||||
|
|
||||||
assertEquals(true, PredicateUtils.anyPredicate(new Predicate[] {
|
assertTrue(PredicateUtils.anyPredicate(truePredicate(), truePredicate(), truePredicate()).evaluate(null));
|
||||||
TruePredicate.truePredicate(), TruePredicate.truePredicate(), TruePredicate.truePredicate()}).evaluate(null));
|
assertTrue(PredicateUtils.anyPredicate(truePredicate(), FalsePredicate.falsePredicate(), truePredicate()).evaluate(null));
|
||||||
assertEquals(true, PredicateUtils.anyPredicate(new Predicate[] {
|
assertTrue(PredicateUtils.anyPredicate(FalsePredicate.falsePredicate(), FalsePredicate.falsePredicate(), truePredicate()).evaluate(null));
|
||||||
TruePredicate.truePredicate(), FalsePredicate.falsePredicate(), TruePredicate.truePredicate()}).evaluate(null));
|
assertFalse(PredicateUtils.anyPredicate(FalsePredicate.falsePredicate(), FalsePredicate.falsePredicate(), FalsePredicate.falsePredicate()).evaluate(null));
|
||||||
assertEquals(true, PredicateUtils.anyPredicate(new Predicate[] {
|
|
||||||
FalsePredicate.falsePredicate(), FalsePredicate.falsePredicate(), TruePredicate.truePredicate()}).evaluate(null));
|
|
||||||
assertEquals(false, PredicateUtils.anyPredicate(new Predicate[] {
|
|
||||||
FalsePredicate.falsePredicate(), FalsePredicate.falsePredicate(), FalsePredicate.falsePredicate()}).evaluate(null));
|
|
||||||
final Collection<Predicate<Object>> coll = new ArrayList<>();
|
final Collection<Predicate<Object>> coll = new ArrayList<>();
|
||||||
coll.add(TruePredicate.truePredicate());
|
coll.add(TruePredicate.truePredicate());
|
||||||
coll.add(TruePredicate.truePredicate());
|
coll.add(TruePredicate.truePredicate());
|
||||||
coll.add(TruePredicate.truePredicate());
|
coll.add(TruePredicate.truePredicate());
|
||||||
assertEquals(true, PredicateUtils.anyPredicate(coll).evaluate(null));
|
assertTrue(PredicateUtils.anyPredicate(coll).evaluate(null));
|
||||||
coll.clear();
|
coll.clear();
|
||||||
coll.add(TruePredicate.truePredicate());
|
coll.add(TruePredicate.truePredicate());
|
||||||
coll.add(FalsePredicate.falsePredicate());
|
coll.add(FalsePredicate.falsePredicate());
|
||||||
coll.add(TruePredicate.truePredicate());
|
coll.add(TruePredicate.truePredicate());
|
||||||
assertEquals(true, PredicateUtils.anyPredicate(coll).evaluate(null));
|
assertTrue(PredicateUtils.anyPredicate(coll).evaluate(null));
|
||||||
coll.clear();
|
coll.clear();
|
||||||
coll.add(FalsePredicate.falsePredicate());
|
coll.add(FalsePredicate.falsePredicate());
|
||||||
coll.add(FalsePredicate.falsePredicate());
|
coll.add(FalsePredicate.falsePredicate());
|
||||||
coll.add(TruePredicate.truePredicate());
|
coll.add(TruePredicate.truePredicate());
|
||||||
assertEquals(true, PredicateUtils.anyPredicate(coll).evaluate(null));
|
assertTrue(PredicateUtils.anyPredicate(coll).evaluate(null));
|
||||||
coll.clear();
|
coll.clear();
|
||||||
coll.add(FalsePredicate.falsePredicate());
|
coll.add(FalsePredicate.falsePredicate());
|
||||||
coll.add(FalsePredicate.falsePredicate());
|
coll.add(FalsePredicate.falsePredicate());
|
||||||
coll.add(FalsePredicate.falsePredicate());
|
coll.add(FalsePredicate.falsePredicate());
|
||||||
assertEquals(false, PredicateUtils.anyPredicate(coll).evaluate(null));
|
assertFalse(PredicateUtils.anyPredicate(coll).evaluate(null));
|
||||||
coll.clear();
|
coll.clear();
|
||||||
coll.add(FalsePredicate.falsePredicate());
|
coll.add(FalsePredicate.falsePredicate());
|
||||||
assertFalse(PredicateUtils.anyPredicate(coll), null);
|
assertPredicateFalse(PredicateUtils.anyPredicate(coll), null);
|
||||||
coll.clear();
|
coll.clear();
|
||||||
coll.add(TruePredicate.truePredicate());
|
coll.add(TruePredicate.truePredicate());
|
||||||
assertTrue(PredicateUtils.anyPredicate(coll), null);
|
assertPredicateTrue(PredicateUtils.anyPredicate(coll), null);
|
||||||
coll.clear();
|
coll.clear();
|
||||||
assertFalse(PredicateUtils.anyPredicate(coll), null);
|
assertPredicateFalse(PredicateUtils.anyPredicate(coll), null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected=NullPointerException.class)
|
@Test(expected=NullPointerException.class)
|
||||||
@ -303,10 +295,9 @@ public class PredicateUtilsTest extends AbstractPredicateTest {
|
|||||||
PredicateUtils.anyPredicate(new Predicate[] {null});
|
PredicateUtils.anyPredicate(new Predicate[] {null});
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
@Test(expected=NullPointerException.class)
|
@Test(expected=NullPointerException.class)
|
||||||
public void testAnyPredicateEx3() {
|
public void testAnyPredicateEx3() {
|
||||||
PredicateUtils.anyPredicate(new Predicate[] {null, null});
|
PredicateUtils.anyPredicate(null, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected=NullPointerException.class)
|
@Test(expected=NullPointerException.class)
|
||||||
@ -316,7 +307,7 @@ public class PredicateUtilsTest extends AbstractPredicateTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testAnyPredicateEx5() {
|
public void testAnyPredicateEx5() {
|
||||||
PredicateUtils.anyPredicate(Collections.<Predicate<Object>>emptyList());
|
PredicateUtils.anyPredicate(Collections.emptyList());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected=NullPointerException.class)
|
@Test(expected=NullPointerException.class)
|
||||||
@ -332,10 +323,10 @@ public class PredicateUtilsTest extends AbstractPredicateTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testEitherPredicate() {
|
public void testEitherPredicate() {
|
||||||
assertEquals(false, PredicateUtils.eitherPredicate(TruePredicate.truePredicate(), TruePredicate.truePredicate()).evaluate(null));
|
assertFalse(PredicateUtils.eitherPredicate(truePredicate(), truePredicate()).evaluate(null));
|
||||||
assertEquals(true, PredicateUtils.eitherPredicate(TruePredicate.truePredicate(), FalsePredicate.falsePredicate()).evaluate(null));
|
assertTrue(PredicateUtils.eitherPredicate(truePredicate(), FalsePredicate.falsePredicate()).evaluate(null));
|
||||||
assertEquals(true, PredicateUtils.eitherPredicate(FalsePredicate.falsePredicate(), TruePredicate.truePredicate()).evaluate(null));
|
assertTrue(PredicateUtils.eitherPredicate(FalsePredicate.falsePredicate(), truePredicate()).evaluate(null));
|
||||||
assertEquals(false, PredicateUtils.eitherPredicate(FalsePredicate.falsePredicate(), FalsePredicate.falsePredicate()).evaluate(null));
|
assertFalse(PredicateUtils.eitherPredicate(FalsePredicate.falsePredicate(), FalsePredicate.falsePredicate()).evaluate(null));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected=NullPointerException.class)
|
@Test(expected=NullPointerException.class)
|
||||||
@ -349,47 +340,41 @@ public class PredicateUtilsTest extends AbstractPredicateTest {
|
|||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
@Test
|
@Test
|
||||||
public void testOnePredicate() {
|
public void testOnePredicate() {
|
||||||
assertFalse(PredicateUtils.onePredicate((Predicate<Object>[]) new Predicate[] {}), null);
|
assertPredicateFalse(PredicateUtils.onePredicate((Predicate<Object>[]) new Predicate[] {}), null);
|
||||||
assertEquals(false, PredicateUtils.onePredicate(new Predicate[] {
|
assertFalse(PredicateUtils.onePredicate(truePredicate(), truePredicate(), truePredicate()).evaluate(null));
|
||||||
TruePredicate.truePredicate(), TruePredicate.truePredicate(), TruePredicate.truePredicate()}).evaluate(null));
|
assertFalse(PredicateUtils.onePredicate(truePredicate(), FalsePredicate.falsePredicate(), truePredicate()).evaluate(null));
|
||||||
assertEquals(false, PredicateUtils.onePredicate(new Predicate[] {
|
assertTrue(PredicateUtils.onePredicate(truePredicate(), FalsePredicate.falsePredicate(), FalsePredicate.falsePredicate()).evaluate(null));
|
||||||
TruePredicate.truePredicate(), FalsePredicate.falsePredicate(), TruePredicate.truePredicate()}).evaluate(null));
|
assertTrue(PredicateUtils.onePredicate(FalsePredicate.falsePredicate(), truePredicate(), FalsePredicate.falsePredicate()).evaluate(null));
|
||||||
assertEquals(true, PredicateUtils.onePredicate(new Predicate[] {
|
assertTrue(PredicateUtils.onePredicate(FalsePredicate.falsePredicate(), FalsePredicate.falsePredicate(), truePredicate()).evaluate(null));
|
||||||
TruePredicate.truePredicate(), FalsePredicate.falsePredicate(), FalsePredicate.falsePredicate()}).evaluate(null));
|
assertFalse(PredicateUtils.onePredicate(FalsePredicate.falsePredicate(), FalsePredicate.falsePredicate(), FalsePredicate.falsePredicate()).evaluate(null));
|
||||||
assertEquals(true, PredicateUtils.onePredicate(new Predicate[] {
|
|
||||||
FalsePredicate.falsePredicate(), TruePredicate.truePredicate(), FalsePredicate.falsePredicate()}).evaluate(null));
|
|
||||||
assertEquals(true, PredicateUtils.onePredicate(new Predicate[] {
|
|
||||||
FalsePredicate.falsePredicate(), FalsePredicate.falsePredicate(), TruePredicate.truePredicate()}).evaluate(null));
|
|
||||||
assertEquals(false, PredicateUtils.onePredicate(new Predicate[] {
|
|
||||||
FalsePredicate.falsePredicate(), FalsePredicate.falsePredicate(), FalsePredicate.falsePredicate()}).evaluate(null));
|
|
||||||
final Collection<Predicate<Object>> coll = new ArrayList<>();
|
final Collection<Predicate<Object>> coll = new ArrayList<>();
|
||||||
coll.add(TruePredicate.truePredicate());
|
coll.add(TruePredicate.truePredicate());
|
||||||
coll.add(TruePredicate.truePredicate());
|
coll.add(TruePredicate.truePredicate());
|
||||||
coll.add(TruePredicate.truePredicate());
|
coll.add(TruePredicate.truePredicate());
|
||||||
assertEquals(false, PredicateUtils.onePredicate(coll).evaluate(null));
|
assertFalse(PredicateUtils.onePredicate(coll).evaluate(null));
|
||||||
coll.clear();
|
coll.clear();
|
||||||
coll.add(TruePredicate.truePredicate());
|
coll.add(TruePredicate.truePredicate());
|
||||||
coll.add(FalsePredicate.falsePredicate());
|
coll.add(FalsePredicate.falsePredicate());
|
||||||
coll.add(TruePredicate.truePredicate());
|
coll.add(TruePredicate.truePredicate());
|
||||||
assertEquals(false, PredicateUtils.onePredicate(coll).evaluate(null));
|
assertFalse(PredicateUtils.onePredicate(coll).evaluate(null));
|
||||||
coll.clear();
|
coll.clear();
|
||||||
coll.add(FalsePredicate.falsePredicate());
|
coll.add(FalsePredicate.falsePredicate());
|
||||||
coll.add(FalsePredicate.falsePredicate());
|
coll.add(FalsePredicate.falsePredicate());
|
||||||
coll.add(TruePredicate.truePredicate());
|
coll.add(TruePredicate.truePredicate());
|
||||||
assertEquals(true, PredicateUtils.onePredicate(coll).evaluate(null));
|
assertTrue(PredicateUtils.onePredicate(coll).evaluate(null));
|
||||||
coll.clear();
|
coll.clear();
|
||||||
coll.add(FalsePredicate.falsePredicate());
|
coll.add(FalsePredicate.falsePredicate());
|
||||||
coll.add(FalsePredicate.falsePredicate());
|
coll.add(FalsePredicate.falsePredicate());
|
||||||
coll.add(FalsePredicate.falsePredicate());
|
coll.add(FalsePredicate.falsePredicate());
|
||||||
assertEquals(false, PredicateUtils.onePredicate(coll).evaluate(null));
|
assertFalse(PredicateUtils.onePredicate(coll).evaluate(null));
|
||||||
coll.clear();
|
coll.clear();
|
||||||
coll.add(FalsePredicate.falsePredicate());
|
coll.add(FalsePredicate.falsePredicate());
|
||||||
assertFalse(PredicateUtils.onePredicate(coll), null);
|
assertPredicateFalse(PredicateUtils.onePredicate(coll), null);
|
||||||
coll.clear();
|
coll.clear();
|
||||||
coll.add(TruePredicate.truePredicate());
|
coll.add(TruePredicate.truePredicate());
|
||||||
assertTrue(PredicateUtils.onePredicate(coll), null);
|
assertPredicateTrue(PredicateUtils.onePredicate(coll), null);
|
||||||
coll.clear();
|
coll.clear();
|
||||||
assertFalse(PredicateUtils.onePredicate(coll), null);
|
assertPredicateFalse(PredicateUtils.onePredicate(coll), null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected=NullPointerException.class)
|
@Test(expected=NullPointerException.class)
|
||||||
@ -403,10 +388,9 @@ public class PredicateUtilsTest extends AbstractPredicateTest {
|
|||||||
PredicateUtils.onePredicate(new Predicate[] {null});
|
PredicateUtils.onePredicate(new Predicate[] {null});
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
@Test(expected=NullPointerException.class)
|
@Test(expected=NullPointerException.class)
|
||||||
public void testOnePredicateEx3() {
|
public void testOnePredicateEx3() {
|
||||||
PredicateUtils.onePredicate(new Predicate[] {null, null});
|
PredicateUtils.onePredicate(null, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected=NullPointerException.class)
|
@Test(expected=NullPointerException.class)
|
||||||
@ -422,10 +406,7 @@ public class PredicateUtilsTest extends AbstractPredicateTest {
|
|||||||
|
|
||||||
@Test(expected=NullPointerException.class)
|
@Test(expected=NullPointerException.class)
|
||||||
public void testOnePredicateEx6() {
|
public void testOnePredicateEx6() {
|
||||||
final Collection<Predicate<Object>> coll = new ArrayList<>();
|
PredicateUtils.onePredicate(Arrays.asList(null, null));
|
||||||
coll.add(null);
|
|
||||||
coll.add(null);
|
|
||||||
PredicateUtils.onePredicate(coll);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// neitherPredicate
|
// neitherPredicate
|
||||||
@ -433,10 +414,10 @@ public class PredicateUtilsTest extends AbstractPredicateTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testNeitherPredicate() {
|
public void testNeitherPredicate() {
|
||||||
assertEquals(false, PredicateUtils.neitherPredicate(TruePredicate.truePredicate(), TruePredicate.truePredicate()).evaluate(null));
|
assertFalse(PredicateUtils.neitherPredicate(truePredicate(), truePredicate()).evaluate(null));
|
||||||
assertEquals(false, PredicateUtils.neitherPredicate(TruePredicate.truePredicate(), FalsePredicate.falsePredicate()).evaluate(null));
|
assertFalse(PredicateUtils.neitherPredicate(truePredicate(), FalsePredicate.falsePredicate()).evaluate(null));
|
||||||
assertEquals(false, PredicateUtils.neitherPredicate(FalsePredicate.falsePredicate(), TruePredicate.truePredicate()).evaluate(null));
|
assertFalse(PredicateUtils.neitherPredicate(FalsePredicate.falsePredicate(), truePredicate()).evaluate(null));
|
||||||
assertEquals(true, PredicateUtils.neitherPredicate(FalsePredicate.falsePredicate(), FalsePredicate.falsePredicate()).evaluate(null));
|
assertTrue(PredicateUtils.neitherPredicate(FalsePredicate.falsePredicate(), FalsePredicate.falsePredicate()).evaluate(null));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected=NullPointerException.class)
|
@Test(expected=NullPointerException.class)
|
||||||
@ -450,43 +431,39 @@ public class PredicateUtilsTest extends AbstractPredicateTest {
|
|||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
@Test
|
@Test
|
||||||
public void testNonePredicate() {
|
public void testNonePredicate() {
|
||||||
assertTrue(PredicateUtils.nonePredicate(new Predicate[] {}), null);
|
assertPredicateTrue(PredicateUtils.nonePredicate(), null);
|
||||||
assertEquals(false, PredicateUtils.nonePredicate(new Predicate[] {
|
assertFalse(PredicateUtils.nonePredicate(truePredicate(), truePredicate(), truePredicate()).evaluate(null));
|
||||||
TruePredicate.truePredicate(), TruePredicate.truePredicate(), TruePredicate.truePredicate() }).evaluate(null));
|
assertFalse(PredicateUtils.nonePredicate(truePredicate(), FalsePredicate.falsePredicate(), truePredicate()).evaluate(null));
|
||||||
assertEquals(false, PredicateUtils.nonePredicate(new Predicate[] {
|
assertFalse(PredicateUtils.nonePredicate(FalsePredicate.falsePredicate(), FalsePredicate.falsePredicate(), truePredicate()).evaluate(null));
|
||||||
TruePredicate.truePredicate(), FalsePredicate.falsePredicate(), TruePredicate.truePredicate() }).evaluate(null));
|
assertTrue(PredicateUtils.nonePredicate(FalsePredicate.falsePredicate(), FalsePredicate.falsePredicate(), FalsePredicate.falsePredicate()).evaluate(null));
|
||||||
assertEquals(false, PredicateUtils.nonePredicate(new Predicate[] {
|
|
||||||
FalsePredicate.falsePredicate(), FalsePredicate.falsePredicate(), TruePredicate.truePredicate() }).evaluate(null));
|
|
||||||
assertEquals(true, PredicateUtils.nonePredicate(new Predicate[] {
|
|
||||||
FalsePredicate.falsePredicate(), FalsePredicate.falsePredicate(), FalsePredicate.falsePredicate() }).evaluate(null));
|
|
||||||
final Collection<Predicate<Object>> coll = new ArrayList<>();
|
final Collection<Predicate<Object>> coll = new ArrayList<>();
|
||||||
coll.add(TruePredicate.truePredicate());
|
coll.add(TruePredicate.truePredicate());
|
||||||
coll.add(TruePredicate.truePredicate());
|
coll.add(TruePredicate.truePredicate());
|
||||||
coll.add(TruePredicate.truePredicate());
|
coll.add(TruePredicate.truePredicate());
|
||||||
assertEquals(false, PredicateUtils.nonePredicate(coll).evaluate(null));
|
assertFalse(PredicateUtils.nonePredicate(coll).evaluate(null));
|
||||||
coll.clear();
|
coll.clear();
|
||||||
coll.add(TruePredicate.truePredicate());
|
coll.add(TruePredicate.truePredicate());
|
||||||
coll.add(FalsePredicate.falsePredicate());
|
coll.add(FalsePredicate.falsePredicate());
|
||||||
coll.add(TruePredicate.truePredicate());
|
coll.add(TruePredicate.truePredicate());
|
||||||
assertEquals(false, PredicateUtils.nonePredicate(coll).evaluate(null));
|
assertFalse(PredicateUtils.nonePredicate(coll).evaluate(null));
|
||||||
coll.clear();
|
coll.clear();
|
||||||
coll.add(FalsePredicate.falsePredicate());
|
coll.add(FalsePredicate.falsePredicate());
|
||||||
coll.add(FalsePredicate.falsePredicate());
|
coll.add(FalsePredicate.falsePredicate());
|
||||||
coll.add(TruePredicate.truePredicate());
|
coll.add(TruePredicate.truePredicate());
|
||||||
assertEquals(false, PredicateUtils.nonePredicate(coll).evaluate(null));
|
assertFalse(PredicateUtils.nonePredicate(coll).evaluate(null));
|
||||||
coll.clear();
|
coll.clear();
|
||||||
coll.add(FalsePredicate.falsePredicate());
|
coll.add(FalsePredicate.falsePredicate());
|
||||||
coll.add(FalsePredicate.falsePredicate());
|
coll.add(FalsePredicate.falsePredicate());
|
||||||
coll.add(FalsePredicate.falsePredicate());
|
coll.add(FalsePredicate.falsePredicate());
|
||||||
assertEquals(true, PredicateUtils.nonePredicate(coll).evaluate(null));
|
assertTrue(PredicateUtils.nonePredicate(coll).evaluate(null));
|
||||||
coll.clear();
|
coll.clear();
|
||||||
coll.add(FalsePredicate.falsePredicate());
|
coll.add(FalsePredicate.falsePredicate());
|
||||||
assertTrue(PredicateUtils.nonePredicate(coll), null);
|
assertPredicateTrue(PredicateUtils.nonePredicate(coll), null);
|
||||||
coll.clear();
|
coll.clear();
|
||||||
coll.add(TruePredicate.truePredicate());
|
coll.add(TruePredicate.truePredicate());
|
||||||
assertFalse(PredicateUtils.nonePredicate(coll), null);
|
assertPredicateFalse(PredicateUtils.nonePredicate(coll), null);
|
||||||
coll.clear();
|
coll.clear();
|
||||||
assertTrue(PredicateUtils.nonePredicate(coll), null);
|
assertPredicateTrue(PredicateUtils.nonePredicate(coll), null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected=NullPointerException.class)
|
@Test(expected=NullPointerException.class)
|
||||||
@ -503,7 +480,7 @@ public class PredicateUtilsTest extends AbstractPredicateTest {
|
|||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
@Test(expected=NullPointerException.class)
|
@Test(expected=NullPointerException.class)
|
||||||
public void testNonePredicateEx3() {
|
public void testNonePredicateEx3() {
|
||||||
PredicateUtils.nonePredicate(new Predicate[] {null, null});
|
PredicateUtils.nonePredicate(null, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected=NullPointerException.class)
|
@Test(expected=NullPointerException.class)
|
||||||
@ -513,7 +490,7 @@ public class PredicateUtilsTest extends AbstractPredicateTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testNonePredicateEx5() {
|
public void testNonePredicateEx5() {
|
||||||
PredicateUtils.nonePredicate(Collections.<Predicate<Object>>emptyList());
|
PredicateUtils.nonePredicate(Collections.emptyList());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected=NullPointerException.class)
|
@Test(expected=NullPointerException.class)
|
||||||
@ -530,10 +507,10 @@ public class PredicateUtilsTest extends AbstractPredicateTest {
|
|||||||
@Test
|
@Test
|
||||||
public void testInstanceOfPredicate() {
|
public void testInstanceOfPredicate() {
|
||||||
assertNotNull(PredicateUtils.instanceofPredicate(String.class));
|
assertNotNull(PredicateUtils.instanceofPredicate(String.class));
|
||||||
assertEquals(false, PredicateUtils.instanceofPredicate(String.class).evaluate(null));
|
assertFalse(PredicateUtils.instanceofPredicate(String.class).evaluate(null));
|
||||||
assertEquals(false, PredicateUtils.instanceofPredicate(String.class).evaluate(cObject));
|
assertFalse(PredicateUtils.instanceofPredicate(String.class).evaluate(cObject));
|
||||||
assertEquals(true, PredicateUtils.instanceofPredicate(String.class).evaluate(cString));
|
assertTrue(PredicateUtils.instanceofPredicate(String.class).evaluate(cString));
|
||||||
assertEquals(false, PredicateUtils.instanceofPredicate(String.class).evaluate(cInteger));
|
assertFalse(PredicateUtils.instanceofPredicate(String.class).evaluate(cInteger));
|
||||||
}
|
}
|
||||||
|
|
||||||
// uniquePredicate
|
// uniquePredicate
|
||||||
@ -542,12 +519,12 @@ public class PredicateUtilsTest extends AbstractPredicateTest {
|
|||||||
@Test
|
@Test
|
||||||
public void testUniquePredicate() {
|
public void testUniquePredicate() {
|
||||||
final Predicate<Object> p = PredicateUtils.uniquePredicate();
|
final Predicate<Object> p = PredicateUtils.uniquePredicate();
|
||||||
assertEquals(true, p.evaluate(new Object()));
|
assertTrue(p.evaluate(new Object()));
|
||||||
assertEquals(true, p.evaluate(new Object()));
|
assertTrue(p.evaluate(new Object()));
|
||||||
assertEquals(true, p.evaluate(new Object()));
|
assertTrue(p.evaluate(new Object()));
|
||||||
assertEquals(true, p.evaluate(cString));
|
assertTrue(p.evaluate(cString));
|
||||||
assertEquals(false, p.evaluate(cString));
|
assertFalse(p.evaluate(cString));
|
||||||
assertEquals(false, p.evaluate(cString));
|
assertFalse(p.evaluate(cString));
|
||||||
}
|
}
|
||||||
|
|
||||||
// asPredicate(Transformer)
|
// asPredicate(Transformer)
|
||||||
@ -555,8 +532,8 @@ public class PredicateUtilsTest extends AbstractPredicateTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testAsPredicateTransformer() {
|
public void testAsPredicateTransformer() {
|
||||||
assertEquals(false, PredicateUtils.asPredicate(TransformerUtils.<Boolean>nopTransformer()).evaluate(false));
|
assertFalse(PredicateUtils.asPredicate(TransformerUtils.nopTransformer()).evaluate(false));
|
||||||
assertEquals(true, PredicateUtils.asPredicate(TransformerUtils.<Boolean>nopTransformer()).evaluate(true));
|
assertTrue(PredicateUtils.asPredicate(TransformerUtils.nopTransformer()).evaluate(true));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected=NullPointerException.class)
|
@Test(expected=NullPointerException.class)
|
||||||
@ -566,7 +543,7 @@ public class PredicateUtilsTest extends AbstractPredicateTest {
|
|||||||
|
|
||||||
@Test(expected=FunctorException.class)
|
@Test(expected=FunctorException.class)
|
||||||
public void testAsPredicateTransformerEx2() {
|
public void testAsPredicateTransformerEx2() {
|
||||||
PredicateUtils.asPredicate(TransformerUtils.<Boolean>nopTransformer()).evaluate(null);
|
PredicateUtils.asPredicate(TransformerUtils.nopTransformer()).evaluate(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
// invokerPredicate
|
// invokerPredicate
|
||||||
@ -575,9 +552,9 @@ public class PredicateUtilsTest extends AbstractPredicateTest {
|
|||||||
@Test
|
@Test
|
||||||
public void testInvokerPredicate() {
|
public void testInvokerPredicate() {
|
||||||
final List<Object> list = new ArrayList<>();
|
final List<Object> list = new ArrayList<>();
|
||||||
assertEquals(true, PredicateUtils.invokerPredicate("isEmpty").evaluate(list));
|
assertTrue(PredicateUtils.invokerPredicate("isEmpty").evaluate(list));
|
||||||
list.add(new Object());
|
list.add(new Object());
|
||||||
assertEquals(false, PredicateUtils.invokerPredicate("isEmpty").evaluate(list));
|
assertFalse(PredicateUtils.invokerPredicate("isEmpty").evaluate(list));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected=NullPointerException.class)
|
@Test(expected=NullPointerException.class)
|
||||||
@ -601,11 +578,11 @@ public class PredicateUtilsTest extends AbstractPredicateTest {
|
|||||||
@Test
|
@Test
|
||||||
public void testInvokerPredicate2() {
|
public void testInvokerPredicate2() {
|
||||||
final List<String> list = new ArrayList<>();
|
final List<String> list = new ArrayList<>();
|
||||||
assertEquals(false, PredicateUtils.invokerPredicate(
|
assertFalse(PredicateUtils.invokerPredicate(
|
||||||
"contains", new Class[] {Object.class}, new Object[] {cString}).evaluate(list));
|
"contains", new Class[]{Object.class}, new Object[]{cString}).evaluate(list));
|
||||||
list.add(cString);
|
list.add(cString);
|
||||||
assertEquals(true, PredicateUtils.invokerPredicate(
|
assertTrue(PredicateUtils.invokerPredicate(
|
||||||
"contains", new Class[] {Object.class}, new Object[] {cString}).evaluate(list));
|
"contains", new Class[]{Object.class}, new Object[]{cString}).evaluate(list));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected=NullPointerException.class)
|
@Test(expected=NullPointerException.class)
|
||||||
@ -629,7 +606,7 @@ public class PredicateUtilsTest extends AbstractPredicateTest {
|
|||||||
|
|
||||||
@Test(expected=FunctorException.class)
|
@Test(expected=FunctorException.class)
|
||||||
public void testNullIsExceptionPredicate() {
|
public void testNullIsExceptionPredicate() {
|
||||||
assertEquals(true, PredicateUtils.nullIsExceptionPredicate(TruePredicate.truePredicate()).evaluate(new Object()));
|
assertTrue(PredicateUtils.nullIsExceptionPredicate(truePredicate()).evaluate(new Object()));
|
||||||
PredicateUtils.nullIsExceptionPredicate(TruePredicate.truePredicate()).evaluate(null);
|
PredicateUtils.nullIsExceptionPredicate(TruePredicate.truePredicate()).evaluate(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -643,9 +620,9 @@ public class PredicateUtilsTest extends AbstractPredicateTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testNullIsTruePredicate() {
|
public void testNullIsTruePredicate() {
|
||||||
assertEquals(true, PredicateUtils.nullIsTruePredicate(TruePredicate.truePredicate()).evaluate(null));
|
assertTrue(PredicateUtils.nullIsTruePredicate(truePredicate()).evaluate(null));
|
||||||
assertEquals(true, PredicateUtils.nullIsTruePredicate(TruePredicate.truePredicate()).evaluate(new Object()));
|
assertTrue(PredicateUtils.nullIsTruePredicate(truePredicate()).evaluate(new Object()));
|
||||||
assertEquals(false, PredicateUtils.nullIsTruePredicate(FalsePredicate.falsePredicate()).evaluate(new Object()));
|
assertFalse(PredicateUtils.nullIsTruePredicate(FalsePredicate.falsePredicate()).evaluate(new Object()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected=NullPointerException.class)
|
@Test(expected=NullPointerException.class)
|
||||||
@ -658,9 +635,9 @@ public class PredicateUtilsTest extends AbstractPredicateTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testNullIsFalsePredicate() {
|
public void testNullIsFalsePredicate() {
|
||||||
assertEquals(false, PredicateUtils.nullIsFalsePredicate(TruePredicate.truePredicate()).evaluate(null));
|
assertFalse(PredicateUtils.nullIsFalsePredicate(truePredicate()).evaluate(null));
|
||||||
assertEquals(true, PredicateUtils.nullIsFalsePredicate(TruePredicate.truePredicate()).evaluate(new Object()));
|
assertTrue(PredicateUtils.nullIsFalsePredicate(truePredicate()).evaluate(new Object()));
|
||||||
assertEquals(false, PredicateUtils.nullIsFalsePredicate(FalsePredicate.falsePredicate()).evaluate(new Object()));
|
assertFalse(PredicateUtils.nullIsFalsePredicate(FalsePredicate.falsePredicate()).evaluate(new Object()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected=NullPointerException.class)
|
@Test(expected=NullPointerException.class)
|
||||||
@ -673,16 +650,16 @@ public class PredicateUtilsTest extends AbstractPredicateTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testTransformedPredicate() {
|
public void testTransformedPredicate() {
|
||||||
assertEquals(true, PredicateUtils.transformedPredicate(
|
assertTrue(PredicateUtils.transformedPredicate(
|
||||||
TransformerUtils.nopTransformer(),
|
TransformerUtils.nopTransformer(),
|
||||||
TruePredicate.truePredicate()).evaluate(new Object()));
|
truePredicate()).evaluate(new Object()));
|
||||||
|
|
||||||
final Map<Object, Object> map = new HashMap<>();
|
final Map<Object, Object> map = new HashMap<>();
|
||||||
map.put(Boolean.TRUE, "Hello");
|
map.put(Boolean.TRUE, "Hello");
|
||||||
final Transformer<Object, Object> t = TransformerUtils.mapTransformer(map);
|
final Transformer<Object, Object> t = TransformerUtils.mapTransformer(map);
|
||||||
final Predicate<Object> p = EqualPredicate.<Object>equalPredicate("Hello");
|
final Predicate<Object> p = EqualPredicate.<Object>equalPredicate("Hello");
|
||||||
assertEquals(false, PredicateUtils.transformedPredicate(t, p).evaluate(null));
|
assertFalse(PredicateUtils.transformedPredicate(t, p).evaluate(null));
|
||||||
assertEquals(true, PredicateUtils.transformedPredicate(t, p).evaluate(Boolean.TRUE));
|
assertTrue(PredicateUtils.transformedPredicate(t, p).evaluate(Boolean.TRUE));
|
||||||
try {
|
try {
|
||||||
PredicateUtils.transformedPredicate(null, null);
|
PredicateUtils.transformedPredicate(null, null);
|
||||||
fail();
|
fail();
|
||||||
|
@ -18,6 +18,8 @@ package org.apache.commons.collections4;
|
|||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertFalse;
|
import static org.junit.Assert.assertFalse;
|
||||||
|
import static org.junit.Assert.assertNotEquals;
|
||||||
|
import static org.junit.Assert.assertNull;
|
||||||
import static org.junit.Assert.assertSame;
|
import static org.junit.Assert.assertSame;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
import static org.junit.Assert.fail;
|
import static org.junit.Assert.fail;
|
||||||
@ -161,13 +163,13 @@ public class SetUtilsTest {
|
|||||||
final Set<String> a = new HashSet<>(data);
|
final Set<String> a = new HashSet<>(data);
|
||||||
final Set<String> b = new HashSet<>(data);
|
final Set<String> b = new HashSet<>(data);
|
||||||
|
|
||||||
assertEquals(true, a.equals(b));
|
assertEquals(a, b);
|
||||||
assertEquals(true, SetUtils.isEqualSet(a, b));
|
assertTrue(SetUtils.isEqualSet(a, b));
|
||||||
a.clear();
|
a.clear();
|
||||||
assertEquals(false, SetUtils.isEqualSet(a, b));
|
assertFalse(SetUtils.isEqualSet(a, b));
|
||||||
assertEquals(false, SetUtils.isEqualSet(a, null));
|
assertFalse(SetUtils.isEqualSet(a, null));
|
||||||
assertEquals(false, SetUtils.isEqualSet(null, b));
|
assertFalse(SetUtils.isEqualSet(null, b));
|
||||||
assertEquals(true, SetUtils.isEqualSet(null, null));
|
assertTrue(SetUtils.isEqualSet(null, null));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -177,12 +179,12 @@ public class SetUtilsTest {
|
|||||||
final Set<String> a = new HashSet<>(data);
|
final Set<String> a = new HashSet<>(data);
|
||||||
final Set<String> b = new HashSet<>(data);
|
final Set<String> b = new HashSet<>(data);
|
||||||
|
|
||||||
assertEquals(true, a.hashCode() == b.hashCode());
|
assertEquals(a.hashCode(), b.hashCode());
|
||||||
assertEquals(true, a.hashCode() == SetUtils.hashCodeForSet(a));
|
assertEquals(a.hashCode(), SetUtils.hashCodeForSet(a));
|
||||||
assertEquals(true, b.hashCode() == SetUtils.hashCodeForSet(b));
|
assertEquals(b.hashCode(), SetUtils.hashCodeForSet(b));
|
||||||
assertEquals(true, SetUtils.hashCodeForSet(a) == SetUtils.hashCodeForSet(b));
|
assertEquals(SetUtils.hashCodeForSet(a), SetUtils.hashCodeForSet(b));
|
||||||
a.clear();
|
a.clear();
|
||||||
assertEquals(false, SetUtils.hashCodeForSet(a) == SetUtils.hashCodeForSet(b));
|
assertNotEquals(SetUtils.hashCodeForSet(a), SetUtils.hashCodeForSet(b));
|
||||||
assertEquals(0, SetUtils.hashCodeForSet(null));
|
assertEquals(0, SetUtils.hashCodeForSet(null));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -208,7 +210,7 @@ public class SetUtilsTest {
|
|||||||
assertTrue("set contains null", set4.contains(null));
|
assertTrue("set contains null", set4.contains(null));
|
||||||
|
|
||||||
final Set<?> set5 = SetUtils.hashSet((Object[]) null);
|
final Set<?> set5 = SetUtils.hashSet((Object[]) null);
|
||||||
assertEquals("set is null", null, set5);
|
assertNull("set is null", set5);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -269,7 +271,7 @@ public class SetUtilsTest {
|
|||||||
assertTrue("set contains null", set4.contains(null));
|
assertTrue("set contains null", set4.contains(null));
|
||||||
|
|
||||||
final Set<?> set5 = SetUtils.unmodifiableSet((Object[]) null);
|
final Set<?> set5 = SetUtils.unmodifiableSet((Object[]) null);
|
||||||
assertEquals("set is null", null, set5);
|
assertNull("set is null", set5);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -18,6 +18,7 @@ package org.apache.commons.collections4;
|
|||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertNotNull;
|
import static org.junit.Assert.assertNotNull;
|
||||||
|
import static org.junit.Assert.assertNull;
|
||||||
import static org.junit.Assert.assertSame;
|
import static org.junit.Assert.assertSame;
|
||||||
import static org.junit.Assert.fail;
|
import static org.junit.Assert.fail;
|
||||||
|
|
||||||
@ -75,10 +76,10 @@ public class TransformerUtilsTest {
|
|||||||
public void testNullTransformer() {
|
public void testNullTransformer() {
|
||||||
assertNotNull(TransformerUtils.nullTransformer());
|
assertNotNull(TransformerUtils.nullTransformer());
|
||||||
assertSame(TransformerUtils.nullTransformer(), TransformerUtils.nullTransformer());
|
assertSame(TransformerUtils.nullTransformer(), TransformerUtils.nullTransformer());
|
||||||
assertEquals(null, TransformerUtils.nullTransformer().transform(null));
|
assertNull(TransformerUtils.nullTransformer().transform(null));
|
||||||
assertEquals(null, TransformerUtils.nullTransformer().transform(cObject));
|
assertNull(TransformerUtils.nullTransformer().transform(cObject));
|
||||||
assertEquals(null, TransformerUtils.nullTransformer().transform(cString));
|
assertNull(TransformerUtils.nullTransformer().transform(cString));
|
||||||
assertEquals(null, TransformerUtils.nullTransformer().transform(cInteger));
|
assertNull(TransformerUtils.nullTransformer().transform(cInteger));
|
||||||
}
|
}
|
||||||
|
|
||||||
// nopTransformer
|
// nopTransformer
|
||||||
@ -88,7 +89,7 @@ public class TransformerUtilsTest {
|
|||||||
public void testNopTransformer() {
|
public void testNopTransformer() {
|
||||||
assertNotNull(TransformerUtils.nullTransformer());
|
assertNotNull(TransformerUtils.nullTransformer());
|
||||||
assertSame(TransformerUtils.nullTransformer(), TransformerUtils.nullTransformer());
|
assertSame(TransformerUtils.nullTransformer(), TransformerUtils.nullTransformer());
|
||||||
assertEquals(null, TransformerUtils.nopTransformer().transform(null));
|
assertNull(TransformerUtils.nopTransformer().transform(null));
|
||||||
assertEquals(cObject, TransformerUtils.nopTransformer().transform(cObject));
|
assertEquals(cObject, TransformerUtils.nopTransformer().transform(cObject));
|
||||||
assertEquals(cString, TransformerUtils.nopTransformer().transform(cString));
|
assertEquals(cString, TransformerUtils.nopTransformer().transform(cString));
|
||||||
assertEquals(cInteger, TransformerUtils.nopTransformer().transform(cInteger));
|
assertEquals(cInteger, TransformerUtils.nopTransformer().transform(cInteger));
|
||||||
@ -111,7 +112,7 @@ public class TransformerUtilsTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCloneTransformer() {
|
public void testCloneTransformer() {
|
||||||
assertEquals(null, TransformerUtils.cloneTransformer().transform(null));
|
assertNull(TransformerUtils.cloneTransformer().transform(null));
|
||||||
assertEquals(cString, TransformerUtils.cloneTransformer().transform(cString));
|
assertEquals(cString, TransformerUtils.cloneTransformer().transform(cString));
|
||||||
assertEquals(cInteger, TransformerUtils.cloneTransformer().transform(cInteger));
|
assertEquals(cInteger, TransformerUtils.cloneTransformer().transform(cInteger));
|
||||||
try {
|
try {
|
||||||
@ -135,7 +136,7 @@ public class TransformerUtilsTest {
|
|||||||
assertEquals(Integer.valueOf(0), TransformerUtils.mapTransformer(map).transform(null));
|
assertEquals(Integer.valueOf(0), TransformerUtils.mapTransformer(map).transform(null));
|
||||||
assertEquals(Integer.valueOf(1), TransformerUtils.mapTransformer(map).transform(cObject));
|
assertEquals(Integer.valueOf(1), TransformerUtils.mapTransformer(map).transform(cObject));
|
||||||
assertEquals(Integer.valueOf(2), TransformerUtils.mapTransformer(map).transform(cString));
|
assertEquals(Integer.valueOf(2), TransformerUtils.mapTransformer(map).transform(cString));
|
||||||
assertEquals(null, TransformerUtils.mapTransformer(map).transform(cInteger));
|
assertNull(TransformerUtils.mapTransformer(map).transform(cInteger));
|
||||||
assertSame(ConstantTransformer.NULL_INSTANCE, TransformerUtils.mapTransformer(null));
|
assertSame(ConstantTransformer.NULL_INSTANCE, TransformerUtils.mapTransformer(null));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -144,7 +145,7 @@ public class TransformerUtilsTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testExecutorTransformer() {
|
public void testExecutorTransformer() {
|
||||||
assertEquals(null, TransformerUtils.asTransformer(ClosureUtils.nopClosure()).transform(null));
|
assertNull(TransformerUtils.asTransformer(ClosureUtils.nopClosure()).transform(null));
|
||||||
assertEquals(cObject, TransformerUtils.asTransformer(ClosureUtils.nopClosure()).transform(cObject));
|
assertEquals(cObject, TransformerUtils.asTransformer(ClosureUtils.nopClosure()).transform(cObject));
|
||||||
assertEquals(cString, TransformerUtils.asTransformer(ClosureUtils.nopClosure()).transform(cString));
|
assertEquals(cString, TransformerUtils.asTransformer(ClosureUtils.nopClosure()).transform(cString));
|
||||||
assertEquals(cInteger, TransformerUtils.asTransformer(ClosureUtils.nopClosure()).transform(cInteger));
|
assertEquals(cInteger, TransformerUtils.asTransformer(ClosureUtils.nopClosure()).transform(cInteger));
|
||||||
@ -178,10 +179,10 @@ public class TransformerUtilsTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testFactoryTransformer() {
|
public void testFactoryTransformer() {
|
||||||
assertEquals(null, TransformerUtils.asTransformer(FactoryUtils.nullFactory()).transform(null));
|
assertNull(TransformerUtils.asTransformer(FactoryUtils.nullFactory()).transform(null));
|
||||||
assertEquals(null, TransformerUtils.asTransformer(FactoryUtils.nullFactory()).transform(cObject));
|
assertNull(TransformerUtils.asTransformer(FactoryUtils.nullFactory()).transform(cObject));
|
||||||
assertEquals(null, TransformerUtils.asTransformer(FactoryUtils.nullFactory()).transform(cString));
|
assertNull(TransformerUtils.asTransformer(FactoryUtils.nullFactory()).transform(cString));
|
||||||
assertEquals(null, TransformerUtils.asTransformer(FactoryUtils.nullFactory()).transform(cInteger));
|
assertNull(TransformerUtils.asTransformer(FactoryUtils.nullFactory()).transform(cInteger));
|
||||||
try {
|
try {
|
||||||
TransformerUtils.asTransformer((Factory<Object>) null);
|
TransformerUtils.asTransformer((Factory<Object>) null);
|
||||||
} catch (final NullPointerException ex) {
|
} catch (final NullPointerException ex) {
|
||||||
@ -249,13 +250,13 @@ public class TransformerUtilsTest {
|
|||||||
|
|
||||||
final Predicate<Integer> lessThanFivePredicate = value -> value < 5;
|
final Predicate<Integer> lessThanFivePredicate = value -> value < 5;
|
||||||
// if/else tests
|
// if/else tests
|
||||||
assertEquals("A", TransformerUtils.<Integer, String>ifTransformer(lessThanFivePredicate, a, b).transform(1));
|
assertEquals("A", TransformerUtils.ifTransformer(lessThanFivePredicate, a, b).transform(1));
|
||||||
assertEquals("B", TransformerUtils.<Integer, String>ifTransformer(lessThanFivePredicate, a, b).transform(5));
|
assertEquals("B", TransformerUtils.ifTransformer(lessThanFivePredicate, a, b).transform(5));
|
||||||
|
|
||||||
// if tests
|
// if tests
|
||||||
final Predicate<String> equalsAPredicate = EqualPredicate.equalPredicate("A");
|
final Predicate<String> equalsAPredicate = EqualPredicate.equalPredicate("A");
|
||||||
assertEquals("C", TransformerUtils.<String>ifTransformer(equalsAPredicate, c).transform("A"));
|
assertEquals("C", TransformerUtils.ifTransformer(equalsAPredicate, c).transform("A"));
|
||||||
assertEquals("B", TransformerUtils.<String>ifTransformer(equalsAPredicate, c).transform("B"));
|
assertEquals("B", TransformerUtils.ifTransformer(equalsAPredicate, c).transform("B"));
|
||||||
|
|
||||||
try {
|
try {
|
||||||
TransformerUtils.ifTransformer(null, null);
|
TransformerUtils.ifTransformer(null, null);
|
||||||
@ -288,9 +289,9 @@ public class TransformerUtilsTest {
|
|||||||
assertEquals("A", TransformerUtils.switchTransformer(TruePredicate.truePredicate(), a, b).transform(null));
|
assertEquals("A", TransformerUtils.switchTransformer(TruePredicate.truePredicate(), a, b).transform(null));
|
||||||
assertEquals("B", TransformerUtils.switchTransformer(FalsePredicate.falsePredicate(), a, b).transform(null));
|
assertEquals("B", TransformerUtils.switchTransformer(FalsePredicate.falsePredicate(), a, b).transform(null));
|
||||||
|
|
||||||
assertEquals(null, TransformerUtils.<Object, String>switchTransformer(
|
assertNull(TransformerUtils.<Object, String>switchTransformer(
|
||||||
new Predicate[] { EqualPredicate.equalPredicate("HELLO"), EqualPredicate.equalPredicate("THERE") },
|
new Predicate[]{EqualPredicate.equalPredicate("HELLO"), EqualPredicate.equalPredicate("THERE")},
|
||||||
new Transformer[] { a, b }).transform("WELL"));
|
new Transformer[]{a, b}).transform("WELL"));
|
||||||
assertEquals("A", TransformerUtils.switchTransformer(
|
assertEquals("A", TransformerUtils.switchTransformer(
|
||||||
new Predicate[] { EqualPredicate.equalPredicate("HELLO"), EqualPredicate.equalPredicate("THERE") },
|
new Predicate[] { EqualPredicate.equalPredicate("HELLO"), EqualPredicate.equalPredicate("THERE") },
|
||||||
new Transformer[] { a, b }).transform("HELLO"));
|
new Transformer[] { a, b }).transform("HELLO"));
|
||||||
@ -305,7 +306,7 @@ public class TransformerUtilsTest {
|
|||||||
Map<Predicate<String>, Transformer<String, String>> map = new HashMap<>();
|
Map<Predicate<String>, Transformer<String, String>> map = new HashMap<>();
|
||||||
map.put(EqualPredicate.equalPredicate("HELLO"), a);
|
map.put(EqualPredicate.equalPredicate("HELLO"), a);
|
||||||
map.put(EqualPredicate.equalPredicate("THERE"), b);
|
map.put(EqualPredicate.equalPredicate("THERE"), b);
|
||||||
assertEquals(null, TransformerUtils.switchTransformer(map).transform("WELL"));
|
assertNull(TransformerUtils.switchTransformer(map).transform("WELL"));
|
||||||
assertEquals("A", TransformerUtils.switchTransformer(map).transform("HELLO"));
|
assertEquals("A", TransformerUtils.switchTransformer(map).transform("HELLO"));
|
||||||
assertEquals("B", TransformerUtils.switchTransformer(map).transform("THERE"));
|
assertEquals("B", TransformerUtils.switchTransformer(map).transform("THERE"));
|
||||||
map.put(null, c);
|
map.put(null, c);
|
||||||
@ -322,11 +323,11 @@ public class TransformerUtilsTest {
|
|||||||
fail();
|
fail();
|
||||||
} catch (final NullPointerException ex) {}
|
} catch (final NullPointerException ex) {}
|
||||||
try {
|
try {
|
||||||
TransformerUtils.switchTransformer((Predicate[]) null, (Transformer[]) null);
|
TransformerUtils.switchTransformer(null, (Transformer[]) null);
|
||||||
fail();
|
fail();
|
||||||
} catch (final NullPointerException ex) {}
|
} catch (final NullPointerException ex) {}
|
||||||
try {
|
try {
|
||||||
TransformerUtils.switchTransformer((Map<Predicate<Object>, Transformer<Object, Object>>) null);
|
TransformerUtils.switchTransformer(null);
|
||||||
fail();
|
fail();
|
||||||
} catch (final NullPointerException ex) {}
|
} catch (final NullPointerException ex) {}
|
||||||
try {
|
try {
|
||||||
@ -353,7 +354,7 @@ public class TransformerUtilsTest {
|
|||||||
Map<String, Transformer<String, String>> map = new HashMap<>();
|
Map<String, Transformer<String, String>> map = new HashMap<>();
|
||||||
map.put("HELLO", a);
|
map.put("HELLO", a);
|
||||||
map.put("THERE", b);
|
map.put("THERE", b);
|
||||||
assertEquals(null, TransformerUtils.switchMapTransformer(map).transform("WELL"));
|
assertNull(TransformerUtils.switchMapTransformer(map).transform("WELL"));
|
||||||
assertEquals("A", TransformerUtils.switchMapTransformer(map).transform("HELLO"));
|
assertEquals("A", TransformerUtils.switchMapTransformer(map).transform("HELLO"));
|
||||||
assertEquals("B", TransformerUtils.switchMapTransformer(map).transform("THERE"));
|
assertEquals("B", TransformerUtils.switchMapTransformer(map).transform("THERE"));
|
||||||
map.put(null, c);
|
map.put(null, c);
|
||||||
@ -376,10 +377,10 @@ public class TransformerUtilsTest {
|
|||||||
@Test
|
@Test
|
||||||
public void testInvokerTransformer() {
|
public void testInvokerTransformer() {
|
||||||
final List<Object> list = new ArrayList<>();
|
final List<Object> list = new ArrayList<>();
|
||||||
assertEquals(Integer.valueOf(0), TransformerUtils.invokerTransformer("size").transform(list));
|
assertEquals(0, TransformerUtils.invokerTransformer("size").transform(list));
|
||||||
list.add(new Object());
|
list.add(new Object());
|
||||||
assertEquals(Integer.valueOf(1), TransformerUtils.invokerTransformer("size").transform(list));
|
assertEquals(1, TransformerUtils.invokerTransformer("size").transform(list));
|
||||||
assertEquals(null, TransformerUtils.invokerTransformer("size").transform(null));
|
assertNull(TransformerUtils.invokerTransformer("size").transform(null));
|
||||||
|
|
||||||
try {
|
try {
|
||||||
TransformerUtils.invokerTransformer(null);
|
TransformerUtils.invokerTransformer(null);
|
||||||
@ -402,8 +403,8 @@ public class TransformerUtilsTest {
|
|||||||
list.add(cString);
|
list.add(cString);
|
||||||
assertEquals(Boolean.TRUE, TransformerUtils.invokerTransformer("contains",
|
assertEquals(Boolean.TRUE, TransformerUtils.invokerTransformer("contains",
|
||||||
new Class[] { Object.class }, new Object[] { cString }).transform(list));
|
new Class[] { Object.class }, new Object[] { cString }).transform(list));
|
||||||
assertEquals(null, TransformerUtils.invokerTransformer("contains",
|
assertNull(TransformerUtils.invokerTransformer("contains",
|
||||||
new Class[] { Object.class }, new Object[] { cString }).transform(null));
|
new Class[]{Object.class}, new Object[]{cString}).transform(null));
|
||||||
|
|
||||||
try {
|
try {
|
||||||
TransformerUtils.invokerTransformer(null, null, null);
|
TransformerUtils.invokerTransformer(null, null, null);
|
||||||
@ -438,7 +439,7 @@ public class TransformerUtilsTest {
|
|||||||
assertEquals( "StringValueTransformer should return \"null\" when given a null argument.", "null",
|
assertEquals( "StringValueTransformer should return \"null\" when given a null argument.", "null",
|
||||||
TransformerUtils.stringValueTransformer().transform(null));
|
TransformerUtils.stringValueTransformer().transform(null));
|
||||||
assertEquals( "StringValueTransformer should return toString value", "6",
|
assertEquals( "StringValueTransformer should return toString value", "6",
|
||||||
TransformerUtils.stringValueTransformer().transform(Integer.valueOf(6)));
|
TransformerUtils.stringValueTransformer().transform(6));
|
||||||
}
|
}
|
||||||
|
|
||||||
// instantiateFactory
|
// instantiateFactory
|
||||||
@ -464,7 +465,7 @@ public class TransformerUtilsTest {
|
|||||||
trans = TransformerUtils.instantiateTransformer();
|
trans = TransformerUtils.instantiateTransformer();
|
||||||
assertEquals("", trans.transform(String.class));
|
assertEquals("", trans.transform(String.class));
|
||||||
|
|
||||||
trans = TransformerUtils.instantiateTransformer(new Class[] { Long.TYPE }, new Object[] { new Long(1000L) });
|
trans = TransformerUtils.instantiateTransformer(new Class[] { Long.TYPE }, new Object[] {1000L});
|
||||||
assertEquals(new Date(1000L), trans.transform(Date.class));
|
assertEquals(new Date(1000L), trans.transform(Date.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -33,6 +33,8 @@ import org.apache.commons.collections4.BulkTest;
|
|||||||
import org.apache.commons.collections4.collection.AbstractCollectionTest;
|
import org.apache.commons.collections4.collection.AbstractCollectionTest;
|
||||||
import org.apache.commons.collections4.set.AbstractSetTest;
|
import org.apache.commons.collections4.set.AbstractSetTest;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertNotEquals;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Abstract test class for {@link org.apache.commons.collections4.Bag Bag} methods and contracts.
|
* Abstract test class for {@link org.apache.commons.collections4.Bag Bag} methods and contracts.
|
||||||
* <p>
|
* <p>
|
||||||
@ -76,8 +78,7 @@ public abstract class AbstractBagTest<T> extends AbstractCollectionTest<T> {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public Collection<T> makeConfirmedCollection() {
|
public Collection<T> makeConfirmedCollection() {
|
||||||
final ArrayList<T> list = new ArrayList<>();
|
return new ArrayList<>();
|
||||||
return list;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -155,18 +156,18 @@ public abstract class AbstractBagTest<T> extends AbstractCollectionTest<T> {
|
|||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public void testBagEqualsSelf() {
|
public void testBagEqualsSelf() {
|
||||||
final Bag<T> bag = makeObject();
|
final Bag<T> bag = makeObject();
|
||||||
assertTrue(bag.equals(bag));
|
assertEquals(bag, bag);
|
||||||
|
|
||||||
if (!isAddSupported()) {
|
if (!isAddSupported()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
bag.add((T) "elt");
|
bag.add((T) "elt");
|
||||||
assertTrue(bag.equals(bag));
|
assertEquals(bag, bag);
|
||||||
bag.add((T) "elt"); // again
|
bag.add((T) "elt"); // again
|
||||||
assertTrue(bag.equals(bag));
|
assertEquals(bag, bag);
|
||||||
bag.add((T) "elt2");
|
bag.add((T) "elt2");
|
||||||
assertTrue(bag.equals(bag));
|
assertEquals(bag, bag);
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
@ -223,20 +224,20 @@ public abstract class AbstractBagTest<T> extends AbstractCollectionTest<T> {
|
|||||||
|
|
||||||
final Bag<T> bag = makeObject();
|
final Bag<T> bag = makeObject();
|
||||||
|
|
||||||
assertEquals("Bag does not have at least 1 'A'", false, bag.contains("A"));
|
assertFalse("Bag does not have at least 1 'A'", bag.contains("A"));
|
||||||
assertEquals("Bag does not have at least 1 'B'", false, bag.contains("B"));
|
assertFalse("Bag does not have at least 1 'B'", bag.contains("B"));
|
||||||
|
|
||||||
bag.add((T) "A"); // bag 1A
|
bag.add((T) "A"); // bag 1A
|
||||||
assertEquals("Bag has at least 1 'A'", true, bag.contains("A"));
|
assertTrue("Bag has at least 1 'A'", bag.contains("A"));
|
||||||
assertEquals("Bag does not have at least 1 'B'", false, bag.contains("B"));
|
assertFalse("Bag does not have at least 1 'B'", bag.contains("B"));
|
||||||
|
|
||||||
bag.add((T) "A"); // bag 2A
|
bag.add((T) "A"); // bag 2A
|
||||||
assertEquals("Bag has at least 1 'A'", true, bag.contains("A"));
|
assertTrue("Bag has at least 1 'A'", bag.contains("A"));
|
||||||
assertEquals("Bag does not have at least 1 'B'", false, bag.contains("B"));
|
assertFalse("Bag does not have at least 1 'B'", bag.contains("B"));
|
||||||
|
|
||||||
bag.add((T) "B"); // bag 2A,1B
|
bag.add((T) "B"); // bag 2A,1B
|
||||||
assertEquals("Bag has at least 1 'A'", true, bag.contains("A"));
|
assertTrue("Bag has at least 1 'A'", bag.contains("A"));
|
||||||
assertEquals("Bag has at least 1 'B'", true, bag.contains("B"));
|
assertTrue("Bag has at least 1 'B'", bag.contains("B"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
@ -258,39 +259,39 @@ public abstract class AbstractBagTest<T> extends AbstractCollectionTest<T> {
|
|||||||
known1A1B.add("A");
|
known1A1B.add("A");
|
||||||
known1A1B.add("B");
|
known1A1B.add("B");
|
||||||
|
|
||||||
assertEquals("Bag containsAll of empty", true, bag.containsAll(known));
|
assertTrue("Bag containsAll of empty", bag.containsAll(known));
|
||||||
assertEquals("Bag does not containsAll of 1 'A'", false, bag.containsAll(known1A));
|
assertFalse("Bag does not containsAll of 1 'A'", bag.containsAll(known1A));
|
||||||
assertEquals("Bag does not containsAll of 2 'A'", false, bag.containsAll(known2A));
|
assertFalse("Bag does not containsAll of 2 'A'", bag.containsAll(known2A));
|
||||||
assertEquals("Bag does not containsAll of 1 'B'", false, bag.containsAll(known1B));
|
assertFalse("Bag does not containsAll of 1 'B'", bag.containsAll(known1B));
|
||||||
assertEquals("Bag does not containsAll of 1 'A' 1 'B'", false, bag.containsAll(known1A1B));
|
assertFalse("Bag does not containsAll of 1 'A' 1 'B'", bag.containsAll(known1A1B));
|
||||||
|
|
||||||
bag.add((T) "A"); // bag 1A
|
bag.add((T) "A"); // bag 1A
|
||||||
assertEquals("Bag containsAll of empty", true, bag.containsAll(known));
|
assertTrue("Bag containsAll of empty", bag.containsAll(known));
|
||||||
assertEquals("Bag containsAll of 1 'A'", true, bag.containsAll(known1A));
|
assertTrue("Bag containsAll of 1 'A'", bag.containsAll(known1A));
|
||||||
assertEquals("Bag does not containsAll of 2 'A'", false, bag.containsAll(known2A));
|
assertFalse("Bag does not containsAll of 2 'A'", bag.containsAll(known2A));
|
||||||
assertEquals("Bag does not containsAll of 1 'B'", false, bag.containsAll(known1B));
|
assertFalse("Bag does not containsAll of 1 'B'", bag.containsAll(known1B));
|
||||||
assertEquals("Bag does not containsAll of 1 'A' 1 'B'", false, bag.containsAll(known1A1B));
|
assertFalse("Bag does not containsAll of 1 'A' 1 'B'", bag.containsAll(known1A1B));
|
||||||
|
|
||||||
bag.add((T) "A"); // bag 2A
|
bag.add((T) "A"); // bag 2A
|
||||||
assertEquals("Bag containsAll of empty", true, bag.containsAll(known));
|
assertTrue("Bag containsAll of empty", bag.containsAll(known));
|
||||||
assertEquals("Bag containsAll of 1 'A'", true, bag.containsAll(known1A));
|
assertTrue("Bag containsAll of 1 'A'", bag.containsAll(known1A));
|
||||||
assertEquals("Bag containsAll of 2 'A'", true, bag.containsAll(known2A));
|
assertTrue("Bag containsAll of 2 'A'", bag.containsAll(known2A));
|
||||||
assertEquals("Bag does not containsAll of 1 'B'", false, bag.containsAll(known1B));
|
assertFalse("Bag does not containsAll of 1 'B'", bag.containsAll(known1B));
|
||||||
assertEquals("Bag does not containsAll of 1 'A' 1 'B'", false, bag.containsAll(known1A1B));
|
assertFalse("Bag does not containsAll of 1 'A' 1 'B'", bag.containsAll(known1A1B));
|
||||||
|
|
||||||
bag.add((T) "A"); // bag 3A
|
bag.add((T) "A"); // bag 3A
|
||||||
assertEquals("Bag containsAll of empty", true, bag.containsAll(known));
|
assertTrue("Bag containsAll of empty", bag.containsAll(known));
|
||||||
assertEquals("Bag containsAll of 1 'A'", true, bag.containsAll(known1A));
|
assertTrue("Bag containsAll of 1 'A'", bag.containsAll(known1A));
|
||||||
assertEquals("Bag containsAll of 2 'A'", true, bag.containsAll(known2A));
|
assertTrue("Bag containsAll of 2 'A'", bag.containsAll(known2A));
|
||||||
assertEquals("Bag does not containsAll of 1 'B'", false, bag.containsAll(known1B));
|
assertFalse("Bag does not containsAll of 1 'B'", bag.containsAll(known1B));
|
||||||
assertEquals("Bag does not containsAll of 1 'A' 1 'B'", false, bag.containsAll(known1A1B));
|
assertFalse("Bag does not containsAll of 1 'A' 1 'B'", bag.containsAll(known1A1B));
|
||||||
|
|
||||||
bag.add((T) "B"); // bag 3A1B
|
bag.add((T) "B"); // bag 3A1B
|
||||||
assertEquals("Bag containsAll of empty", true, bag.containsAll(known));
|
assertTrue("Bag containsAll of empty", bag.containsAll(known));
|
||||||
assertEquals("Bag containsAll of 1 'A'", true, bag.containsAll(known1A));
|
assertTrue("Bag containsAll of 1 'A'", bag.containsAll(known1A));
|
||||||
assertEquals("Bag containsAll of 2 'A'", true, bag.containsAll(known2A));
|
assertTrue("Bag containsAll of 2 'A'", bag.containsAll(known2A));
|
||||||
assertEquals("Bag containsAll of 1 'B'", true, bag.containsAll(known1B));
|
assertTrue("Bag containsAll of 1 'B'", bag.containsAll(known1B));
|
||||||
assertEquals("Bag containsAll of 1 'A' 1 'B'", true, bag.containsAll(known1A1B));
|
assertTrue("Bag containsAll of 1 'A' 1 'B'", bag.containsAll(known1A1B));
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
@ -452,18 +453,18 @@ public abstract class AbstractBagTest<T> extends AbstractCollectionTest<T> {
|
|||||||
assertEquals(2, bag.size());
|
assertEquals(2, bag.size());
|
||||||
final Iterator<T> it = bag.iterator();
|
final Iterator<T> it = bag.iterator();
|
||||||
assertEquals("A", it.next());
|
assertEquals("A", it.next());
|
||||||
assertEquals(true, it.hasNext());
|
assertTrue(it.hasNext());
|
||||||
it.remove();
|
it.remove();
|
||||||
assertEquals(1, bag.size());
|
assertEquals(1, bag.size());
|
||||||
assertEquals(true, it.hasNext());
|
assertTrue(it.hasNext());
|
||||||
assertEquals("A", it.next());
|
assertEquals("A", it.next());
|
||||||
assertEquals(false, it.hasNext());
|
assertFalse(it.hasNext());
|
||||||
it.remove();
|
it.remove();
|
||||||
assertEquals(0, bag.size());
|
assertEquals(0, bag.size());
|
||||||
assertEquals(false, it.hasNext());
|
assertFalse(it.hasNext());
|
||||||
|
|
||||||
final Iterator<T> it2 = bag.iterator();
|
final Iterator<T> it2 = bag.iterator();
|
||||||
assertEquals(false, it2.hasNext());
|
assertFalse(it2.hasNext());
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
@ -523,11 +524,11 @@ public abstract class AbstractBagTest<T> extends AbstractCollectionTest<T> {
|
|||||||
|
|
||||||
final Bag<T> bag = makeObject();
|
final Bag<T> bag = makeObject();
|
||||||
final Bag<T> bag2 = makeObject();
|
final Bag<T> bag2 = makeObject();
|
||||||
assertEquals(true, bag.equals(bag2));
|
assertEquals(bag, bag2);
|
||||||
bag.add((T) "A");
|
bag.add((T) "A");
|
||||||
assertEquals(false, bag.equals(bag2));
|
assertNotEquals(bag, bag2);
|
||||||
bag2.add((T) "A");
|
bag2.add((T) "A");
|
||||||
assertEquals(true, bag.equals(bag2));
|
assertEquals(bag, bag2);
|
||||||
bag.add((T) "A");
|
bag.add((T) "A");
|
||||||
bag.add((T) "B");
|
bag.add((T) "B");
|
||||||
bag.add((T) "B");
|
bag.add((T) "B");
|
||||||
@ -536,7 +537,7 @@ public abstract class AbstractBagTest<T> extends AbstractCollectionTest<T> {
|
|||||||
bag2.add((T) "B");
|
bag2.add((T) "B");
|
||||||
bag2.add((T) "B");
|
bag2.add((T) "B");
|
||||||
bag2.add((T) "C");
|
bag2.add((T) "C");
|
||||||
assertEquals(true, bag.equals(bag2));
|
assertEquals(bag, bag2);
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
@ -547,11 +548,11 @@ public abstract class AbstractBagTest<T> extends AbstractCollectionTest<T> {
|
|||||||
|
|
||||||
final Bag<T> bag = makeObject();
|
final Bag<T> bag = makeObject();
|
||||||
final Bag<T> bag2 = new HashBag<>();
|
final Bag<T> bag2 = new HashBag<>();
|
||||||
assertEquals(true, bag.equals(bag2));
|
assertEquals(bag, bag2);
|
||||||
bag.add((T) "A");
|
bag.add((T) "A");
|
||||||
assertEquals(false, bag.equals(bag2));
|
assertNotEquals(bag, bag2);
|
||||||
bag2.add((T) "A");
|
bag2.add((T) "A");
|
||||||
assertEquals(true, bag.equals(bag2));
|
assertEquals(bag, bag2);
|
||||||
bag.add((T) "A");
|
bag.add((T) "A");
|
||||||
bag.add((T) "B");
|
bag.add((T) "B");
|
||||||
bag.add((T) "B");
|
bag.add((T) "B");
|
||||||
@ -560,7 +561,7 @@ public abstract class AbstractBagTest<T> extends AbstractCollectionTest<T> {
|
|||||||
bag2.add((T) "B");
|
bag2.add((T) "B");
|
||||||
bag2.add((T) "B");
|
bag2.add((T) "B");
|
||||||
bag2.add((T) "C");
|
bag2.add((T) "C");
|
||||||
assertEquals(true, bag.equals(bag2));
|
assertEquals(bag, bag2);
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
@ -684,7 +685,7 @@ public abstract class AbstractBagTest<T> extends AbstractCollectionTest<T> {
|
|||||||
final Bag<T> bag = makeObject();
|
final Bag<T> bag = makeObject();
|
||||||
if (bag instanceof Serializable && !skipSerializedCanonicalTests() && isTestSerialization()) {
|
if (bag instanceof Serializable && !skipSerializedCanonicalTests() && isTestSerialization()) {
|
||||||
final Bag<?> bag2 = (Bag<?>) readExternalFormFromDisk(getCanonicalEmptyCollectionName(bag));
|
final Bag<?> bag2 = (Bag<?>) readExternalFormFromDisk(getCanonicalEmptyCollectionName(bag));
|
||||||
assertTrue("Bag is empty", bag2.size() == 0);
|
assertTrue("Bag is empty", bag2.isEmpty());
|
||||||
assertEquals(bag, bag2);
|
assertEquals(bag, bag2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -96,7 +96,7 @@ public class CollectionBagTest<T> extends AbstractCollectionTest<T> {
|
|||||||
final Bag<T> bag = makeObject();
|
final Bag<T> bag = makeObject();
|
||||||
if (bag instanceof Serializable && !skipSerializedCanonicalTests() && isTestSerialization()) {
|
if (bag instanceof Serializable && !skipSerializedCanonicalTests() && isTestSerialization()) {
|
||||||
final Bag<?> bag2 = (Bag<?>) readExternalFormFromDisk(getCanonicalEmptyCollectionName(bag));
|
final Bag<?> bag2 = (Bag<?>) readExternalFormFromDisk(getCanonicalEmptyCollectionName(bag));
|
||||||
assertTrue("Bag is empty", bag2.size() == 0);
|
assertTrue("Bag is empty", bag2.isEmpty());
|
||||||
assertEquals(bag, bag2);
|
assertEquals(bag, bag2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -136,7 +136,7 @@ public class CollectionSortedBagTest<T> extends AbstractCollectionTest<T> {
|
|||||||
final Bag<T> bag = makeObject();
|
final Bag<T> bag = makeObject();
|
||||||
if (bag instanceof Serializable && !skipSerializedCanonicalTests() && isTestSerialization()) {
|
if (bag instanceof Serializable && !skipSerializedCanonicalTests() && isTestSerialization()) {
|
||||||
final Bag<?> bag2 = (Bag<?>) readExternalFormFromDisk(getCanonicalEmptyCollectionName(bag));
|
final Bag<?> bag2 = (Bag<?>) readExternalFormFromDisk(getCanonicalEmptyCollectionName(bag));
|
||||||
assertTrue("Bag is empty", bag2.size() == 0);
|
assertEquals("Bag is empty", 0, bag2.size());
|
||||||
assertEquals(bag, bag2);
|
assertEquals(bag, bag2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -72,28 +72,26 @@ public class PredicatedBagTest<T> extends AbstractBagTest<T> {
|
|||||||
for (int i = 0; i < els.length; i++) {
|
for (int i = 0; i < els.length; i++) {
|
||||||
bag.add(els[i]);
|
bag.add(els[i]);
|
||||||
assertEquals(i + 1, bag.size());
|
assertEquals(i + 1, bag.size());
|
||||||
assertEquals(true, bag.contains(els[i]));
|
assertTrue(bag.contains(els[i]));
|
||||||
}
|
}
|
||||||
Set<T> set = ((PredicatedBag<T>) bag).uniqueSet();
|
Set<T> set = bag.uniqueSet();
|
||||||
assertTrue("Unique set contains the first element", set.contains(els[0]));
|
assertTrue("Unique set contains the first element", set.contains(els[0]));
|
||||||
assertEquals(true, bag.remove(els[0]));
|
assertTrue(bag.remove(els[0]));
|
||||||
set = ((PredicatedBag<T>) bag).uniqueSet();
|
set = bag.uniqueSet();
|
||||||
assertTrue("Unique set now does not contain the first element",
|
assertFalse("Unique set now does not contain the first element", set.contains(els[0]));
|
||||||
!set.contains(els[0]));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public void testIllegalAdd() {
|
public void testIllegalAdd() {
|
||||||
final Bag<T> bag = makeTestBag();
|
final Bag<T> bag = makeTestBag();
|
||||||
final Integer i = Integer.valueOf(3);
|
final Integer i = 3;
|
||||||
try {
|
try {
|
||||||
bag.add((T) i);
|
bag.add((T) i);
|
||||||
fail("Integer should fail string predicate.");
|
fail("Integer should fail string predicate.");
|
||||||
} catch (final IllegalArgumentException e) {
|
} catch (final IllegalArgumentException e) {
|
||||||
// expected
|
// expected
|
||||||
}
|
}
|
||||||
assertTrue("Collection shouldn't contain illegal element",
|
assertFalse("Collection shouldn't contain illegal element", bag.contains(i));
|
||||||
!bag.contains(i));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
@ -101,7 +99,7 @@ public class PredicatedBagTest<T> extends AbstractBagTest<T> {
|
|||||||
final HashBag<Object> elements = new HashBag<>();
|
final HashBag<Object> elements = new HashBag<>();
|
||||||
elements.add("one");
|
elements.add("one");
|
||||||
elements.add("two");
|
elements.add("two");
|
||||||
elements.add(Integer.valueOf(3));
|
elements.add(3);
|
||||||
elements.add("four");
|
elements.add("four");
|
||||||
try {
|
try {
|
||||||
decorateBag((HashBag<T>) elements, stringPredicate());
|
decorateBag((HashBag<T>) elements, stringPredicate());
|
||||||
|
@ -91,7 +91,7 @@ public class PredicatedSortedBagTest<T> extends AbstractSortedBagTest<T> {
|
|||||||
assertEquals("first element", bag.first(), one);
|
assertEquals("first element", bag.first(), one);
|
||||||
assertEquals("last element", bag.last(), two);
|
assertEquals("last element", bag.last(), two);
|
||||||
final Comparator<? super T> c = bag.comparator();
|
final Comparator<? super T> c = bag.comparator();
|
||||||
assertTrue("natural order, so comparator should be null", c == null);
|
assertNull("natural order, so comparator should be null", c);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -53,17 +53,17 @@ public class TransformedBagTest<T> extends AbstractBagTest<T> {
|
|||||||
//T had better be Object!
|
//T had better be Object!
|
||||||
final Bag<T> bag = TransformedBag.transformingBag(new HashBag<T>(),
|
final Bag<T> bag = TransformedBag.transformingBag(new HashBag<T>(),
|
||||||
(Transformer<T, T>) TransformedCollectionTest.STRING_TO_INTEGER_TRANSFORMER);
|
(Transformer<T, T>) TransformedCollectionTest.STRING_TO_INTEGER_TRANSFORMER);
|
||||||
assertEquals(0, bag.size());
|
assertTrue(bag.isEmpty());
|
||||||
final Object[] els = new Object[] {"1", "3", "5", "7", "2", "4", "6"};
|
final Object[] els = new Object[] {"1", "3", "5", "7", "2", "4", "6"};
|
||||||
for (int i = 0; i < els.length; i++) {
|
for (int i = 0; i < els.length; i++) {
|
||||||
bag.add((T) els[i]);
|
bag.add((T) els[i]);
|
||||||
assertEquals(i + 1, bag.size());
|
assertEquals(i + 1, bag.size());
|
||||||
assertEquals(true, bag.contains(Integer.valueOf((String) els[i])));
|
assertTrue(bag.contains(Integer.valueOf((String) els[i])));
|
||||||
assertEquals(false, bag.contains(els[i]));
|
assertFalse(bag.contains(els[i]));
|
||||||
}
|
}
|
||||||
|
|
||||||
assertEquals(false, bag.remove(els[0]));
|
assertFalse(bag.remove(els[0]));
|
||||||
assertEquals(true, bag.remove(Integer.valueOf((String) els[0])));
|
assertTrue(bag.remove(Integer.valueOf((String) els[0])));
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
@ -77,12 +77,12 @@ public class TransformedBagTest<T> extends AbstractBagTest<T> {
|
|||||||
(Transformer<T, T>) TransformedCollectionTest.STRING_TO_INTEGER_TRANSFORMER);
|
(Transformer<T, T>) TransformedCollectionTest.STRING_TO_INTEGER_TRANSFORMER);
|
||||||
assertEquals(els.length, bag.size());
|
assertEquals(els.length, bag.size());
|
||||||
for (final Object el : els) {
|
for (final Object el : els) {
|
||||||
assertEquals(true, bag.contains(Integer.valueOf((String) el)));
|
assertTrue(bag.contains(Integer.valueOf((String) el)));
|
||||||
assertEquals(false, bag.contains(el));
|
assertFalse(bag.contains(el));
|
||||||
}
|
}
|
||||||
|
|
||||||
assertEquals(false, bag.remove(els[0]));
|
assertFalse(bag.remove(els[0]));
|
||||||
assertEquals(true, bag.remove(Integer.valueOf((String) els[0])));
|
assertTrue(bag.remove(Integer.valueOf((String) els[0])));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -55,10 +55,10 @@ public class TransformedSortedBagTest<T> extends AbstractSortedBagTest<T> {
|
|||||||
for (int i = 0; i < els.length; i++) {
|
for (int i = 0; i < els.length; i++) {
|
||||||
bag.add((T) els[i]);
|
bag.add((T) els[i]);
|
||||||
assertEquals(i + 1, bag.size());
|
assertEquals(i + 1, bag.size());
|
||||||
assertEquals(true, bag.contains(Integer.valueOf((String) els[i])));
|
assertTrue(bag.contains(Integer.valueOf((String) els[i])));
|
||||||
}
|
}
|
||||||
|
|
||||||
assertEquals(true, bag.remove(Integer.valueOf((String) els[0])));
|
assertTrue(bag.remove(Integer.valueOf((String) els[0])));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -71,10 +71,10 @@ public class TransformedSortedBagTest<T> extends AbstractSortedBagTest<T> {
|
|||||||
final SortedBag<T> bag = TransformedSortedBag.transformedSortedBag(originalBag, (Transformer<T, T>) TransformedCollectionTest.STRING_TO_INTEGER_TRANSFORMER);
|
final SortedBag<T> bag = TransformedSortedBag.transformedSortedBag(originalBag, (Transformer<T, T>) TransformedCollectionTest.STRING_TO_INTEGER_TRANSFORMER);
|
||||||
assertEquals(els.length, bag.size());
|
assertEquals(els.length, bag.size());
|
||||||
for (final Object el : els) {
|
for (final Object el : els) {
|
||||||
assertEquals(true, bag.contains(Integer.valueOf((String) el)));
|
assertTrue(bag.contains(Integer.valueOf((String) el)));
|
||||||
}
|
}
|
||||||
|
|
||||||
assertEquals(true, bag.remove(Integer.valueOf((String) els[0])));
|
assertTrue(bag.remove(Integer.valueOf((String) els[0])));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -132,10 +132,10 @@ public abstract class AbstractBidiMapTest<K, V> extends AbstractIterableMapTest<
|
|||||||
final Set<V> keys2 = map2.keySet();
|
final Set<V> keys2 = map2.keySet();
|
||||||
final Collection<V> values1 = map1.values();
|
final Collection<V> values1 = map1.values();
|
||||||
final Collection<K> values2 = map2.values();
|
final Collection<K> values2 = map2.values();
|
||||||
assertEquals(true, keys1.containsAll(values2));
|
assertTrue(keys1.containsAll(values2));
|
||||||
assertEquals(true, values2.containsAll(keys1));
|
assertTrue(values2.containsAll(keys1));
|
||||||
assertEquals(true, values1.containsAll(keys2));
|
assertTrue(values1.containsAll(keys2));
|
||||||
assertEquals(true, keys2.containsAll(values1));
|
assertTrue(keys2.containsAll(values1));
|
||||||
}
|
}
|
||||||
|
|
||||||
// testGetKey
|
// testGetKey
|
||||||
@ -254,18 +254,18 @@ public abstract class AbstractBidiMapTest<K, V> extends AbstractIterableMapTest<
|
|||||||
removeValue(makeFullMap(), getSampleValues()[0]);
|
removeValue(makeFullMap(), getSampleValues()[0]);
|
||||||
removeValue(makeFullMap().inverseBidiMap(), getSampleKeys()[0]);
|
removeValue(makeFullMap().inverseBidiMap(), getSampleKeys()[0]);
|
||||||
|
|
||||||
assertEquals(null, makeFullMap().removeValue("NotPresent"));
|
assertNull(makeFullMap().removeValue("NotPresent"));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void remove(final BidiMap<?, ?> map, final Object key) {
|
private void remove(final BidiMap<?, ?> map, final Object key) {
|
||||||
final Object value = map.remove(key);
|
final Object value = map.remove(key);
|
||||||
assertTrue("Key was not removed.", !map.containsKey(key));
|
assertFalse("Key was not removed.", map.containsKey(key));
|
||||||
assertNull("Value was not removed.", map.getKey(value));
|
assertNull("Value was not removed.", map.getKey(value));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void removeValue(final BidiMap<?, ?> map, final Object value) {
|
private void removeValue(final BidiMap<?, ?> map, final Object value) {
|
||||||
final Object key = map.removeValue(value);
|
final Object key = map.removeValue(value);
|
||||||
assertTrue("Key was not removed.", !map.containsKey(key));
|
assertFalse("Key was not removed.", map.containsKey(key));
|
||||||
assertNull("Value was not removed.", map.getKey(value));
|
assertNull("Value was not removed.", map.getKey(value));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -274,13 +274,13 @@ public abstract class AbstractBidiMapTest<K, V> extends AbstractIterableMapTest<
|
|||||||
resetFull();
|
resetFull();
|
||||||
final Iterator<K> keys = map.keySet().iterator();
|
final Iterator<K> keys = map.keySet().iterator();
|
||||||
final Iterator<V> values = map.values().iterator();
|
final Iterator<V> values = map.values().iterator();
|
||||||
for (; keys.hasNext() && values.hasNext();) {
|
while (keys.hasNext() && values.hasNext()) {
|
||||||
final K key = keys.next();
|
final K key = keys.next();
|
||||||
final V value = values.next();
|
final V value = values.next();
|
||||||
assertSame(map.get(key), value);
|
assertSame(map.get(key), value);
|
||||||
}
|
}
|
||||||
assertEquals(false, keys.hasNext());
|
assertFalse(keys.hasNext());
|
||||||
assertEquals(false, values.hasNext());
|
assertFalse(values.hasNext());
|
||||||
}
|
}
|
||||||
|
|
||||||
//-----------------------------------------------------------------------
|
//-----------------------------------------------------------------------
|
||||||
@ -296,15 +296,11 @@ public abstract class AbstractBidiMapTest<K, V> extends AbstractIterableMapTest<
|
|||||||
private void removeByKeySet(final BidiMap<?, ?> map, final Object key, final Object value) {
|
private void removeByKeySet(final BidiMap<?, ?> map, final Object key, final Object value) {
|
||||||
map.keySet().remove(key);
|
map.keySet().remove(key);
|
||||||
|
|
||||||
assertTrue("Key was not removed.", !map.containsKey(key));
|
assertFalse("Key was not removed.", map.containsKey(key));
|
||||||
assertTrue("Value was not removed.", !map.containsValue(value));
|
assertFalse("Value was not removed.", map.containsValue(value));
|
||||||
|
|
||||||
assertTrue(
|
assertFalse("Key was not removed from inverse map.", map.inverseBidiMap().containsValue(key));
|
||||||
"Key was not removed from inverse map.",
|
assertFalse("Value was not removed from inverse map.", map.inverseBidiMap().containsKey(value));
|
||||||
!map.inverseBidiMap().containsValue(key));
|
|
||||||
assertTrue(
|
|
||||||
"Value was not removed from inverse map.",
|
|
||||||
!map.inverseBidiMap().containsKey(value));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//-----------------------------------------------------------------------
|
//-----------------------------------------------------------------------
|
||||||
@ -322,15 +318,11 @@ public abstract class AbstractBidiMapTest<K, V> extends AbstractIterableMapTest<
|
|||||||
temp.put(key, value);
|
temp.put(key, value);
|
||||||
map.entrySet().remove(temp.entrySet().iterator().next());
|
map.entrySet().remove(temp.entrySet().iterator().next());
|
||||||
|
|
||||||
assertTrue("Key was not removed.", !map.containsKey(key));
|
assertFalse("Key was not removed.", map.containsKey(key));
|
||||||
assertTrue("Value was not removed.", !map.containsValue(value));
|
assertFalse("Value was not removed.", map.containsValue(value));
|
||||||
|
|
||||||
assertTrue(
|
assertFalse("Key was not removed from inverse map.", map.inverseBidiMap().containsValue(key));
|
||||||
"Key was not removed from inverse map.",
|
assertFalse("Value was not removed from inverse map.", map.inverseBidiMap().containsKey(value));
|
||||||
!map.inverseBidiMap().containsValue(key));
|
|
||||||
assertTrue(
|
|
||||||
"Value was not removed from inverse map.",
|
|
||||||
!map.inverseBidiMap().containsKey(value));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -394,11 +386,11 @@ public abstract class AbstractBidiMapTest<K, V> extends AbstractIterableMapTest<
|
|||||||
entryConfirmed2.setValue(newValue1);
|
entryConfirmed2.setValue(newValue1);
|
||||||
AbstractBidiMapTest.this.getConfirmed().remove(key1);
|
AbstractBidiMapTest.this.getConfirmed().remove(key1);
|
||||||
assertEquals(newValue1, entry2.getValue());
|
assertEquals(newValue1, entry2.getValue());
|
||||||
assertEquals(true, AbstractBidiMapTest.this.getMap().containsKey(entry2.getKey()));
|
assertTrue(AbstractBidiMapTest.this.getMap().containsKey(entry2.getKey()));
|
||||||
assertEquals(true, AbstractBidiMapTest.this.getMap().containsValue(newValue1));
|
assertTrue(AbstractBidiMapTest.this.getMap().containsValue(newValue1));
|
||||||
assertEquals(newValue1, AbstractBidiMapTest.this.getMap().get(entry2.getKey()));
|
assertEquals(newValue1, AbstractBidiMapTest.this.getMap().get(entry2.getKey()));
|
||||||
assertEquals(false, AbstractBidiMapTest.this.getMap().containsKey(key1));
|
assertFalse(AbstractBidiMapTest.this.getMap().containsKey(key1));
|
||||||
assertEquals(false, AbstractBidiMapTest.this.getMap().containsValue(newValue2));
|
assertFalse(AbstractBidiMapTest.this.getMap().containsValue(newValue2));
|
||||||
TestBidiMapEntrySet.this.verify();
|
TestBidiMapEntrySet.this.verify();
|
||||||
|
|
||||||
// check for ConcurrentModification
|
// check for ConcurrentModification
|
||||||
@ -541,7 +533,7 @@ public abstract class AbstractBidiMapTest<K, V> extends AbstractIterableMapTest<
|
|||||||
resetFull();
|
resetFull();
|
||||||
final BidiMap<K, V> bidi = getMap();
|
final BidiMap<K, V> bidi = getMap();
|
||||||
final MapIterator<K, V> it = bidi.mapIterator();
|
final MapIterator<K, V> it = bidi.mapIterator();
|
||||||
assertEquals(true, it.hasNext());
|
assertTrue(it.hasNext());
|
||||||
final K key1 = it.next();
|
final K key1 = it.next();
|
||||||
|
|
||||||
if (!isSetValueSupported()) {
|
if (!isSetValueSupported()) {
|
||||||
@ -557,8 +549,8 @@ public abstract class AbstractBidiMapTest<K, V> extends AbstractIterableMapTest<
|
|||||||
confirmed.put(key1, newValue1);
|
confirmed.put(key1, newValue1);
|
||||||
assertSame(key1, it.getKey());
|
assertSame(key1, it.getKey());
|
||||||
assertSame(newValue1, it.getValue());
|
assertSame(newValue1, it.getValue());
|
||||||
assertEquals(true, bidi.containsKey(key1));
|
assertTrue(bidi.containsKey(key1));
|
||||||
assertEquals(true, bidi.containsValue(newValue1));
|
assertTrue(bidi.containsValue(newValue1));
|
||||||
assertEquals(newValue1, bidi.get(key1));
|
assertEquals(newValue1, bidi.get(key1));
|
||||||
verify();
|
verify();
|
||||||
|
|
||||||
@ -566,8 +558,8 @@ public abstract class AbstractBidiMapTest<K, V> extends AbstractIterableMapTest<
|
|||||||
confirmed.put(key1, newValue1);
|
confirmed.put(key1, newValue1);
|
||||||
assertSame(key1, it.getKey());
|
assertSame(key1, it.getKey());
|
||||||
assertSame(newValue1, it.getValue());
|
assertSame(newValue1, it.getValue());
|
||||||
assertEquals(true, bidi.containsKey(key1));
|
assertTrue(bidi.containsKey(key1));
|
||||||
assertEquals(true, bidi.containsValue(newValue1));
|
assertTrue(bidi.containsValue(newValue1));
|
||||||
assertEquals(newValue1, bidi.get(key1));
|
assertEquals(newValue1, bidi.get(key1));
|
||||||
verify();
|
verify();
|
||||||
|
|
||||||
@ -576,8 +568,8 @@ public abstract class AbstractBidiMapTest<K, V> extends AbstractIterableMapTest<
|
|||||||
confirmed.put(key2, newValue2);
|
confirmed.put(key2, newValue2);
|
||||||
assertSame(key2, it.getKey());
|
assertSame(key2, it.getKey());
|
||||||
assertSame(newValue2, it.getValue());
|
assertSame(newValue2, it.getValue());
|
||||||
assertEquals(true, bidi.containsKey(key2));
|
assertTrue(bidi.containsKey(key2));
|
||||||
assertEquals(true, bidi.containsValue(newValue2));
|
assertTrue(bidi.containsValue(newValue2));
|
||||||
assertEquals(newValue2, bidi.get(key2));
|
assertEquals(newValue2, bidi.get(key2));
|
||||||
verify();
|
verify();
|
||||||
|
|
||||||
@ -592,11 +584,11 @@ public abstract class AbstractBidiMapTest<K, V> extends AbstractIterableMapTest<
|
|||||||
confirmed.put(key2, newValue1);
|
confirmed.put(key2, newValue1);
|
||||||
AbstractBidiMapTest.this.getConfirmed().remove(key1);
|
AbstractBidiMapTest.this.getConfirmed().remove(key1);
|
||||||
assertEquals(newValue1, it.getValue());
|
assertEquals(newValue1, it.getValue());
|
||||||
assertEquals(true, bidi.containsKey(it.getKey()));
|
assertTrue(bidi.containsKey(it.getKey()));
|
||||||
assertEquals(true, bidi.containsValue(newValue1));
|
assertTrue(bidi.containsValue(newValue1));
|
||||||
assertEquals(newValue1, bidi.get(it.getKey()));
|
assertEquals(newValue1, bidi.get(it.getKey()));
|
||||||
assertEquals(false, bidi.containsKey(key1));
|
assertFalse(bidi.containsKey(key1));
|
||||||
assertEquals(false, bidi.containsValue(newValue2));
|
assertFalse(bidi.containsValue(newValue2));
|
||||||
verify();
|
verify();
|
||||||
|
|
||||||
// check for ConcurrentModification
|
// check for ConcurrentModification
|
||||||
|
@ -53,7 +53,7 @@ public abstract class AbstractSortedBidiMapTest<K extends Comparable<K>, V exten
|
|||||||
sortedValues.addAll(map.values());
|
sortedValues.addAll(map.values());
|
||||||
sortedValues = Collections.unmodifiableList(sortedValues);
|
sortedValues = Collections.unmodifiableList(sortedValues);
|
||||||
|
|
||||||
sortedNewValues.addAll(this.<V>getAsList(getNewSampleValues()));
|
sortedNewValues.addAll(getAsList(getNewSampleValues()));
|
||||||
}
|
}
|
||||||
|
|
||||||
// public AbstractTestSortedBidiMap() {
|
// public AbstractTestSortedBidiMap() {
|
||||||
@ -116,14 +116,14 @@ public abstract class AbstractSortedBidiMapTest<K extends Comparable<K>, V exten
|
|||||||
|
|
||||||
final SortedMap<K, V> head = sm.headMap(toKey);
|
final SortedMap<K, V> head = sm.headMap(toKey);
|
||||||
assertEquals(1, head.size());
|
assertEquals(1, head.size());
|
||||||
assertEquals(true, sm.containsKey(first));
|
assertTrue(sm.containsKey(first));
|
||||||
assertEquals(true, head.containsKey(first));
|
assertTrue(head.containsKey(first));
|
||||||
assertEquals(true, sm.containsValue(firstValue));
|
assertTrue(sm.containsValue(firstValue));
|
||||||
assertEquals(true, head.containsValue(firstValue));
|
assertTrue(head.containsValue(firstValue));
|
||||||
assertEquals(true, sm.containsKey(second));
|
assertTrue(sm.containsKey(second));
|
||||||
assertEquals(false, head.containsKey(second));
|
assertFalse(head.containsKey(second));
|
||||||
assertEquals(true, sm.containsValue(secondValue));
|
assertTrue(sm.containsValue(secondValue));
|
||||||
assertEquals(false, head.containsValue(secondValue));
|
assertFalse(head.containsValue(secondValue));
|
||||||
}
|
}
|
||||||
|
|
||||||
//-----------------------------------------------------------------------
|
//-----------------------------------------------------------------------
|
||||||
@ -151,26 +151,26 @@ public abstract class AbstractSortedBidiMapTest<K extends Comparable<K>, V exten
|
|||||||
assertEquals(size - 2, sm.size());
|
assertEquals(size - 2, sm.size());
|
||||||
assertEquals(size - 2, sm.inverseBidiMap().size());
|
assertEquals(size - 2, sm.inverseBidiMap().size());
|
||||||
|
|
||||||
assertEquals(false, sm.containsKey(first));
|
assertFalse(sm.containsKey(first));
|
||||||
assertEquals(false, sm.containsValue(firstValue));
|
assertFalse(sm.containsValue(firstValue));
|
||||||
assertEquals(false, sm.inverseBidiMap().containsKey(firstValue));
|
assertFalse(sm.inverseBidiMap().containsKey(firstValue));
|
||||||
assertEquals(false, sm.inverseBidiMap().containsValue(first));
|
assertFalse(sm.inverseBidiMap().containsValue(first));
|
||||||
assertEquals(false, sub.containsKey(first));
|
assertFalse(sub.containsKey(first));
|
||||||
assertEquals(false, sub.containsValue(firstValue));
|
assertFalse(sub.containsValue(firstValue));
|
||||||
|
|
||||||
assertEquals(false, sm.containsKey(second));
|
assertFalse(sm.containsKey(second));
|
||||||
assertEquals(false, sm.containsValue(secondValue));
|
assertFalse(sm.containsValue(secondValue));
|
||||||
assertEquals(false, sm.inverseBidiMap().containsKey(secondValue));
|
assertFalse(sm.inverseBidiMap().containsKey(secondValue));
|
||||||
assertEquals(false, sm.inverseBidiMap().containsValue(second));
|
assertFalse(sm.inverseBidiMap().containsValue(second));
|
||||||
assertEquals(false, sub.containsKey(second));
|
assertFalse(sub.containsKey(second));
|
||||||
assertEquals(false, sub.containsValue(secondValue));
|
assertFalse(sub.containsValue(secondValue));
|
||||||
|
|
||||||
assertEquals(true, sm.containsKey(toKey));
|
assertTrue(sm.containsKey(toKey));
|
||||||
assertEquals(true, sm.containsValue(toKeyValue));
|
assertTrue(sm.containsValue(toKeyValue));
|
||||||
assertEquals(true, sm.inverseBidiMap().containsKey(toKeyValue));
|
assertTrue(sm.inverseBidiMap().containsKey(toKeyValue));
|
||||||
assertEquals(true, sm.inverseBidiMap().containsValue(toKey));
|
assertTrue(sm.inverseBidiMap().containsValue(toKey));
|
||||||
assertEquals(false, sub.containsKey(toKey));
|
assertFalse(sub.containsKey(toKey));
|
||||||
assertEquals(false, sub.containsValue(toKeyValue));
|
assertFalse(sub.containsValue(toKeyValue));
|
||||||
}
|
}
|
||||||
|
|
||||||
//-----------------------------------------------------------------------
|
//-----------------------------------------------------------------------
|
||||||
@ -189,32 +189,32 @@ public abstract class AbstractSortedBidiMapTest<K extends Comparable<K>, V exten
|
|||||||
final int size = sm.size();
|
final int size = sm.size();
|
||||||
final SortedMap<K, V> sub = sm.headMap(toKey);
|
final SortedMap<K, V> sub = sm.headMap(toKey);
|
||||||
assertEquals(2, sub.size());
|
assertEquals(2, sub.size());
|
||||||
assertEquals(true, sm.containsKey(first));
|
assertTrue(sm.containsKey(first));
|
||||||
assertEquals(true, sub.containsKey(first));
|
assertTrue(sub.containsKey(first));
|
||||||
assertEquals(true, sm.containsKey(second));
|
assertTrue(sm.containsKey(second));
|
||||||
assertEquals(true, sub.containsKey(second));
|
assertTrue(sub.containsKey(second));
|
||||||
|
|
||||||
final V firstValue = sub.remove(first);
|
final V firstValue = sub.remove(first);
|
||||||
assertEquals(1, sub.size());
|
assertEquals(1, sub.size());
|
||||||
assertEquals(size - 1, sm.size());
|
assertEquals(size - 1, sm.size());
|
||||||
assertEquals(size - 1, sm.inverseBidiMap().size());
|
assertEquals(size - 1, sm.inverseBidiMap().size());
|
||||||
assertEquals(false, sm.containsKey(first));
|
assertFalse(sm.containsKey(first));
|
||||||
assertEquals(false, sm.containsValue(firstValue));
|
assertFalse(sm.containsValue(firstValue));
|
||||||
assertEquals(false, sm.inverseBidiMap().containsKey(firstValue));
|
assertFalse(sm.inverseBidiMap().containsKey(firstValue));
|
||||||
assertEquals(false, sm.inverseBidiMap().containsValue(first));
|
assertFalse(sm.inverseBidiMap().containsValue(first));
|
||||||
assertEquals(false, sub.containsKey(first));
|
assertFalse(sub.containsKey(first));
|
||||||
assertEquals(false, sub.containsValue(firstValue));
|
assertFalse(sub.containsValue(firstValue));
|
||||||
|
|
||||||
final V secondValue = sub.remove(second);
|
final V secondValue = sub.remove(second);
|
||||||
assertEquals(0, sub.size());
|
assertEquals(0, sub.size());
|
||||||
assertEquals(size - 2, sm.size());
|
assertEquals(size - 2, sm.size());
|
||||||
assertEquals(size - 2, sm.inverseBidiMap().size());
|
assertEquals(size - 2, sm.inverseBidiMap().size());
|
||||||
assertEquals(false, sm.containsKey(second));
|
assertFalse(sm.containsKey(second));
|
||||||
assertEquals(false, sm.containsValue(secondValue));
|
assertFalse(sm.containsValue(secondValue));
|
||||||
assertEquals(false, sm.inverseBidiMap().containsKey(secondValue));
|
assertFalse(sm.inverseBidiMap().containsKey(secondValue));
|
||||||
assertEquals(false, sm.inverseBidiMap().containsValue(second));
|
assertFalse(sm.inverseBidiMap().containsValue(second));
|
||||||
assertEquals(false, sub.containsKey(second));
|
assertFalse(sub.containsKey(second));
|
||||||
assertEquals(false, sub.containsValue(secondValue));
|
assertFalse(sub.containsValue(secondValue));
|
||||||
}
|
}
|
||||||
|
|
||||||
//-----------------------------------------------------------------------
|
//-----------------------------------------------------------------------
|
||||||
@ -239,36 +239,36 @@ public abstract class AbstractSortedBidiMapTest<K extends Comparable<K>, V exten
|
|||||||
final Iterator<Map.Entry<K, V>> it2 = set.iterator();
|
final Iterator<Map.Entry<K, V>> it2 = set.iterator();
|
||||||
final Map.Entry<K, V> firstEntry = cloneMapEntry(it2.next());
|
final Map.Entry<K, V> firstEntry = cloneMapEntry(it2.next());
|
||||||
final Map.Entry<K, V> secondEntry = cloneMapEntry(it2.next());
|
final Map.Entry<K, V> secondEntry = cloneMapEntry(it2.next());
|
||||||
assertEquals(true, sm.containsKey(first));
|
assertTrue(sm.containsKey(first));
|
||||||
assertEquals(true, sub.containsKey(first));
|
assertTrue(sub.containsKey(first));
|
||||||
assertEquals(true, set.contains(firstEntry));
|
assertTrue(set.contains(firstEntry));
|
||||||
assertEquals(true, sm.containsKey(second));
|
assertTrue(sm.containsKey(second));
|
||||||
assertEquals(true, sub.containsKey(second));
|
assertTrue(sub.containsKey(second));
|
||||||
assertEquals(true, set.contains(secondEntry));
|
assertTrue(set.contains(secondEntry));
|
||||||
|
|
||||||
set.remove(firstEntry);
|
set.remove(firstEntry);
|
||||||
assertEquals(1, sub.size());
|
assertEquals(1, sub.size());
|
||||||
assertEquals(size - 1, sm.size());
|
assertEquals(size - 1, sm.size());
|
||||||
assertEquals(size - 1, sm.inverseBidiMap().size());
|
assertEquals(size - 1, sm.inverseBidiMap().size());
|
||||||
assertEquals(false, sm.containsKey(firstEntry.getKey()));
|
assertFalse(sm.containsKey(firstEntry.getKey()));
|
||||||
assertEquals(false, sm.containsValue(firstEntry.getValue()));
|
assertFalse(sm.containsValue(firstEntry.getValue()));
|
||||||
assertEquals(false, sm.inverseBidiMap().containsKey(firstEntry.getValue()));
|
assertFalse(sm.inverseBidiMap().containsKey(firstEntry.getValue()));
|
||||||
assertEquals(false, sm.inverseBidiMap().containsValue(firstEntry.getKey()));
|
assertFalse(sm.inverseBidiMap().containsValue(firstEntry.getKey()));
|
||||||
assertEquals(false, sub.containsKey(firstEntry.getKey()));
|
assertFalse(sub.containsKey(firstEntry.getKey()));
|
||||||
assertEquals(false, sub.containsValue(firstEntry.getValue()));
|
assertFalse(sub.containsValue(firstEntry.getValue()));
|
||||||
assertEquals(false, set.contains(firstEntry));
|
assertFalse(set.contains(firstEntry));
|
||||||
|
|
||||||
set.remove(secondEntry);
|
set.remove(secondEntry);
|
||||||
assertEquals(0, sub.size());
|
assertEquals(0, sub.size());
|
||||||
assertEquals(size - 2, sm.size());
|
assertEquals(size - 2, sm.size());
|
||||||
assertEquals(size - 2, sm.inverseBidiMap().size());
|
assertEquals(size - 2, sm.inverseBidiMap().size());
|
||||||
assertEquals(false, sm.containsKey(secondEntry.getKey()));
|
assertFalse(sm.containsKey(secondEntry.getKey()));
|
||||||
assertEquals(false, sm.containsValue(secondEntry.getValue()));
|
assertFalse(sm.containsValue(secondEntry.getValue()));
|
||||||
assertEquals(false, sm.inverseBidiMap().containsKey(secondEntry.getValue()));
|
assertFalse(sm.inverseBidiMap().containsKey(secondEntry.getValue()));
|
||||||
assertEquals(false, sm.inverseBidiMap().containsValue(secondEntry.getKey()));
|
assertFalse(sm.inverseBidiMap().containsValue(secondEntry.getKey()));
|
||||||
assertEquals(false, sub.containsKey(secondEntry.getKey()));
|
assertFalse(sub.containsKey(secondEntry.getKey()));
|
||||||
assertEquals(false, sub.containsValue(secondEntry.getValue()));
|
assertFalse(sub.containsValue(secondEntry.getValue()));
|
||||||
assertEquals(false, set.contains(secondEntry));
|
assertFalse(set.contains(secondEntry));
|
||||||
}
|
}
|
||||||
|
|
||||||
//-----------------------------------------------------------------------
|
//-----------------------------------------------------------------------
|
||||||
@ -286,18 +286,18 @@ public abstract class AbstractSortedBidiMapTest<K extends Comparable<K>, V exten
|
|||||||
|
|
||||||
final SortedMap<K, V> sub = sm.tailMap(fromKey);
|
final SortedMap<K, V> sub = sm.tailMap(fromKey);
|
||||||
assertEquals(sm.size() - 1, sub.size());
|
assertEquals(sm.size() - 1, sub.size());
|
||||||
assertEquals(true, sm.containsKey(first));
|
assertTrue(sm.containsKey(first));
|
||||||
assertEquals(false, sub.containsKey(first));
|
assertFalse(sub.containsKey(first));
|
||||||
assertEquals(true, sm.containsValue(firstValue));
|
assertTrue(sm.containsValue(firstValue));
|
||||||
assertEquals(false, sub.containsValue(firstValue));
|
assertFalse(sub.containsValue(firstValue));
|
||||||
assertEquals(true, sm.containsKey(fromKey));
|
assertTrue(sm.containsKey(fromKey));
|
||||||
assertEquals(true, sub.containsKey(fromKey));
|
assertTrue(sub.containsKey(fromKey));
|
||||||
assertEquals(true, sm.containsValue(fromKeyValue));
|
assertTrue(sm.containsValue(fromKeyValue));
|
||||||
assertEquals(true, sub.containsValue(fromKeyValue));
|
assertTrue(sub.containsValue(fromKeyValue));
|
||||||
assertEquals(true, sm.containsKey(second));
|
assertTrue(sm.containsKey(second));
|
||||||
assertEquals(true, sub.containsKey(second));
|
assertTrue(sub.containsKey(second));
|
||||||
assertEquals(true, sm.containsValue(secondValue));
|
assertTrue(sm.containsValue(secondValue));
|
||||||
assertEquals(true, sub.containsValue(secondValue));
|
assertTrue(sub.containsValue(secondValue));
|
||||||
}
|
}
|
||||||
|
|
||||||
//-----------------------------------------------------------------------
|
//-----------------------------------------------------------------------
|
||||||
@ -327,26 +327,26 @@ public abstract class AbstractSortedBidiMapTest<K extends Comparable<K>, V exten
|
|||||||
assertEquals(3, sm.size());
|
assertEquals(3, sm.size());
|
||||||
assertEquals(3, sm.inverseBidiMap().size());
|
assertEquals(3, sm.inverseBidiMap().size());
|
||||||
|
|
||||||
assertEquals(true, sm.containsKey(first));
|
assertTrue(sm.containsKey(first));
|
||||||
assertEquals(true, sm.containsValue(firstValue));
|
assertTrue(sm.containsValue(firstValue));
|
||||||
assertEquals(true, sm.inverseBidiMap().containsKey(firstValue));
|
assertTrue(sm.inverseBidiMap().containsKey(firstValue));
|
||||||
assertEquals(true, sm.inverseBidiMap().containsValue(first));
|
assertTrue(sm.inverseBidiMap().containsValue(first));
|
||||||
assertEquals(false, sub.containsKey(first));
|
assertFalse(sub.containsKey(first));
|
||||||
assertEquals(false, sub.containsValue(firstValue));
|
assertFalse(sub.containsValue(firstValue));
|
||||||
|
|
||||||
assertEquals(false, sm.containsKey(fromKey));
|
assertFalse(sm.containsKey(fromKey));
|
||||||
assertEquals(false, sm.containsValue(fromKeyValue));
|
assertFalse(sm.containsValue(fromKeyValue));
|
||||||
assertEquals(false, sm.inverseBidiMap().containsKey(fromKeyValue));
|
assertFalse(sm.inverseBidiMap().containsKey(fromKeyValue));
|
||||||
assertEquals(false, sm.inverseBidiMap().containsValue(fromKey));
|
assertFalse(sm.inverseBidiMap().containsValue(fromKey));
|
||||||
assertEquals(false, sub.containsKey(fromKey));
|
assertFalse(sub.containsKey(fromKey));
|
||||||
assertEquals(false, sub.containsValue(fromKeyValue));
|
assertFalse(sub.containsValue(fromKeyValue));
|
||||||
|
|
||||||
assertEquals(false, sm.containsKey(second));
|
assertFalse(sm.containsKey(second));
|
||||||
assertEquals(false, sm.containsValue(secondValue));
|
assertFalse(sm.containsValue(secondValue));
|
||||||
assertEquals(false, sm.inverseBidiMap().containsKey(secondValue));
|
assertFalse(sm.inverseBidiMap().containsKey(secondValue));
|
||||||
assertEquals(false, sm.inverseBidiMap().containsValue(second));
|
assertFalse(sm.inverseBidiMap().containsValue(second));
|
||||||
assertEquals(false, sub.containsKey(second));
|
assertFalse(sub.containsKey(second));
|
||||||
assertEquals(false, sub.containsValue(secondValue));
|
assertFalse(sub.containsValue(secondValue));
|
||||||
}
|
}
|
||||||
|
|
||||||
//-----------------------------------------------------------------------
|
//-----------------------------------------------------------------------
|
||||||
@ -366,32 +366,32 @@ public abstract class AbstractSortedBidiMapTest<K extends Comparable<K>, V exten
|
|||||||
|
|
||||||
final int size = sm.size();
|
final int size = sm.size();
|
||||||
final SortedMap<K, V> sub = sm.tailMap(fromKey);
|
final SortedMap<K, V> sub = sm.tailMap(fromKey);
|
||||||
assertEquals(true, sm.containsKey(first));
|
assertTrue(sm.containsKey(first));
|
||||||
assertEquals(true, sub.containsKey(first));
|
assertTrue(sub.containsKey(first));
|
||||||
assertEquals(true, sm.containsKey(second));
|
assertTrue(sm.containsKey(second));
|
||||||
assertEquals(true, sub.containsKey(second));
|
assertTrue(sub.containsKey(second));
|
||||||
|
|
||||||
final Object firstValue = sub.remove(first);
|
final Object firstValue = sub.remove(first);
|
||||||
assertEquals(size - 3, sub.size());
|
assertEquals(size - 3, sub.size());
|
||||||
assertEquals(size - 1, sm.size());
|
assertEquals(size - 1, sm.size());
|
||||||
assertEquals(size - 1, sm.inverseBidiMap().size());
|
assertEquals(size - 1, sm.inverseBidiMap().size());
|
||||||
assertEquals(false, sm.containsKey(first));
|
assertFalse(sm.containsKey(first));
|
||||||
assertEquals(false, sm.containsValue(firstValue));
|
assertFalse(sm.containsValue(firstValue));
|
||||||
assertEquals(false, sm.inverseBidiMap().containsKey(firstValue));
|
assertFalse(sm.inverseBidiMap().containsKey(firstValue));
|
||||||
assertEquals(false, sm.inverseBidiMap().containsValue(first));
|
assertFalse(sm.inverseBidiMap().containsValue(first));
|
||||||
assertEquals(false, sub.containsKey(first));
|
assertFalse(sub.containsKey(first));
|
||||||
assertEquals(false, sub.containsValue(firstValue));
|
assertFalse(sub.containsValue(firstValue));
|
||||||
|
|
||||||
final Object secondValue = sub.remove(second);
|
final Object secondValue = sub.remove(second);
|
||||||
assertEquals(size - 4, sub.size());
|
assertEquals(size - 4, sub.size());
|
||||||
assertEquals(size - 2, sm.size());
|
assertEquals(size - 2, sm.size());
|
||||||
assertEquals(size - 2, sm.inverseBidiMap().size());
|
assertEquals(size - 2, sm.inverseBidiMap().size());
|
||||||
assertEquals(false, sm.containsKey(second));
|
assertFalse(sm.containsKey(second));
|
||||||
assertEquals(false, sm.containsValue(secondValue));
|
assertFalse(sm.containsValue(secondValue));
|
||||||
assertEquals(false, sm.inverseBidiMap().containsKey(secondValue));
|
assertFalse(sm.inverseBidiMap().containsKey(secondValue));
|
||||||
assertEquals(false, sm.inverseBidiMap().containsValue(second));
|
assertFalse(sm.inverseBidiMap().containsValue(second));
|
||||||
assertEquals(false, sub.containsKey(second));
|
assertFalse(sub.containsKey(second));
|
||||||
assertEquals(false, sub.containsValue(secondValue));
|
assertFalse(sub.containsValue(secondValue));
|
||||||
}
|
}
|
||||||
|
|
||||||
//-----------------------------------------------------------------------
|
//-----------------------------------------------------------------------
|
||||||
@ -416,36 +416,36 @@ public abstract class AbstractSortedBidiMapTest<K extends Comparable<K>, V exten
|
|||||||
it2.next();
|
it2.next();
|
||||||
final Map.Entry<K, V> firstEntry = cloneMapEntry(it2.next());
|
final Map.Entry<K, V> firstEntry = cloneMapEntry(it2.next());
|
||||||
final Map.Entry<K, V> secondEntry = cloneMapEntry(it2.next());
|
final Map.Entry<K, V> secondEntry = cloneMapEntry(it2.next());
|
||||||
assertEquals(true, sm.containsKey(first));
|
assertTrue(sm.containsKey(first));
|
||||||
assertEquals(true, sub.containsKey(first));
|
assertTrue(sub.containsKey(first));
|
||||||
assertEquals(true, set.contains(firstEntry));
|
assertTrue(set.contains(firstEntry));
|
||||||
assertEquals(true, sm.containsKey(second));
|
assertTrue(sm.containsKey(second));
|
||||||
assertEquals(true, sub.containsKey(second));
|
assertTrue(sub.containsKey(second));
|
||||||
assertEquals(true, set.contains(secondEntry));
|
assertTrue(set.contains(secondEntry));
|
||||||
|
|
||||||
set.remove(firstEntry);
|
set.remove(firstEntry);
|
||||||
assertEquals(size - 3, sub.size());
|
assertEquals(size - 3, sub.size());
|
||||||
assertEquals(size - 1, sm.size());
|
assertEquals(size - 1, sm.size());
|
||||||
assertEquals(size - 1, sm.inverseBidiMap().size());
|
assertEquals(size - 1, sm.inverseBidiMap().size());
|
||||||
assertEquals(false, sm.containsKey(firstEntry.getKey()));
|
assertFalse(sm.containsKey(firstEntry.getKey()));
|
||||||
assertEquals(false, sm.containsValue(firstEntry.getValue()));
|
assertFalse(sm.containsValue(firstEntry.getValue()));
|
||||||
assertEquals(false, sm.inverseBidiMap().containsKey(firstEntry.getValue()));
|
assertFalse(sm.inverseBidiMap().containsKey(firstEntry.getValue()));
|
||||||
assertEquals(false, sm.inverseBidiMap().containsValue(firstEntry.getKey()));
|
assertFalse(sm.inverseBidiMap().containsValue(firstEntry.getKey()));
|
||||||
assertEquals(false, sub.containsKey(firstEntry.getKey()));
|
assertFalse(sub.containsKey(firstEntry.getKey()));
|
||||||
assertEquals(false, sub.containsValue(firstEntry.getValue()));
|
assertFalse(sub.containsValue(firstEntry.getValue()));
|
||||||
assertEquals(false, set.contains(firstEntry));
|
assertFalse(set.contains(firstEntry));
|
||||||
|
|
||||||
set.remove(secondEntry);
|
set.remove(secondEntry);
|
||||||
assertEquals(size - 4, sub.size());
|
assertEquals(size - 4, sub.size());
|
||||||
assertEquals(size - 2, sm.size());
|
assertEquals(size - 2, sm.size());
|
||||||
assertEquals(size - 2, sm.inverseBidiMap().size());
|
assertEquals(size - 2, sm.inverseBidiMap().size());
|
||||||
assertEquals(false, sm.containsKey(secondEntry.getKey()));
|
assertFalse(sm.containsKey(secondEntry.getKey()));
|
||||||
assertEquals(false, sm.containsValue(secondEntry.getValue()));
|
assertFalse(sm.containsValue(secondEntry.getValue()));
|
||||||
assertEquals(false, sm.inverseBidiMap().containsKey(secondEntry.getValue()));
|
assertFalse(sm.inverseBidiMap().containsKey(secondEntry.getValue()));
|
||||||
assertEquals(false, sm.inverseBidiMap().containsValue(secondEntry.getKey()));
|
assertFalse(sm.inverseBidiMap().containsValue(secondEntry.getKey()));
|
||||||
assertEquals(false, sub.containsKey(secondEntry.getKey()));
|
assertFalse(sub.containsKey(secondEntry.getKey()));
|
||||||
assertEquals(false, sub.containsValue(secondEntry.getValue()));
|
assertFalse(sub.containsValue(secondEntry.getValue()));
|
||||||
assertEquals(false, set.contains(secondEntry));
|
assertFalse(set.contains(secondEntry));
|
||||||
}
|
}
|
||||||
|
|
||||||
//-----------------------------------------------------------------------
|
//-----------------------------------------------------------------------
|
||||||
@ -466,22 +466,22 @@ public abstract class AbstractSortedBidiMapTest<K extends Comparable<K>, V exten
|
|||||||
|
|
||||||
final SortedMap<K, V> sub = sm.subMap(fromKey, toKey);
|
final SortedMap<K, V> sub = sm.subMap(fromKey, toKey);
|
||||||
assertEquals(2, sub.size());
|
assertEquals(2, sub.size());
|
||||||
assertEquals(true, sm.containsKey(first));
|
assertTrue(sm.containsKey(first));
|
||||||
assertEquals(false, sub.containsKey(first));
|
assertFalse(sub.containsKey(first));
|
||||||
assertEquals(true, sm.containsValue(firstValue));
|
assertTrue(sm.containsValue(firstValue));
|
||||||
assertEquals(false, sub.containsValue(firstValue));
|
assertFalse(sub.containsValue(firstValue));
|
||||||
assertEquals(true, sm.containsKey(fromKey));
|
assertTrue(sm.containsKey(fromKey));
|
||||||
assertEquals(true, sub.containsKey(fromKey));
|
assertTrue(sub.containsKey(fromKey));
|
||||||
assertEquals(true, sm.containsValue(fromKeyValue));
|
assertTrue(sm.containsValue(fromKeyValue));
|
||||||
assertEquals(true, sub.containsValue(fromKeyValue));
|
assertTrue(sub.containsValue(fromKeyValue));
|
||||||
assertEquals(true, sm.containsKey(second));
|
assertTrue(sm.containsKey(second));
|
||||||
assertEquals(true, sub.containsKey(second));
|
assertTrue(sub.containsKey(second));
|
||||||
assertEquals(true, sm.containsValue(secondValue));
|
assertTrue(sm.containsValue(secondValue));
|
||||||
assertEquals(true, sub.containsValue(secondValue));
|
assertTrue(sub.containsValue(secondValue));
|
||||||
assertEquals(true, sm.containsKey(third));
|
assertTrue(sm.containsKey(third));
|
||||||
assertEquals(false, sub.containsKey(third));
|
assertFalse(sub.containsKey(third));
|
||||||
assertEquals(true, sm.containsValue(thirdValue));
|
assertTrue(sm.containsValue(thirdValue));
|
||||||
assertEquals(false, sub.containsValue(thirdValue));
|
assertFalse(sub.containsValue(thirdValue));
|
||||||
}
|
}
|
||||||
|
|
||||||
//-----------------------------------------------------------------------
|
//-----------------------------------------------------------------------
|
||||||
@ -512,33 +512,33 @@ public abstract class AbstractSortedBidiMapTest<K extends Comparable<K>, V exten
|
|||||||
assertEquals(size - 3, sm.size());
|
assertEquals(size - 3, sm.size());
|
||||||
assertEquals(size - 3, sm.inverseBidiMap().size());
|
assertEquals(size - 3, sm.inverseBidiMap().size());
|
||||||
|
|
||||||
assertEquals(false, sm.containsKey(fromKey));
|
assertFalse(sm.containsKey(fromKey));
|
||||||
assertEquals(false, sm.containsValue(fromKeyValue));
|
assertFalse(sm.containsValue(fromKeyValue));
|
||||||
assertEquals(false, sm.inverseBidiMap().containsKey(fromKeyValue));
|
assertFalse(sm.inverseBidiMap().containsKey(fromKeyValue));
|
||||||
assertEquals(false, sm.inverseBidiMap().containsValue(fromKey));
|
assertFalse(sm.inverseBidiMap().containsValue(fromKey));
|
||||||
assertEquals(false, sub.containsKey(fromKey));
|
assertFalse(sub.containsKey(fromKey));
|
||||||
assertEquals(false, sub.containsValue(fromKeyValue));
|
assertFalse(sub.containsValue(fromKeyValue));
|
||||||
|
|
||||||
assertEquals(false, sm.containsKey(first));
|
assertFalse(sm.containsKey(first));
|
||||||
assertEquals(false, sm.containsValue(firstValue));
|
assertFalse(sm.containsValue(firstValue));
|
||||||
assertEquals(false, sm.inverseBidiMap().containsKey(firstValue));
|
assertFalse(sm.inverseBidiMap().containsKey(firstValue));
|
||||||
assertEquals(false, sm.inverseBidiMap().containsValue(first));
|
assertFalse(sm.inverseBidiMap().containsValue(first));
|
||||||
assertEquals(false, sub.containsKey(first));
|
assertFalse(sub.containsKey(first));
|
||||||
assertEquals(false, sub.containsValue(firstValue));
|
assertFalse(sub.containsValue(firstValue));
|
||||||
|
|
||||||
assertEquals(false, sm.containsKey(second));
|
assertFalse(sm.containsKey(second));
|
||||||
assertEquals(false, sm.containsValue(secondValue));
|
assertFalse(sm.containsValue(secondValue));
|
||||||
assertEquals(false, sm.inverseBidiMap().containsKey(secondValue));
|
assertFalse(sm.inverseBidiMap().containsKey(secondValue));
|
||||||
assertEquals(false, sm.inverseBidiMap().containsValue(second));
|
assertFalse(sm.inverseBidiMap().containsValue(second));
|
||||||
assertEquals(false, sub.containsKey(second));
|
assertFalse(sub.containsKey(second));
|
||||||
assertEquals(false, sub.containsValue(secondValue));
|
assertFalse(sub.containsValue(secondValue));
|
||||||
|
|
||||||
assertEquals(true, sm.containsKey(toKey));
|
assertTrue(sm.containsKey(toKey));
|
||||||
assertEquals(true, sm.containsValue(toKeyValue));
|
assertTrue(sm.containsValue(toKeyValue));
|
||||||
assertEquals(true, sm.inverseBidiMap().containsKey(toKeyValue));
|
assertTrue(sm.inverseBidiMap().containsKey(toKeyValue));
|
||||||
assertEquals(true, sm.inverseBidiMap().containsValue(toKey));
|
assertTrue(sm.inverseBidiMap().containsValue(toKey));
|
||||||
assertEquals(false, sub.containsKey(toKey));
|
assertFalse(sub.containsKey(toKey));
|
||||||
assertEquals(false, sub.containsValue(toKeyValue));
|
assertFalse(sub.containsValue(toKeyValue));
|
||||||
}
|
}
|
||||||
|
|
||||||
//-----------------------------------------------------------------------
|
//-----------------------------------------------------------------------
|
||||||
@ -559,32 +559,32 @@ public abstract class AbstractSortedBidiMapTest<K extends Comparable<K>, V exten
|
|||||||
|
|
||||||
final int size = sm.size();
|
final int size = sm.size();
|
||||||
final SortedMap<K, V> sub = sm.subMap(fromKey, toKey);
|
final SortedMap<K, V> sub = sm.subMap(fromKey, toKey);
|
||||||
assertEquals(true, sm.containsKey(first));
|
assertTrue(sm.containsKey(first));
|
||||||
assertEquals(true, sub.containsKey(first));
|
assertTrue(sub.containsKey(first));
|
||||||
assertEquals(true, sm.containsKey(second));
|
assertTrue(sm.containsKey(second));
|
||||||
assertEquals(true, sub.containsKey(second));
|
assertTrue(sub.containsKey(second));
|
||||||
|
|
||||||
final V firstValue = sub.remove(first);
|
final V firstValue = sub.remove(first);
|
||||||
assertEquals(2, sub.size());
|
assertEquals(2, sub.size());
|
||||||
assertEquals(size - 1, sm.size());
|
assertEquals(size - 1, sm.size());
|
||||||
assertEquals(size - 1, sm.inverseBidiMap().size());
|
assertEquals(size - 1, sm.inverseBidiMap().size());
|
||||||
assertEquals(false, sm.containsKey(first));
|
assertFalse(sm.containsKey(first));
|
||||||
assertEquals(false, sm.containsValue(firstValue));
|
assertFalse(sm.containsValue(firstValue));
|
||||||
assertEquals(false, sm.inverseBidiMap().containsKey(firstValue));
|
assertFalse(sm.inverseBidiMap().containsKey(firstValue));
|
||||||
assertEquals(false, sm.inverseBidiMap().containsValue(first));
|
assertFalse(sm.inverseBidiMap().containsValue(first));
|
||||||
assertEquals(false, sub.containsKey(first));
|
assertFalse(sub.containsKey(first));
|
||||||
assertEquals(false, sub.containsValue(firstValue));
|
assertFalse(sub.containsValue(firstValue));
|
||||||
|
|
||||||
final V secondValue = sub.remove(second);
|
final V secondValue = sub.remove(second);
|
||||||
assertEquals(1, sub.size());
|
assertEquals(1, sub.size());
|
||||||
assertEquals(size - 2, sm.size());
|
assertEquals(size - 2, sm.size());
|
||||||
assertEquals(size - 2, sm.inverseBidiMap().size());
|
assertEquals(size - 2, sm.inverseBidiMap().size());
|
||||||
assertEquals(false, sm.containsKey(second));
|
assertFalse(sm.containsKey(second));
|
||||||
assertEquals(false, sm.containsValue(secondValue));
|
assertFalse(sm.containsValue(secondValue));
|
||||||
assertEquals(false, sm.inverseBidiMap().containsKey(secondValue));
|
assertFalse(sm.inverseBidiMap().containsKey(secondValue));
|
||||||
assertEquals(false, sm.inverseBidiMap().containsValue(second));
|
assertFalse(sm.inverseBidiMap().containsValue(second));
|
||||||
assertEquals(false, sub.containsKey(second));
|
assertFalse(sub.containsKey(second));
|
||||||
assertEquals(false, sub.containsValue(secondValue));
|
assertFalse(sub.containsValue(secondValue));
|
||||||
}
|
}
|
||||||
|
|
||||||
//-----------------------------------------------------------------------
|
//-----------------------------------------------------------------------
|
||||||
@ -611,36 +611,36 @@ public abstract class AbstractSortedBidiMapTest<K extends Comparable<K>, V exten
|
|||||||
it2.next();
|
it2.next();
|
||||||
final Map.Entry<K, V> firstEntry = cloneMapEntry(it2.next());
|
final Map.Entry<K, V> firstEntry = cloneMapEntry(it2.next());
|
||||||
final Map.Entry<K, V> secondEntry = cloneMapEntry(it2.next());
|
final Map.Entry<K, V> secondEntry = cloneMapEntry(it2.next());
|
||||||
assertEquals(true, sm.containsKey(first));
|
assertTrue(sm.containsKey(first));
|
||||||
assertEquals(true, sub.containsKey(first));
|
assertTrue(sub.containsKey(first));
|
||||||
assertEquals(true, set.contains(firstEntry));
|
assertTrue(set.contains(firstEntry));
|
||||||
assertEquals(true, sm.containsKey(second));
|
assertTrue(sm.containsKey(second));
|
||||||
assertEquals(true, sub.containsKey(second));
|
assertTrue(sub.containsKey(second));
|
||||||
assertEquals(true, set.contains(secondEntry));
|
assertTrue(set.contains(secondEntry));
|
||||||
|
|
||||||
set.remove(firstEntry);
|
set.remove(firstEntry);
|
||||||
assertEquals(2, sub.size());
|
assertEquals(2, sub.size());
|
||||||
assertEquals(size - 1, sm.size());
|
assertEquals(size - 1, sm.size());
|
||||||
assertEquals(size - 1, sm.inverseBidiMap().size());
|
assertEquals(size - 1, sm.inverseBidiMap().size());
|
||||||
assertEquals(false, sm.containsKey(firstEntry.getKey()));
|
assertFalse(sm.containsKey(firstEntry.getKey()));
|
||||||
assertEquals(false, sm.containsValue(firstEntry.getValue()));
|
assertFalse(sm.containsValue(firstEntry.getValue()));
|
||||||
assertEquals(false, sm.inverseBidiMap().containsKey(firstEntry.getValue()));
|
assertFalse(sm.inverseBidiMap().containsKey(firstEntry.getValue()));
|
||||||
assertEquals(false, sm.inverseBidiMap().containsValue(firstEntry.getKey()));
|
assertFalse(sm.inverseBidiMap().containsValue(firstEntry.getKey()));
|
||||||
assertEquals(false, sub.containsKey(firstEntry.getKey()));
|
assertFalse(sub.containsKey(firstEntry.getKey()));
|
||||||
assertEquals(false, sub.containsValue(firstEntry.getValue()));
|
assertFalse(sub.containsValue(firstEntry.getValue()));
|
||||||
assertEquals(false, set.contains(firstEntry));
|
assertFalse(set.contains(firstEntry));
|
||||||
|
|
||||||
set.remove(secondEntry);
|
set.remove(secondEntry);
|
||||||
assertEquals(1, sub.size());
|
assertEquals(1, sub.size());
|
||||||
assertEquals(size - 2, sm.size());
|
assertEquals(size - 2, sm.size());
|
||||||
assertEquals(size - 2, sm.inverseBidiMap().size());
|
assertEquals(size - 2, sm.inverseBidiMap().size());
|
||||||
assertEquals(false, sm.containsKey(secondEntry.getKey()));
|
assertFalse(sm.containsKey(secondEntry.getKey()));
|
||||||
assertEquals(false, sm.containsValue(secondEntry.getValue()));
|
assertFalse(sm.containsValue(secondEntry.getValue()));
|
||||||
assertEquals(false, sm.inverseBidiMap().containsKey(secondEntry.getValue()));
|
assertFalse(sm.inverseBidiMap().containsKey(secondEntry.getValue()));
|
||||||
assertEquals(false, sm.inverseBidiMap().containsValue(secondEntry.getKey()));
|
assertFalse(sm.inverseBidiMap().containsValue(secondEntry.getKey()));
|
||||||
assertEquals(false, sub.containsKey(secondEntry.getKey()));
|
assertFalse(sub.containsKey(secondEntry.getKey()));
|
||||||
assertEquals(false, sub.containsValue(secondEntry.getValue()));
|
assertFalse(sub.containsValue(secondEntry.getValue()));
|
||||||
assertEquals(false, set.contains(secondEntry));
|
assertFalse(set.contains(secondEntry));
|
||||||
}
|
}
|
||||||
|
|
||||||
//-----------------------------------------------------------------------
|
//-----------------------------------------------------------------------
|
||||||
|
@ -33,6 +33,7 @@ import java.util.Iterator;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.NoSuchElementException;
|
import java.util.NoSuchElementException;
|
||||||
|
import java.util.Objects;
|
||||||
import java.util.function.Predicate;
|
import java.util.function.Predicate;
|
||||||
|
|
||||||
import org.apache.commons.collections4.AbstractObjectTest;
|
import org.apache.commons.collections4.AbstractObjectTest;
|
||||||
@ -282,7 +283,7 @@ public abstract class AbstractCollectionTest<E> extends AbstractObjectTest {
|
|||||||
// skip values already matched
|
// skip values already matched
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (o == confirmedValues[i] || o != null && o.equals(confirmedValues[i])) {
|
if (Objects.equals(o, confirmedValues[i])) {
|
||||||
// values matched
|
// values matched
|
||||||
matched[i] = true;
|
matched[i] = true;
|
||||||
match = true;
|
match = true;
|
||||||
@ -647,16 +648,14 @@ public abstract class AbstractCollectionTest<E> extends AbstractObjectTest {
|
|||||||
resetEmpty();
|
resetEmpty();
|
||||||
elements = getFullElements();
|
elements = getFullElements();
|
||||||
for (int i = 0; i < elements.length; i++) {
|
for (int i = 0; i < elements.length; i++) {
|
||||||
assertTrue("Empty collection shouldn't contain element[" + i + "]",
|
assertFalse("Empty collection shouldn't contain element[" + i + "]", getCollection().contains(elements[i]));
|
||||||
!getCollection().contains(elements[i]));
|
|
||||||
}
|
}
|
||||||
// make sure calls to "contains" don't change anything
|
// make sure calls to "contains" don't change anything
|
||||||
verify();
|
verify();
|
||||||
|
|
||||||
elements = getOtherElements();
|
elements = getOtherElements();
|
||||||
for (int i = 0; i < elements.length; i++) {
|
for (int i = 0; i < elements.length; i++) {
|
||||||
assertTrue("Empty collection shouldn't contain element[" + i + "]",
|
assertFalse("Empty collection shouldn't contain element[" + i + "]", getCollection().contains(elements[i]));
|
||||||
!getCollection().contains(elements[i]));
|
|
||||||
}
|
}
|
||||||
// make sure calls to "contains" don't change anything
|
// make sure calls to "contains" don't change anything
|
||||||
verify();
|
verify();
|
||||||
@ -673,8 +672,7 @@ public abstract class AbstractCollectionTest<E> extends AbstractObjectTest {
|
|||||||
resetFull();
|
resetFull();
|
||||||
elements = getOtherElements();
|
elements = getOtherElements();
|
||||||
for (final Object element : elements) {
|
for (final Object element : elements) {
|
||||||
assertTrue("Full collection shouldn't contain element",
|
assertFalse("Full collection shouldn't contain element", getCollection().contains(element));
|
||||||
!getCollection().contains(element));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -687,14 +685,13 @@ public abstract class AbstractCollectionTest<E> extends AbstractObjectTest {
|
|||||||
assertTrue("Every Collection should contain all elements of an " +
|
assertTrue("Every Collection should contain all elements of an " +
|
||||||
"empty Collection.", getCollection().containsAll(col));
|
"empty Collection.", getCollection().containsAll(col));
|
||||||
col.addAll(Arrays.asList(getOtherElements()));
|
col.addAll(Arrays.asList(getOtherElements()));
|
||||||
assertTrue("Empty Collection shouldn't contain all elements of " +
|
assertFalse("Empty Collection shouldn't contain all elements of " +
|
||||||
"a non-empty Collection.", !getCollection().containsAll(col));
|
"a non-empty Collection.", getCollection().containsAll(col));
|
||||||
// make sure calls to "containsAll" don't change anything
|
// make sure calls to "containsAll" don't change anything
|
||||||
verify();
|
verify();
|
||||||
|
|
||||||
resetFull();
|
resetFull();
|
||||||
assertTrue("Full collection shouldn't contain other elements",
|
assertFalse("Full collection shouldn't contain other elements", getCollection().containsAll(col));
|
||||||
!getCollection().containsAll(col));
|
|
||||||
|
|
||||||
col.clear();
|
col.clear();
|
||||||
col.addAll(Arrays.asList(getFullElements()));
|
col.addAll(Arrays.asList(getFullElements()));
|
||||||
@ -728,12 +725,12 @@ public abstract class AbstractCollectionTest<E> extends AbstractObjectTest {
|
|||||||
*/
|
*/
|
||||||
public void testCollectionIsEmpty() {
|
public void testCollectionIsEmpty() {
|
||||||
resetEmpty();
|
resetEmpty();
|
||||||
assertEquals("New Collection should be empty.", true, getCollection().isEmpty());
|
assertTrue("New Collection should be empty.", getCollection().isEmpty());
|
||||||
// make sure calls to "isEmpty() don't change anything
|
// make sure calls to "isEmpty() don't change anything
|
||||||
verify();
|
verify();
|
||||||
|
|
||||||
resetFull();
|
resetFull();
|
||||||
assertEquals("Full collection shouldn't be empty", false, getCollection().isEmpty());
|
assertFalse("Full collection shouldn't be empty", getCollection().isEmpty());
|
||||||
// make sure calls to "isEmpty() don't change anything
|
// make sure calls to "isEmpty() don't change anything
|
||||||
verify();
|
verify();
|
||||||
}
|
}
|
||||||
@ -744,7 +741,7 @@ public abstract class AbstractCollectionTest<E> extends AbstractObjectTest {
|
|||||||
public void testCollectionIterator() {
|
public void testCollectionIterator() {
|
||||||
resetEmpty();
|
resetEmpty();
|
||||||
Iterator<E> it1 = getCollection().iterator();
|
Iterator<E> it1 = getCollection().iterator();
|
||||||
assertEquals("Iterator for empty Collection shouldn't have next.", false, it1.hasNext());
|
assertFalse("Iterator for empty Collection shouldn't have next.", it1.hasNext());
|
||||||
try {
|
try {
|
||||||
it1.next();
|
it1.next();
|
||||||
fail("Iterator at end of Collection should throw "
|
fail("Iterator at end of Collection should throw "
|
||||||
@ -761,7 +758,7 @@ public abstract class AbstractCollectionTest<E> extends AbstractObjectTest {
|
|||||||
assertTrue("Iterator for full collection should haveNext", it1.hasNext());
|
assertTrue("Iterator for full collection should haveNext", it1.hasNext());
|
||||||
it1.next();
|
it1.next();
|
||||||
}
|
}
|
||||||
assertTrue("Iterator should be finished", !it1.hasNext());
|
assertFalse("Iterator should be finished", it1.hasNext());
|
||||||
|
|
||||||
final ArrayList<E> list = new ArrayList<>();
|
final ArrayList<E> list = new ArrayList<>();
|
||||||
it1 = getCollection().iterator();
|
it1 = getCollection().iterator();
|
||||||
@ -871,7 +868,7 @@ public abstract class AbstractCollectionTest<E> extends AbstractObjectTest {
|
|||||||
|
|
||||||
resetFull();
|
resetFull();
|
||||||
for (final E element : other) {
|
for (final E element : other) {
|
||||||
assertTrue("Shouldn't remove nonexistent other element", !getCollection().remove(element));
|
assertFalse("Shouldn't remove nonexistent other element", getCollection().remove(element));
|
||||||
verify();
|
verify();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -916,12 +913,10 @@ public abstract class AbstractCollectionTest<E> extends AbstractObjectTest {
|
|||||||
verify();
|
verify();
|
||||||
|
|
||||||
resetFull();
|
resetFull();
|
||||||
assertTrue("Full collection removeAll should return false for empty input",
|
assertFalse("Full collection removeAll should return false for empty input", getCollection().removeAll(Collections.EMPTY_SET));
|
||||||
!getCollection().removeAll(Collections.EMPTY_SET));
|
|
||||||
verify();
|
verify();
|
||||||
|
|
||||||
assertTrue("Full collection removeAll should return false for other elements",
|
assertFalse("Full collection removeAll should return false for other elements", getCollection().removeAll(Arrays.asList(getOtherElements())));
|
||||||
!getCollection().removeAll(Arrays.asList(getOtherElements())));
|
|
||||||
verify();
|
verify();
|
||||||
|
|
||||||
assertTrue("Full collection removeAll should return true for full elements",
|
assertTrue("Full collection removeAll should return true for full elements",
|
||||||
@ -941,7 +936,7 @@ public abstract class AbstractCollectionTest<E> extends AbstractObjectTest {
|
|||||||
|
|
||||||
assertTrue("Collection should shrink after removeAll", getCollection().size() < size);
|
assertTrue("Collection should shrink after removeAll", getCollection().size() < size);
|
||||||
for (final E element : all) {
|
for (final E element : all) {
|
||||||
assertTrue("Collection shouldn't contain removed element", !getCollection().contains(element));
|
assertFalse("Collection shouldn't contain removed element", getCollection().contains(element));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -955,17 +950,14 @@ public abstract class AbstractCollectionTest<E> extends AbstractObjectTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
resetEmpty();
|
resetEmpty();
|
||||||
assertTrue("Empty collection removeIf should return false for a predicate that returns only false",
|
assertFalse("Empty collection removeIf should return false for a predicate that returns only false", getCollection().removeIf(e -> false));
|
||||||
!getCollection().removeIf(e -> false));
|
|
||||||
verify();
|
verify();
|
||||||
|
|
||||||
assertTrue("Empty collection removeIf should return false for a predicate that returns only true",
|
assertFalse("Empty collection removeIf should return false for a predicate that returns only true", getCollection().removeIf(e -> true));
|
||||||
!getCollection().removeIf(e -> true));
|
|
||||||
verify();
|
verify();
|
||||||
|
|
||||||
resetFull();
|
resetFull();
|
||||||
assertTrue("Full collection removeIf should return false for a predicate that returns only false",
|
assertFalse("Full collection removeIf should return false for a predicate that returns only false", getCollection().removeIf(e -> false));
|
||||||
!getCollection().removeIf(e -> false));
|
|
||||||
verify();
|
verify();
|
||||||
|
|
||||||
assertTrue("Full collection removeIf should return true for a predicate that returns only true",
|
assertTrue("Full collection removeIf should return true for a predicate that returns only true",
|
||||||
@ -988,8 +980,8 @@ public abstract class AbstractCollectionTest<E> extends AbstractObjectTest {
|
|||||||
getConfirmed().removeIf(filter);
|
getConfirmed().removeIf(filter);
|
||||||
verify();
|
verify();
|
||||||
|
|
||||||
assertTrue("Collection should shrink after removeIf", getCollection().size() == size - targetCount);
|
assertEquals("Collection should shrink after removeIf", getCollection().size(), size - targetCount);
|
||||||
assertTrue("Collection shouldn't contain removed element", !getCollection().contains(target));
|
assertFalse("Collection shouldn't contain removed element", getCollection().contains(target));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -1004,11 +996,10 @@ public abstract class AbstractCollectionTest<E> extends AbstractObjectTest {
|
|||||||
final List<E> elements = Arrays.asList(getFullElements());
|
final List<E> elements = Arrays.asList(getFullElements());
|
||||||
final List<E> other = Arrays.asList(getOtherElements());
|
final List<E> other = Arrays.asList(getOtherElements());
|
||||||
|
|
||||||
assertTrue("Empty retainAll() should return false",
|
assertFalse("Empty retainAll() should return false", getCollection().retainAll(Collections.EMPTY_SET));
|
||||||
!getCollection().retainAll(Collections.EMPTY_SET));
|
|
||||||
verify();
|
verify();
|
||||||
|
|
||||||
assertTrue("Empty retainAll() should return false", !getCollection().retainAll(elements));
|
assertFalse("Empty retainAll() should return false", getCollection().retainAll(elements));
|
||||||
verify();
|
verify();
|
||||||
|
|
||||||
resetFull();
|
resetFull();
|
||||||
@ -1024,8 +1015,7 @@ public abstract class AbstractCollectionTest<E> extends AbstractObjectTest {
|
|||||||
|
|
||||||
resetFull();
|
resetFull();
|
||||||
int size = getCollection().size();
|
int size = getCollection().size();
|
||||||
assertTrue("Collection shouldn't change from retainAll elements",
|
assertFalse("Collection shouldn't change from retainAll elements", getCollection().retainAll(elements));
|
||||||
!getCollection().retainAll(elements));
|
|
||||||
verify();
|
verify();
|
||||||
assertEquals("Collection size shouldn't change", size, getCollection().size());
|
assertEquals("Collection size shouldn't change", size, getCollection().size());
|
||||||
|
|
||||||
@ -1047,8 +1037,8 @@ public abstract class AbstractCollectionTest<E> extends AbstractObjectTest {
|
|||||||
resetFull();
|
resetFull();
|
||||||
final HashSet<E> set = new HashSet<>(elements);
|
final HashSet<E> set = new HashSet<>(elements);
|
||||||
size = getCollection().size();
|
size = getCollection().size();
|
||||||
assertTrue("Collection shouldn't change from retainAll without " +
|
assertFalse("Collection shouldn't change from retainAll without " +
|
||||||
"duplicate elements", !getCollection().retainAll(set));
|
"duplicate elements", getCollection().retainAll(set));
|
||||||
verify();
|
verify();
|
||||||
assertEquals("Collection size didn't change from nonduplicate " +
|
assertEquals("Collection size didn't change from nonduplicate " +
|
||||||
"retainAll", size, getCollection().size());
|
"retainAll", size, getCollection().size());
|
||||||
@ -1093,8 +1083,7 @@ public abstract class AbstractCollectionTest<E> extends AbstractObjectTest {
|
|||||||
if (matched[j]) {
|
if (matched[j]) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (array[i] == confirmedArray[j]
|
if (Objects.equals(array[i], confirmedArray[j])) {
|
||||||
|| array[i] != null && array[i].equals(confirmedArray[j])) {
|
|
||||||
matched[j] = true;
|
matched[j] = true;
|
||||||
match = true;
|
match = true;
|
||||||
break;
|
break;
|
||||||
@ -1106,8 +1095,7 @@ public abstract class AbstractCollectionTest<E> extends AbstractObjectTest {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (final boolean element : matched) {
|
for (final boolean element : matched) {
|
||||||
assertEquals("Collection should return all its elements in " + "toArray", true,
|
assertTrue("Collection should return all its elements in " + "toArray", element);
|
||||||
element);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1174,10 +1162,10 @@ public abstract class AbstractCollectionTest<E> extends AbstractObjectTest {
|
|||||||
*/
|
*/
|
||||||
public void testCollectionToString() {
|
public void testCollectionToString() {
|
||||||
resetEmpty();
|
resetEmpty();
|
||||||
assertTrue("toString shouldn't return null", getCollection().toString() != null);
|
assertNotNull("toString shouldn't return null", getCollection().toString());
|
||||||
|
|
||||||
resetFull();
|
resetFull();
|
||||||
assertTrue("toString shouldn't return null", getCollection().toString() != null);
|
assertNotNull("toString shouldn't return null", getCollection().toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -81,9 +81,7 @@ public class CompositeCollectionTest<E> extends AbstractCollectionTest<E> {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public Collection<E> makeConfirmedFullCollection() {
|
public Collection<E> makeConfirmedFullCollection() {
|
||||||
final Collection<E> collection = new HashSet<>();
|
return new HashSet<>(Arrays.asList(getFullElements()));
|
||||||
collection.addAll(Arrays.asList(getFullElements()));
|
|
||||||
return collection;
|
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* Full collection consists of 4 collections, each with one element
|
* Full collection consists of 4 collections, each with one element
|
||||||
@ -188,8 +186,7 @@ public class CompositeCollectionTest<E> extends AbstractCollectionTest<E> {
|
|||||||
one.add((E) "1");
|
one.add((E) "1");
|
||||||
two.add((E) "2");
|
two.add((E) "2");
|
||||||
c.addComposited(one, two);
|
c.addComposited(one, two);
|
||||||
final Collection<E> toCollection = new HashSet<>();
|
final Collection<E> toCollection = new HashSet<>(c);
|
||||||
toCollection.addAll(c);
|
|
||||||
assertTrue(toCollection.containsAll(c));
|
assertTrue(toCollection.containsAll(c));
|
||||||
assertEquals(c.size(), toCollection.size());
|
assertEquals(c.size(), toCollection.size());
|
||||||
}
|
}
|
||||||
@ -281,7 +278,7 @@ public class CompositeCollectionTest<E> extends AbstractCollectionTest<E> {
|
|||||||
c.addComposited(empty);
|
c.addComposited(empty);
|
||||||
assertTrue(c.isEmpty());
|
assertTrue(c.isEmpty());
|
||||||
empty.add((E) "a");
|
empty.add((E) "a");
|
||||||
assertTrue(!c.isEmpty());
|
assertFalse(c.isEmpty());
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
@ -297,8 +294,8 @@ public class CompositeCollectionTest<E> extends AbstractCollectionTest<E> {
|
|||||||
assertTrue(one.contains(next));
|
assertTrue(one.contains(next));
|
||||||
next = i.next();
|
next = i.next();
|
||||||
i.remove();
|
i.remove();
|
||||||
assertTrue(!c.contains(next));
|
assertFalse(c.contains(next));
|
||||||
assertTrue(!two.contains(next));
|
assertFalse(two.contains(next));
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
@ -322,9 +319,9 @@ public class CompositeCollectionTest<E> extends AbstractCollectionTest<E> {
|
|||||||
two.add((E) "1");
|
two.add((E) "1");
|
||||||
c.addComposited(one, two);
|
c.addComposited(one, two);
|
||||||
c.remove("1");
|
c.remove("1");
|
||||||
assertTrue(!c.contains("1"));
|
assertFalse(c.contains("1"));
|
||||||
assertTrue(!one.contains("1"));
|
assertFalse(one.contains("1"));
|
||||||
assertTrue(!two.contains("1"));
|
assertFalse(two.contains("1"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
@ -341,9 +338,9 @@ public class CompositeCollectionTest<E> extends AbstractCollectionTest<E> {
|
|||||||
assertTrue(!one.contains("1"));
|
assertTrue(!one.contains("1"));
|
||||||
assertTrue(!two.contains("1"));
|
assertTrue(!two.contains("1"));
|
||||||
c.removeAll(null);
|
c.removeAll(null);
|
||||||
assertTrue(!c.contains("1"));
|
assertFalse(c.contains("1"));
|
||||||
assertTrue(!one.contains("1"));
|
assertFalse(one.contains("1"));
|
||||||
assertTrue(!two.contains("1"));
|
assertFalse(two.contains("1"));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -388,13 +385,13 @@ public class CompositeCollectionTest<E> extends AbstractCollectionTest<E> {
|
|||||||
two.add((E) "1");
|
two.add((E) "1");
|
||||||
c.addComposited(one);
|
c.addComposited(one);
|
||||||
c.retainAll(two);
|
c.retainAll(two);
|
||||||
assertTrue(!c.contains("2"));
|
assertFalse(c.contains("2"));
|
||||||
assertTrue(!one.contains("2"));
|
assertFalse(one.contains("2"));
|
||||||
assertTrue(c.contains("1"));
|
assertTrue(c.contains("1"));
|
||||||
assertTrue(one.contains("1"));
|
assertTrue(one.contains("1"));
|
||||||
c.retainAll(null);
|
c.retainAll(null);
|
||||||
assertTrue(!c.contains("2"));
|
assertFalse(c.contains("2"));
|
||||||
assertTrue(!one.contains("2"));
|
assertFalse(one.contains("2"));
|
||||||
assertTrue(c.contains("1"));
|
assertTrue(c.contains("1"));
|
||||||
assertTrue(one.contains("1"));
|
assertTrue(one.contains("1"));
|
||||||
}
|
}
|
||||||
@ -419,7 +416,7 @@ public class CompositeCollectionTest<E> extends AbstractCollectionTest<E> {
|
|||||||
assertTrue(foo.containsAll(c));
|
assertTrue(foo.containsAll(c));
|
||||||
assertEquals(c.size(), foo.size());
|
assertEquals(c.size(), foo.size());
|
||||||
one.add((E) "3");
|
one.add((E) "3");
|
||||||
assertTrue(!foo.containsAll(c));
|
assertFalse(foo.containsAll(c));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -62,16 +62,13 @@ public class PredicatedCollectionTest<E> extends AbstractCollectionTest<E> {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Collection<E> makeFullCollection() {
|
public Collection<E> makeFullCollection() {
|
||||||
final List<E> list = new ArrayList<>();
|
final List<E> list = new ArrayList<>(Arrays.asList(getFullElements()));
|
||||||
list.addAll(Arrays.asList(getFullElements()));
|
|
||||||
return decorateCollection(list, truePredicate);
|
return decorateCollection(list, truePredicate);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Collection<E> makeConfirmedFullCollection() {
|
public Collection<E> makeConfirmedFullCollection() {
|
||||||
final List<E> list = new ArrayList<>();
|
return new ArrayList<>(Arrays.asList(getFullElements()));
|
||||||
list.addAll(Arrays.asList(getFullElements()));
|
|
||||||
return list;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//-----------------------------------------------------------------------
|
//-----------------------------------------------------------------------
|
||||||
@ -85,15 +82,14 @@ public class PredicatedCollectionTest<E> extends AbstractCollectionTest<E> {
|
|||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public void testIllegalAdd() {
|
public void testIllegalAdd() {
|
||||||
final Collection<E> c = makeTestCollection();
|
final Collection<E> c = makeTestCollection();
|
||||||
final Integer i = Integer.valueOf(3);
|
final Integer i = 3;
|
||||||
try {
|
try {
|
||||||
c.add((E) i);
|
c.add((E) i);
|
||||||
fail("Integer should fail string predicate.");
|
fail("Integer should fail string predicate.");
|
||||||
} catch (final IllegalArgumentException e) {
|
} catch (final IllegalArgumentException e) {
|
||||||
// expected
|
// expected
|
||||||
}
|
}
|
||||||
assertTrue("Collection shouldn't contain illegal element",
|
assertFalse("Collection shouldn't contain illegal element", c.contains(i));
|
||||||
!c.contains(i));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
@ -110,10 +106,10 @@ public class PredicatedCollectionTest<E> extends AbstractCollectionTest<E> {
|
|||||||
} catch (final IllegalArgumentException e) {
|
} catch (final IllegalArgumentException e) {
|
||||||
// expected
|
// expected
|
||||||
}
|
}
|
||||||
assertTrue("Collection shouldn't contain illegal element", !c.contains("one"));
|
assertFalse("Collection shouldn't contain illegal element", c.contains("one"));
|
||||||
assertTrue("Collection shouldn't contain illegal element", !c.contains("two"));
|
assertFalse("Collection shouldn't contain illegal element", c.contains("two"));
|
||||||
assertTrue("Collection shouldn't contain illegal element", !c.contains(Integer.valueOf(3)));
|
assertFalse("Collection shouldn't contain illegal element", c.contains(3));
|
||||||
assertTrue("Collection shouldn't contain illegal element", !c.contains("four"));
|
assertFalse("Collection shouldn't contain illegal element", c.contains("four"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -63,9 +63,7 @@ public class TransformedCollectionTest extends AbstractCollectionTest<Object> {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Collection<Object> makeConfirmedFullCollection() {
|
public Collection<Object> makeConfirmedFullCollection() {
|
||||||
final List<Object> list = new ArrayList<>();
|
return new ArrayList<>(Arrays.asList(getFullElements()));
|
||||||
list.addAll(Arrays.asList(getFullElements()));
|
|
||||||
return list;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -75,8 +73,7 @@ public class TransformedCollectionTest extends AbstractCollectionTest<Object> {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Collection<Object> makeFullCollection() {
|
public Collection<Object> makeFullCollection() {
|
||||||
final List<Object> list = new ArrayList<>();
|
final List<Object> list = new ArrayList<>(Arrays.asList(getFullElements()));
|
||||||
list.addAll(Arrays.asList(getFullElements()));
|
|
||||||
return TransformedCollection.transformingCollection(list, NOOP_TRANSFORMER);
|
return TransformedCollection.transformingCollection(list, NOOP_TRANSFORMER);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -99,11 +96,11 @@ public class TransformedCollectionTest extends AbstractCollectionTest<Object> {
|
|||||||
for (int i = 0; i < elements.length; i++) {
|
for (int i = 0; i < elements.length; i++) {
|
||||||
coll.add(elements[i]);
|
coll.add(elements[i]);
|
||||||
assertEquals(i + 1, coll.size());
|
assertEquals(i + 1, coll.size());
|
||||||
assertEquals(true, coll.contains(Integer.valueOf((String) elements[i])));
|
assertTrue(coll.contains(Integer.valueOf((String) elements[i])));
|
||||||
assertEquals(false, coll.contains(elements[i]));
|
assertFalse(coll.contains(elements[i]));
|
||||||
}
|
}
|
||||||
|
|
||||||
assertEquals(true, coll.remove(Integer.valueOf((String) elements[0])));
|
assertTrue(coll.remove(Integer.valueOf((String) elements[0])));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testTransformedCollection_decorateTransform() {
|
public void testTransformedCollection_decorateTransform() {
|
||||||
@ -113,12 +110,12 @@ public class TransformedCollectionTest extends AbstractCollectionTest<Object> {
|
|||||||
final Collection<Object> collection = TransformedCollection.transformedCollection(originalCollection, TransformedCollectionTest.STRING_TO_INTEGER_TRANSFORMER);
|
final Collection<Object> collection = TransformedCollection.transformedCollection(originalCollection, TransformedCollectionTest.STRING_TO_INTEGER_TRANSFORMER);
|
||||||
assertEquals(elements.length, collection.size());
|
assertEquals(elements.length, collection.size());
|
||||||
for (final Object element : elements) {
|
for (final Object element : elements) {
|
||||||
assertEquals(true, collection.contains(Integer.valueOf((String) element)));
|
assertTrue(collection.contains(Integer.valueOf((String) element)));
|
||||||
assertEquals(false, collection.contains(element));
|
assertFalse(collection.contains(element));
|
||||||
}
|
}
|
||||||
|
|
||||||
assertEquals(false, collection.remove(elements[0]));
|
assertFalse(collection.remove(elements[0]));
|
||||||
assertEquals(true, collection.remove(Integer.valueOf((String) elements[0])));
|
assertTrue(collection.remove(Integer.valueOf((String) elements[0])));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -97,7 +97,7 @@ public abstract class AbstractComparatorTest<T> extends AbstractObjectTest {
|
|||||||
* Sort the list.
|
* Sort the list.
|
||||||
*/
|
*/
|
||||||
protected void sortObjects(final List<T> list, final Comparator<? super T> comparator) {
|
protected void sortObjects(final List<T> list, final Comparator<? super T> comparator) {
|
||||||
Collections.sort(list, comparator);
|
list.sort(comparator);
|
||||||
}
|
}
|
||||||
|
|
||||||
//-----------------------------------------------------------------------
|
//-----------------------------------------------------------------------
|
||||||
@ -111,7 +111,7 @@ public abstract class AbstractComparatorTest<T> extends AbstractObjectTest {
|
|||||||
|
|
||||||
final List<T> list2 = new LinkedList<>();
|
final List<T> list2 = new LinkedList<>();
|
||||||
|
|
||||||
assertTrue("Comparator cannot sort empty lists", list2.equals(list));
|
assertEquals("Comparator cannot sort empty lists", list2, list);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -127,8 +127,7 @@ public abstract class AbstractComparatorTest<T> extends AbstractObjectTest {
|
|||||||
|
|
||||||
final List<T> orderedList = getComparableObjectsOrdered();
|
final List<T> orderedList = getComparableObjectsOrdered();
|
||||||
|
|
||||||
assertTrue("Comparator did not reorder the List correctly",
|
assertEquals("Comparator did not reorder the List correctly", orderedList, randomList);
|
||||||
orderedList.equals(randomList));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -151,9 +150,7 @@ public abstract class AbstractComparatorTest<T> extends AbstractObjectTest {
|
|||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
assertTrue("Comparator did not reorder the List correctly",
|
assertEquals("Comparator did not reorder the List correctly", orderedList, randomList);
|
||||||
orderedList.equals(randomList));
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -216,9 +213,7 @@ public abstract class AbstractComparatorTest<T> extends AbstractObjectTest {
|
|||||||
|
|
||||||
final List<T> orderedList = getComparableObjectsOrdered();
|
final List<T> orderedList = getComparableObjectsOrdered();
|
||||||
|
|
||||||
assertTrue("Comparator did not reorder the List correctly",
|
assertEquals("Comparator did not reorder the List correctly", orderedList, randomList);
|
||||||
orderedList.equals(randomList));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -17,11 +17,14 @@
|
|||||||
package org.apache.commons.collections4.comparators;
|
package org.apache.commons.collections4.comparators;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertNotEquals;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests for {@link BooleanComparator}.
|
* Tests for {@link BooleanComparator}.
|
||||||
*
|
*
|
||||||
@ -46,14 +49,8 @@ public class BooleanComparatorTest extends AbstractComparatorTest<Boolean> {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<Boolean> getComparableObjectsOrdered() {
|
public List<Boolean> getComparableObjectsOrdered() {
|
||||||
final List<Boolean> list = new ArrayList<>();
|
return new ArrayList<>(Arrays.asList(Boolean.FALSE, Boolean.FALSE, Boolean.FALSE, Boolean.TRUE, Boolean.TRUE,
|
||||||
list.add(new Boolean(false));
|
true));
|
||||||
list.add(Boolean.FALSE);
|
|
||||||
list.add(new Boolean(false));
|
|
||||||
list.add(Boolean.TRUE);
|
|
||||||
list.add(new Boolean(true));
|
|
||||||
list.add(true);
|
|
||||||
return list;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -95,8 +92,8 @@ public class BooleanComparatorTest extends AbstractComparatorTest<Boolean> {
|
|||||||
assertEquals(new BooleanComparator(true), BooleanComparator.getTrueFirstComparator());
|
assertEquals(new BooleanComparator(true), BooleanComparator.getTrueFirstComparator());
|
||||||
assertSame(BooleanComparator.getTrueFirstComparator(), BooleanComparator.booleanComparator(true));
|
assertSame(BooleanComparator.getTrueFirstComparator(), BooleanComparator.booleanComparator(true));
|
||||||
|
|
||||||
assertTrue(!new BooleanComparator().equals(new BooleanComparator(true)));
|
assertNotEquals(new BooleanComparator(), new BooleanComparator(true));
|
||||||
assertTrue(!new BooleanComparator(true).equals(new BooleanComparator(false)));
|
assertNotEquals(new BooleanComparator(true), new BooleanComparator(false));
|
||||||
}
|
}
|
||||||
|
|
||||||
// utilities
|
// utilities
|
||||||
|
@ -17,6 +17,7 @@
|
|||||||
package org.apache.commons.collections4.comparators;
|
package org.apache.commons.collections4.comparators;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -53,19 +54,19 @@ public class ComparatorChainTest extends AbstractComparatorTest<ComparatorChainT
|
|||||||
@Test
|
@Test
|
||||||
public void testNoopComparatorChain() {
|
public void testNoopComparatorChain() {
|
||||||
final ComparatorChain<Integer> chain = new ComparatorChain<>();
|
final ComparatorChain<Integer> chain = new ComparatorChain<>();
|
||||||
final Integer i1 = Integer.valueOf(4);
|
final Integer i1 = 4;
|
||||||
final Integer i2 = Integer.valueOf(6);
|
final Integer i2 = 6;
|
||||||
chain.addComparator(new ComparableComparator<Integer>());
|
chain.addComparator(new ComparableComparator<>());
|
||||||
|
|
||||||
final int correctValue = i1.compareTo(i2);
|
final int correctValue = i1.compareTo(i2);
|
||||||
assertTrue("Comparison returns the right order", chain.compare(i1, i2) == correctValue);
|
assertEquals("Comparison returns the right order", chain.compare(i1, i2), correctValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testBadNoopComparatorChain() {
|
public void testBadNoopComparatorChain() {
|
||||||
final ComparatorChain<Integer> chain = new ComparatorChain<>();
|
final ComparatorChain<Integer> chain = new ComparatorChain<>();
|
||||||
final Integer i1 = Integer.valueOf(4);
|
final Integer i1 = 4;
|
||||||
final Integer i2 = Integer.valueOf(6);
|
final Integer i2 = 6;
|
||||||
try {
|
try {
|
||||||
chain.compare(i1, i2);
|
chain.compare(i1, i2);
|
||||||
fail("An exception should be thrown when a chain contains zero comparators.");
|
fail("An exception should be thrown when a chain contains zero comparators.");
|
||||||
@ -76,21 +77,21 @@ public class ComparatorChainTest extends AbstractComparatorTest<ComparatorChainT
|
|||||||
@Test
|
@Test
|
||||||
public void testListComparatorChain() {
|
public void testListComparatorChain() {
|
||||||
final List<Comparator<Integer>> list = new LinkedList<>();
|
final List<Comparator<Integer>> list = new LinkedList<>();
|
||||||
list.add(new ComparableComparator<Integer>());
|
list.add(new ComparableComparator<>());
|
||||||
final ComparatorChain<Integer> chain = new ComparatorChain<>(list);
|
final ComparatorChain<Integer> chain = new ComparatorChain<>(list);
|
||||||
final Integer i1 = Integer.valueOf(4);
|
final Integer i1 = 4;
|
||||||
final Integer i2 = Integer.valueOf(6);
|
final Integer i2 = 6;
|
||||||
|
|
||||||
final int correctValue = i1.compareTo(i2);
|
final int correctValue = i1.compareTo(i2);
|
||||||
assertTrue("Comparison returns the right order", chain.compare(i1, i2) == correctValue);
|
assertEquals("Comparison returns the right order", chain.compare(i1, i2), correctValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testBadListComparatorChain() {
|
public void testBadListComparatorChain() {
|
||||||
final List<Comparator<Integer>> list = new LinkedList<>();
|
final List<Comparator<Integer>> list = new LinkedList<>();
|
||||||
final ComparatorChain<Integer> chain = new ComparatorChain<>(list);
|
final ComparatorChain<Integer> chain = new ComparatorChain<>(list);
|
||||||
final Integer i1 = Integer.valueOf(4);
|
final Integer i1 = 4;
|
||||||
final Integer i2 = Integer.valueOf(6);
|
final Integer i2 = 6;
|
||||||
try {
|
try {
|
||||||
chain.compare(i1, i2);
|
chain.compare(i1, i2);
|
||||||
fail("An exception should be thrown when a chain contains zero comparators.");
|
fail("An exception should be thrown when a chain contains zero comparators.");
|
||||||
@ -114,24 +115,18 @@ public class ComparatorChainTest extends AbstractComparatorTest<ComparatorChainT
|
|||||||
return 0;
|
return 0;
|
||||||
}, true);
|
}, true);
|
||||||
|
|
||||||
assertTrue(chain.compare(Integer.valueOf(4), Integer.valueOf(5)) > 0);
|
assertTrue(chain.compare(4, 5) > 0);
|
||||||
assertTrue(chain.compare(Integer.valueOf(5), Integer.valueOf(4)) < 0);
|
assertTrue(chain.compare(5, 4) < 0);
|
||||||
assertTrue(chain.compare(Integer.valueOf(4), Integer.valueOf(4)) == 0);
|
assertEquals(0, chain.compare(4, 4));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<PseudoRow> getComparableObjectsOrdered() {
|
public List<PseudoRow> getComparableObjectsOrdered() {
|
||||||
final List<PseudoRow> list = new LinkedList<>();
|
|
||||||
// this is the correct order assuming a
|
// this is the correct order assuming a
|
||||||
// "0th forward, 1st reverse, 2nd forward" sort
|
// "0th forward, 1st reverse, 2nd forward" sort
|
||||||
list.add(new PseudoRow(1, 2, 3));
|
return new LinkedList<>(Arrays.asList(new PseudoRow(1, 2, 3), new PseudoRow(2, 3, 5),
|
||||||
list.add(new PseudoRow(2, 3, 5));
|
new PseudoRow(2, 2, 4), new PseudoRow(2, 2, 8), new PseudoRow(3, 1, 0),
|
||||||
list.add(new PseudoRow(2, 2, 4));
|
new PseudoRow(4, 4, 4), new PseudoRow(4, 4, 7)));
|
||||||
list.add(new PseudoRow(2, 2, 8));
|
|
||||||
list.add(new PseudoRow(3, 1, 0));
|
|
||||||
list.add(new PseudoRow(4, 4, 4));
|
|
||||||
list.add(new PseudoRow(4, 4, 7));
|
|
||||||
return list;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class PseudoRow implements Serializable {
|
public static class PseudoRow implements Serializable {
|
||||||
@ -140,7 +135,7 @@ public class ComparatorChainTest extends AbstractComparatorTest<ComparatorChainT
|
|||||||
* Generated serial version ID.
|
* Generated serial version ID.
|
||||||
*/
|
*/
|
||||||
private static final long serialVersionUID = 8085570439751032499L;
|
private static final long serialVersionUID = 8085570439751032499L;
|
||||||
public int cols[] = new int[3];
|
public int[] cols = new int[3];
|
||||||
|
|
||||||
public PseudoRow(final int col1, final int col2, final int col3) {
|
public PseudoRow(final int col1, final int col2, final int col3) {
|
||||||
cols[0] = col1;
|
cols[0] = col1;
|
||||||
@ -154,15 +149,7 @@ public class ComparatorChainTest extends AbstractComparatorTest<ComparatorChainT
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
final StringBuilder buf = new StringBuilder();
|
return "[" + cols[0] + "," + cols[1] + "," + cols[2] + "]";
|
||||||
buf.append("[");
|
|
||||||
buf.append(cols[0]);
|
|
||||||
buf.append(",");
|
|
||||||
buf.append(cols[1]);
|
|
||||||
buf.append(",");
|
|
||||||
buf.append(cols[2]);
|
|
||||||
buf.append("]");
|
|
||||||
return buf.toString();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -172,21 +159,9 @@ public class ComparatorChainTest extends AbstractComparatorTest<ComparatorChainT
|
|||||||
}
|
}
|
||||||
|
|
||||||
final PseudoRow row = (PseudoRow) o;
|
final PseudoRow row = (PseudoRow) o;
|
||||||
if (getColumn(0) != row.getColumn(0)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (getColumn(1) != row.getColumn(1)) {
|
return getColumn(0) == row.getColumn(0) && getColumn(1) == row.getColumn(1) && getColumn(2) == row.getColumn(2);
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (getColumn(2) != row.getColumn(2)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class ColumnComparator implements Comparator<PseudoRow>, Serializable {
|
public static class ColumnComparator implements Comparator<PseudoRow>, Serializable {
|
||||||
@ -200,17 +175,7 @@ public class ComparatorChainTest extends AbstractComparatorTest<ComparatorChainT
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int compare(final PseudoRow o1, final PseudoRow o2) {
|
public int compare(final PseudoRow o1, final PseudoRow o2) {
|
||||||
|
return Integer.compare(o1.getColumn(colIndex), o2.getColumn(colIndex));
|
||||||
final int col1 = o1.getColumn(colIndex);
|
|
||||||
final int col2 = o2.getColumn(colIndex);
|
|
||||||
|
|
||||||
if (col1 > col2) {
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
if (col1 < col2) {
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -60,8 +60,7 @@ public class FixedOrderComparatorTest extends AbstractComparatorTest<String> {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Comparator<String> makeObject() {
|
public Comparator<String> makeObject() {
|
||||||
final FixedOrderComparator<String> comparator = new FixedOrderComparator<>(topCities);
|
return new FixedOrderComparator<>(topCities);
|
||||||
return comparator;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -141,9 +140,9 @@ public class FixedOrderComparatorTest extends AbstractComparatorTest<String> {
|
|||||||
@Test
|
@Test
|
||||||
public void testLock() {
|
public void testLock() {
|
||||||
final FixedOrderComparator<String> comparator = new FixedOrderComparator<>(topCities);
|
final FixedOrderComparator<String> comparator = new FixedOrderComparator<>(topCities);
|
||||||
assertEquals(false, comparator.isLocked());
|
assertFalse(comparator.isLocked());
|
||||||
comparator.compare("New York", "Tokyo");
|
comparator.compare("New York", "Tokyo");
|
||||||
assertEquals(true, comparator.isLocked());
|
assertTrue(comparator.isLocked());
|
||||||
try {
|
try {
|
||||||
comparator.add("Minneapolis");
|
comparator.add("Minneapolis");
|
||||||
fail("Should have thrown an UnsupportedOperationException");
|
fail("Should have thrown an UnsupportedOperationException");
|
||||||
@ -225,9 +224,10 @@ public class FixedOrderComparatorTest extends AbstractComparatorTest<String> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// testShuffle
|
// testShuffle
|
||||||
for (int i = 0; i < keys.length && !isInNewOrder; i++) {
|
for (int i = 0; i < keys.length; i++) {
|
||||||
if ( !orderedObjects[i].equals(keys[i])) {
|
if (!orderedObjects[i].equals(keys[i])) {
|
||||||
isInNewOrder = true;
|
isInNewOrder = true;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -240,5 +240,4 @@ public class FixedOrderComparatorTest extends AbstractComparatorTest<String> {
|
|||||||
assertEquals(orderedObjects[i], keys[i]);
|
assertEquals(orderedObjects[i], keys[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -44,11 +44,11 @@ public abstract class AbstractPredicateTest {
|
|||||||
*/
|
*/
|
||||||
protected abstract Predicate<?> generatePredicate();
|
protected abstract Predicate<?> generatePredicate();
|
||||||
|
|
||||||
protected <T> void assertFalse(final Predicate<T> predicate, final T testObject) {
|
protected <T> void assertPredicateFalse(final Predicate<T> predicate, final T testObject) {
|
||||||
Assert.assertFalse(predicate.evaluate(testObject));
|
Assert.assertFalse(predicate.evaluate(testObject));
|
||||||
}
|
}
|
||||||
|
|
||||||
protected <T> void assertTrue(final Predicate<T> predicate, final T testObject) {
|
protected <T> void assertPredicateTrue(final Predicate<T> predicate, final T testObject) {
|
||||||
Assert.assertTrue(predicate.evaluate(testObject));
|
Assert.assertTrue(predicate.evaluate(testObject));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -36,45 +36,45 @@ public class ComparatorPredicateTest extends AbstractPredicateTest {
|
|||||||
public void compareEquals() {
|
public void compareEquals() {
|
||||||
final Integer value = Integer.valueOf(10);
|
final Integer value = Integer.valueOf(10);
|
||||||
final Predicate<Integer> p = comparatorPredicate(value, new TestComparator<Integer>());
|
final Predicate<Integer> p = comparatorPredicate(value, new TestComparator<Integer>());
|
||||||
assertFalse(p, Integer.valueOf(value.intValue() - 1));
|
assertPredicateFalse(p, Integer.valueOf(value.intValue() - 1));
|
||||||
assertTrue(p, Integer.valueOf(value.intValue()));
|
assertPredicateTrue(p, Integer.valueOf(value.intValue()));
|
||||||
assertFalse(p, Integer.valueOf(value.intValue() + 1));
|
assertPredicateFalse(p, Integer.valueOf(value.intValue() + 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void compareGreater() {
|
public void compareGreater() {
|
||||||
final Integer value = Integer.valueOf(10);
|
final Integer value = Integer.valueOf(10);
|
||||||
final Predicate<Integer> p = comparatorPredicate(value, new TestComparator<Integer>(), Criterion.GREATER);
|
final Predicate<Integer> p = comparatorPredicate(value, new TestComparator<Integer>(), Criterion.GREATER);
|
||||||
assertTrue(p, Integer.valueOf(value.intValue() - 1));
|
assertPredicateTrue(p, Integer.valueOf(value.intValue() - 1));
|
||||||
assertFalse(p, Integer.valueOf(value.intValue()));
|
assertPredicateFalse(p, Integer.valueOf(value.intValue()));
|
||||||
assertFalse(p, Integer.valueOf(value.intValue() + 1));
|
assertPredicateFalse(p, Integer.valueOf(value.intValue() + 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void compareLess() {
|
public void compareLess() {
|
||||||
final Integer value = Integer.valueOf(10);
|
final Integer value = Integer.valueOf(10);
|
||||||
final Predicate<Integer> p = comparatorPredicate(value, new TestComparator<Integer>(), Criterion.LESS);
|
final Predicate<Integer> p = comparatorPredicate(value, new TestComparator<Integer>(), Criterion.LESS);
|
||||||
assertFalse(p, Integer.valueOf(value.intValue() - 1));
|
assertPredicateFalse(p, Integer.valueOf(value.intValue() - 1));
|
||||||
assertFalse(p, Integer.valueOf(value.intValue()));
|
assertPredicateFalse(p, Integer.valueOf(value.intValue()));
|
||||||
assertTrue(p, Integer.valueOf(value.intValue() + 1));
|
assertPredicateTrue(p, Integer.valueOf(value.intValue() + 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void compareGreaterOrEqual() {
|
public void compareGreaterOrEqual() {
|
||||||
final Integer value = Integer.valueOf(10);
|
final Integer value = Integer.valueOf(10);
|
||||||
final Predicate<Integer> p = comparatorPredicate(value, new TestComparator<Integer>(), Criterion.GREATER_OR_EQUAL);
|
final Predicate<Integer> p = comparatorPredicate(value, new TestComparator<Integer>(), Criterion.GREATER_OR_EQUAL);
|
||||||
assertTrue(p, Integer.valueOf(value.intValue() - 1));
|
assertPredicateTrue(p, Integer.valueOf(value.intValue() - 1));
|
||||||
assertTrue(p, Integer.valueOf(value.intValue()));
|
assertPredicateTrue(p, Integer.valueOf(value.intValue()));
|
||||||
assertFalse(p, Integer.valueOf(value.intValue() + 1));
|
assertPredicateFalse(p, Integer.valueOf(value.intValue() + 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void compareLessOrEqual() {
|
public void compareLessOrEqual() {
|
||||||
final Integer value = Integer.valueOf(10);
|
final Integer value = Integer.valueOf(10);
|
||||||
final Predicate<Integer> p = comparatorPredicate(value, new TestComparator<Integer>(), Criterion.LESS_OR_EQUAL);
|
final Predicate<Integer> p = comparatorPredicate(value, new TestComparator<Integer>(), Criterion.LESS_OR_EQUAL);
|
||||||
assertFalse(p, Integer.valueOf(value.intValue() - 1));
|
assertPredicateFalse(p, Integer.valueOf(value.intValue() - 1));
|
||||||
assertTrue(p, Integer.valueOf(value.intValue()));
|
assertPredicateTrue(p, Integer.valueOf(value.intValue()));
|
||||||
assertTrue(p, Integer.valueOf(value.intValue() + 1));
|
assertPredicateTrue(p, Integer.valueOf(value.intValue() + 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -41,15 +41,15 @@ public class EqualPredicateTest extends AbstractPredicateTest {
|
|||||||
@Test
|
@Test
|
||||||
public void objectFactoryUsesEqualsForTest() throws Exception {
|
public void objectFactoryUsesEqualsForTest() throws Exception {
|
||||||
final Predicate<EqualsTestObject> predicate = equalPredicate(FALSE_OBJECT);
|
final Predicate<EqualsTestObject> predicate = equalPredicate(FALSE_OBJECT);
|
||||||
assertFalse(predicate, FALSE_OBJECT);
|
assertPredicateFalse(predicate, FALSE_OBJECT);
|
||||||
assertTrue(equalPredicate(TRUE_OBJECT), TRUE_OBJECT);
|
assertPredicateTrue(equalPredicate(TRUE_OBJECT), TRUE_OBJECT);
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("boxing")
|
@SuppressWarnings("boxing")
|
||||||
@Test
|
@Test
|
||||||
public void testPredicateTypeCanBeSuperClassOfObject() throws Exception {
|
public void testPredicateTypeCanBeSuperClassOfObject() throws Exception {
|
||||||
final Predicate<Number> predicate = equalPredicate((Number) 4);
|
final Predicate<Number> predicate = equalPredicate((Number) 4);
|
||||||
assertTrue(predicate, 4);
|
assertPredicateTrue(predicate, 4);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class EqualsTestObject {
|
public static class EqualsTestObject {
|
||||||
|
@ -26,13 +26,13 @@ public class NullPredicateTest extends AbstractPredicateTest {
|
|||||||
@Test
|
@Test
|
||||||
public void testNullPredicate() {
|
public void testNullPredicate() {
|
||||||
assertSame(NullPredicate.nullPredicate(), NullPredicate.nullPredicate());
|
assertSame(NullPredicate.nullPredicate(), NullPredicate.nullPredicate());
|
||||||
assertTrue(nullPredicate(), null);
|
assertPredicateTrue(nullPredicate(), null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void ensurePredicateCanBeTypedWithoutWarning() throws Exception {
|
public void ensurePredicateCanBeTypedWithoutWarning() throws Exception {
|
||||||
final Predicate<String> predicate = NullPredicate.nullPredicate();
|
final Predicate<String> predicate = NullPredicate.nullPredicate();
|
||||||
assertFalse(predicate, cString);
|
assertPredicateFalse(predicate, cString);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
Loading…
x
Reference in New Issue
Block a user