@Test public void rejectWith() { ImmutableCollection<Integer> integers = this.classUnderTest(); Assert.assertEquals( this.<Integer>newMutable().withAll(integers).reject(IntegerPredicates.isOdd()), integers.rejectWith(Predicates2.in(), iList(1, 3, 5, 7, 9))); }
@Test public void partition() { ImmutableCollection<Integer> integers = this.classUnderTest(); PartitionImmutableCollection<Integer> partition = integers.partition(IntegerPredicates.isOdd()); Assert.assertEquals(integers.select(IntegerPredicates.isOdd()), partition.getSelected()); Assert.assertEquals(integers.select(IntegerPredicates.isEven()), partition.getRejected()); }
@Test public void collectIf() { ImmutableCollection<Integer> integers = this.classUnderTest(); Assert.assertEquals( integers, integers.collectIf(Predicates.instanceOf(Integer.class), Functions.getIntegerPassThru())); }
@Test public void collectBoolean() { ImmutableCollection<Integer> integers = this.classUnderTest(); ImmutableBooleanCollection immutableCollection = integers.collectBoolean(PrimitiveFunctions.integerIsPositive()); Verify.assertSize(1, immutableCollection); }
@Test public void injectInto() { ImmutableCollection<Integer> integers = this.classUnderTest(); Integer result = integers.injectInto(0, AddFunction.INTEGER); Assert.assertEquals( FastList.newList(integers).injectInto(0, AddFunction.INTEGER_TO_INT), result.intValue()); }
@Test public void countWith() { ImmutableCollection<Integer> integers = this.classUnderTest(); Assert.assertEquals( integers.size(), integers.countWith(Predicates2.instanceOf(), Integer.class)); Assert.assertEquals(0, integers.countWith(Predicates2.instanceOf(), String.class)); }
@Test public void detectWith() { ImmutableCollection<Integer> integers = this.classUnderTest(); Assert.assertEquals( Integer.valueOf(1), integers.detectWith(Predicates2.equal(), Integer.valueOf(1))); Assert.assertNull( integers.detectWith(Predicates2.equal(), Integer.valueOf(integers.size() + 1))); }
@Test public void collectShort() { ImmutableCollection<Integer> integers = this.classUnderTest(); ImmutableShortCollection immutableCollection = integers.collectShort(PrimitiveFunctions.unboxIntegerToShort()); Verify.assertSize(integers.size(), immutableCollection); Assert.assertEquals(integers, immutableCollection.collect(Integer::valueOf)); }
@Test public void toArray() { ImmutableCollection<Integer> integers = this.classUnderTest(); MutableList<Integer> copy = FastList.newList(integers); Assert.assertArrayEquals(integers.toArray(), copy.toArray()); Assert.assertArrayEquals( integers.toArray(new Integer[integers.size()]), copy.toArray(new Integer[integers.size()])); }
@Test public void toSortedList() { ImmutableCollection<Integer> integers = this.classUnderTest(); MutableList<Integer> copy = FastList.newList(integers); MutableList<Integer> list = integers.toSortedList(Collections.<Integer>reverseOrder()); Assert.assertEquals(copy.sortThis(Collections.<Integer>reverseOrder()), list); MutableList<Integer> list2 = integers.toSortedList(); Assert.assertEquals(copy.sortThis(), list2); }
@Test public void toSortedSetWithComparator() { ImmutableCollection<Integer> integers = this.classUnderTest(); MutableSortedSet<Integer> set = integers.toSortedSet(Comparators.<Integer>reverseNaturalOrder()); Assert.assertEquals(integers.toSet(), set); Assert.assertEquals( integers.toSortedList(Comparators.<Integer>reverseNaturalOrder()), set.toList()); }
@Test public void detectWithIfNone() { ImmutableCollection<Integer> integers = this.classUnderTest(); Integer sum = Integer.valueOf(integers.size() + 1); Function0<Integer> function = new PassThruFunction0<Integer>(sum); Assert.assertEquals( Integer.valueOf(1), integers.detectWithIfNone(Predicates2.equal(), Integer.valueOf(1), function)); Assert.assertEquals(sum, integers.detectWithIfNone(Predicates2.equal(), sum, function)); }
@Test public void collectLong() { ImmutableCollection<Integer> integers = this.classUnderTest(); ImmutableLongCollection immutableCollection = integers.collectLong(PrimitiveFunctions.unboxIntegerToLong()); Verify.assertSize(integers.size(), immutableCollection); Assert.assertEquals( integers, immutableCollection.collect(longParameter -> Integer.valueOf((int) longParameter))); }
@Test public void collectWith() { ImmutableCollection<Integer> integers = this.classUnderTest(); ImmutableCollection<String> expected = integers.collect(Functions.chain(Functions.getToString(), StringFunctions.append("!"))); ImmutableCollection<String> actual = integers.collectWith((argument1, argument2) -> argument1 + argument2, "!"); Assert.assertEquals(expected, actual); }
@Test public void collect_target() { ImmutableCollection<Integer> integers = this.classUnderTest(); MutableCollection<String> strings = this.<String>newMutable(); integers.forEach( (Procedure<Integer>) each -> { strings.add(each.toString()); }); MutableCollection<String> target = this.<String>newMutable(); MutableCollection<String> actual = integers.collect(Functions.getToString(), target); Assert.assertEquals(strings, actual); Assert.assertSame(target, actual); }
@Test public void iterator() { ImmutableCollection<Integer> integers = this.classUnderTest(); Iterator<Integer> iterator = integers.iterator(); for (int i = 0; iterator.hasNext(); i++) { Integer integer = iterator.next(); Assert.assertEquals(i + 1, integer.intValue()); } Verify.assertThrows( NoSuchElementException.class, (Runnable) () -> { iterator.next(); }); }
@Test public void collectWith_target() { ImmutableCollection<Integer> integers = this.classUnderTest(); MutableCollection<String> expected = this.<String>newMutable() .with("?") .withAll( integers.collect( Functions.chain(Functions.getToString(), StringFunctions.append("!")))); MutableCollection<String> targetCollection = this.<String>newMutable().with("?"); MutableCollection<String> actual = integers.collectWith( (argument1, argument2) -> argument1 + argument2, "!", targetCollection); Assert.assertEquals(expected, actual); Assert.assertSame(targetCollection, actual); }
@Test public void toSortedSet() { ImmutableCollection<Integer> integers = this.classUnderTest(); MutableSortedSet<Integer> set = integers.toSortedSet(); Verify.assertListsEqual(integers.toSortedList(), set.toList()); }
@Test public void selectInstancesOf() { ImmutableCollection<Integer> integers = this.classUnderTest(); ImmutableCollection<Integer> result = integers.selectInstancesOf(Integer.class); Assert.assertEquals(integers, result); }
@Test public void reject() { ImmutableCollection<Integer> integers = this.classUnderTest(); Verify.assertIterableEmpty(integers.reject(Predicates.lessThan(integers.size() + 1))); Assert.assertEquals(integers, integers.reject(Predicates.greaterThan(integers.size()))); }
@Test public void isEmpty() { ImmutableCollection<Integer> immutableCollection = this.classUnderTest(); Assert.assertFalse(immutableCollection.isEmpty()); Assert.assertTrue(immutableCollection.notEmpty()); }
@Test public void getLast() { ImmutableCollection<Integer> integers = this.classUnderTest(); Assert.assertEquals(Integer.valueOf(integers.size()), integers.getLast()); }
@Test public void collect() { ImmutableCollection<Integer> integers = this.classUnderTest(); Assert.assertEquals(integers, integers.collect(Functions.getIntegerPassThru())); }
@Test public void toSortedSetBy() { ImmutableCollection<Integer> integers = this.classUnderTest(); MutableSortedSet<Integer> set = integers.toSortedSetBy(Functions.getToString()); Verify.assertSortedSetsEqual(TreeSortedSet.newSet(integers), set); }
@Test public void anySatisfyWith() { ImmutableCollection<Integer> integers = this.classUnderTest(); Assert.assertFalse(integers.anySatisfyWith(Predicates2.instanceOf(), String.class)); Assert.assertTrue(integers.anySatisfyWith(Predicates2.instanceOf(), Integer.class)); }
@Test public void allSatisfy() { ImmutableCollection<Integer> integers = this.classUnderTest(); Assert.assertTrue(integers.allSatisfy(Predicates.instanceOf(Integer.class))); Assert.assertFalse(integers.allSatisfy(Predicates.equal(0))); }
@Test public void noneSatisfy() { ImmutableCollection<Integer> integers = this.classUnderTest(); Assert.assertTrue(integers.noneSatisfy(Predicates.instanceOf(String.class))); Assert.assertFalse(integers.noneSatisfy(Predicates.equal(1))); }