@Override @Test public void noneSatisfy() { MutableList<Integer> list = this.getIntegerList(); Assert.assertTrue(Predicates.<Integer>noneSatisfy(String.class::isInstance).accept(list)); Assert.assertFalse(Predicates.noneSatisfy(Predicates.greaterThan(0)).accept(list)); }
@Override @Test public void reject() { Verify.assertContainsAll(this.newWith(1, 2, 3, 4).reject(Predicates.lessThan(3)), 3, 4); Verify.assertContainsAll( this.newWith(1, 2, 3, 4).reject(Predicates.lessThan(3), UnifiedSet.newSet()), 3, 4); }
@Override @Test public void allSatisfy() { MutableList<Integer> list = this.getIntegerList(); Assert.assertTrue(Predicates.<Integer>allSatisfy(Integer.class::isInstance).accept(list)); Assert.assertFalse(Predicates.allSatisfy(Predicates.greaterThan(2)).accept(list)); }
@Test public void reject() { Verify.assertEmpty(SingletonListTest.newWith(1).reject(Predicates.lessThan(3))); Verify.assertContainsAll( SingletonListTest.newWith(1) .reject(Predicates.greaterThan(3), UnifiedSet.<Integer>newSet()), 1); }
@Test public void removeUsingPredicate() { MutableList<Integer> objects = MultiReaderFastList.newListWith(1, 2, 3, null); Assert.assertTrue(objects.removeIf(Predicates.isNull())); Verify.assertSize(3, objects); Verify.assertContainsAll(objects, 1, 2, 3); }
@Override @Test public void removeIf() { MutableList<Integer> objects = MultiReaderFastList.newListWith(1, 2, 3, null); Assert.assertTrue(objects.removeIf(Predicates.cast(each -> each == null))); Verify.assertSize(3, objects); Verify.assertContainsAll(objects, 1, 2, 3); }
@Test public void into() { int sum = Interval.oneTo(5) .select(Predicates.lessThan(5)) .into(FastList.<Integer>newList()) .injectInto(0, AddFunction.INTEGER_TO_INT); Assert.assertEquals(10, sum); }
@Override public void noneSatisfy() { Assert.assertTrue(this.classUnderTest().noneSatisfy(Predicates.lessThan(0))); Assert.assertTrue(this.classUnderTest().noneSatisfy(Predicates.greaterThanOrEqualTo(0))); }
@Override public void anySatisfy() { Assert.assertFalse(this.classUnderTest().anySatisfy(Predicates.lessThan(0))); Assert.assertFalse(this.classUnderTest().anySatisfy(Predicates.greaterThanOrEqualTo(0))); }
@Override @Test default void RichIterable_detect() { assertThat(this.newWith(3, 2, 1).detect(Predicates.greaterThan(0)), isOneOf(3, 2, 1)); assertThat(this.newWith(3, 2, 1).detect(Predicates.greaterThan(1)), isOneOf(3, 2)); assertThat(this.newWith(3, 2, 1).detect(Predicates.greaterThan(2)), is(3)); assertThat(this.newWith(3, 2, 1).detect(Predicates.greaterThan(3)), nullValue()); assertThat(this.newWith(3, 2, 1).detect(Predicates.lessThan(1)), nullValue()); assertThat(this.newWith(3, 2, 1).detect(Predicates.lessThan(2)), is(1)); assertThat(this.newWith(3, 2, 1).detect(Predicates.lessThan(3)), isOneOf(2, 1)); assertThat(this.newWith(3, 2, 1).detect(Predicates.lessThan(4)), isOneOf(3, 2, 1)); assertThat(this.newWith(3, 2, 1).detectWith(Predicates2.greaterThan(), 0), isOneOf(3, 2, 1)); assertThat(this.newWith(3, 2, 1).detectWith(Predicates2.greaterThan(), 1), isOneOf(3, 2)); assertThat(this.newWith(3, 2, 1).detectWith(Predicates2.greaterThan(), 2), is(3)); assertThat(this.newWith(3, 2, 1).detectWith(Predicates2.greaterThan(), 3), nullValue()); assertThat(this.newWith(3, 2, 1).detectWith(Predicates2.lessThan(), 1), nullValue()); assertThat(this.newWith(3, 2, 1).detectWith(Predicates2.lessThan(), 2), is(1)); assertThat(this.newWith(3, 2, 1).detectWith(Predicates2.lessThan(), 3), isOneOf(2, 1)); assertThat(this.newWith(3, 2, 1).detectWith(Predicates2.lessThan(), 4), isOneOf(3, 2, 1)); assertThat( this.newWith(3, 2, 1).detectIfNone(Predicates.greaterThan(0), () -> 4), isOneOf(3, 2, 1)); assertThat( this.newWith(3, 2, 1).detectIfNone(Predicates.greaterThan(1), () -> 4), isOneOf(3, 2)); assertThat(this.newWith(3, 2, 1).detectIfNone(Predicates.greaterThan(2), () -> 4), is(3)); assertThat(this.newWith(3, 2, 1).detectIfNone(Predicates.greaterThan(3), () -> 4), is(4)); assertThat(this.newWith(3, 2, 1).detectIfNone(Predicates.lessThan(1), () -> 4), is(4)); assertThat(this.newWith(3, 2, 1).detectIfNone(Predicates.lessThan(2), () -> 4), is(1)); assertThat(this.newWith(3, 2, 1).detectIfNone(Predicates.lessThan(3), () -> 4), isOneOf(2, 1)); assertThat( this.newWith(3, 2, 1).detectIfNone(Predicates.lessThan(4), () -> 4), isOneOf(3, 2, 1)); assertThat( this.newWith(3, 2, 1).detectWithIfNone(Predicates2.greaterThan(), 0, () -> 4), isOneOf(3, 2, 1)); assertThat( this.newWith(3, 2, 1).detectWithIfNone(Predicates2.greaterThan(), 1, () -> 4), isOneOf(3, 2)); assertThat( this.newWith(3, 2, 1).detectWithIfNone(Predicates2.greaterThan(), 2, () -> 4), is(3)); assertThat( this.newWith(3, 2, 1).detectWithIfNone(Predicates2.greaterThan(), 3, () -> 4), is(4)); assertThat(this.newWith(3, 2, 1).detectWithIfNone(Predicates2.lessThan(), 1, () -> 4), is(4)); assertThat(this.newWith(3, 2, 1).detectWithIfNone(Predicates2.lessThan(), 2, () -> 4), is(1)); assertThat( this.newWith(3, 2, 1).detectWithIfNone(Predicates2.lessThan(), 3, () -> 4), isOneOf(2, 1)); assertThat( this.newWith(3, 2, 1).detectWithIfNone(Predicates2.lessThan(), 4, () -> 4), isOneOf(3, 2, 1)); }
@Test public void removeIf() { MutableList<Integer> objects = SingletonListTest.newWith(1); Verify.assertThrows( UnsupportedOperationException.class, () -> objects.removeIf(Predicates.isNull())); }
@Test public void select() { Verify.assertContainsAll(SingletonListTest.newWith(1).select(Predicates.lessThan(3)), 1); Verify.assertEmpty(SingletonListTest.newWith(1).select(Predicates.greaterThan(3))); }