@Test public void countWith() { Assert.assertEquals( 1, SingletonListTest.newWith(1).countWith(Predicates2.instanceOf(), Integer.class)); Assert.assertEquals( 0, SingletonListTest.newWith(1).countWith(Predicates2.instanceOf(), String.class)); }
@Test public void selectWith() { Verify.assertContainsAll( SingletonListTest.newWith(1).selectWith(Predicates2.<Integer>lessThan(), 3), 1); Verify.assertEmpty( SingletonListTest.newWith(1).selectWith(Predicates2.<Integer>greaterThan(), 3)); }
@Test public void anySatisfyWith() { Assert.assertFalse( SingletonListTest.newWith(1).anySatisfyWith(Predicates2.instanceOf(), String.class)); Assert.assertTrue( SingletonListTest.newWith(1).anySatisfyWith(Predicates2.instanceOf(), Integer.class)); }
@Test public void rejectWith() { Verify.assertEmpty(SingletonListTest.newWith(1).rejectWith(Predicates2.<Integer>lessThan(), 3)); Verify.assertContainsAll( SingletonListTest.newWith(1) .rejectWith(Predicates2.<Integer>greaterThan(), 3, UnifiedSet.<Integer>newSet()), 1); }
@Test public void forLoop() { MutableList<String> list = SingletonListTest.newWith("one"); MutableList<String> upperList = SingletonListTest.newWith("ONE"); for (String each : list) { Verify.assertContains(each.toUpperCase(), upperList); } }
@Test public void collectWith() { Assert.assertEquals( FastList.newListWith(2), SingletonListTest.newWith(1).collectWith(AddFunction.INTEGER, 1)); Assert.assertEquals( FastList.newListWith(2), SingletonListTest.newWith(1) .collectWith(AddFunction.INTEGER, 1, FastList.<Integer>newList())); }
@Test public void collectIf() { Verify.assertContainsAll( SingletonListTest.newWith(1).collectIf(Integer.class::isInstance, String::valueOf), "1"); Verify.assertContainsAll( SingletonListTest.newWith(1) .collectIf(Integer.class::isInstance, String::valueOf, FastList.<String>newList()), "1"); }
@Test public void detectWithIfNone() { Function0<Integer> function = new PassThruFunction0<>(6); Assert.assertEquals( Integer.valueOf(1), SingletonListTest.newWith(1).detectWithIfNone(Object::equals, 1, function)); Assert.assertEquals( Integer.valueOf(6), SingletonListTest.newWith(1).detectWithIfNone(Object::equals, 6, function)); }
@Test public void flatCollect() { Function<Integer, MutableSet<String>> function = object -> UnifiedSet.newSetWith(object.toString()); Verify.assertListsEqual( FastList.newListWith("1"), SingletonListTest.newWith(1).flatCollect(function)); Verify.assertSetsEqual( UnifiedSet.newSetWith("1"), SingletonListTest.newWith(1).flatCollect(function, UnifiedSet.<String>newSet())); }
@Test public void subList() { MutableList<String> list = SingletonListTest.newWith("one"); MutableList<String> subList = list.subList(0, 1); MutableList<String> upperList = SingletonListTest.newWith("ONE"); for (String each : subList) { Verify.assertContains(each.toUpperCase(), upperList); } Assert.assertEquals("one", subList.getFirst()); Assert.assertEquals("one", subList.getLast()); }
@Test public void forEachWithIndex() { MutableList<Integer> result = Lists.mutable.of(); MutableList<Integer> collection = SingletonListTest.newWith(1); collection.forEachWithIndex((object, index) -> result.add(object + index)); Verify.assertContainsAll(result, 1); }
@Test public void forEachWith() { MutableList<Integer> result = Lists.mutable.of(); MutableList<Integer> collection = SingletonListTest.newWith(1); collection.forEachWith((argument1, argument2) -> result.add(argument1 + argument2), 0); Assert.assertEquals(FastList.newListWith(1), result); }
@Test public void tap() { MutableList<Integer> tapResult = Lists.mutable.of(); MutableList<Integer> collection = SingletonListTest.newWith(1); Assert.assertSame(collection, collection.tap(tapResult::add)); Assert.assertEquals(collection.toList(), tapResult); }
@Test public void removeIfWith() { MutableList<Integer> objects = SingletonListTest.newWith(1); Verify.assertThrows( UnsupportedOperationException.class, () -> objects.removeIfWith(Predicates2.isNull(), null)); }
@Test public void toSortedListBy() { MutableList<Integer> integers = SingletonListTest.newWith(1); MutableList<Integer> list = integers.toSortedListBy(Functions.getIntegerPassThru()); Assert.assertEquals(FastList.newListWith(1), list); Assert.assertNotSame(integers, list); }
@Test public void forEach() { MutableList<Integer> result = Lists.mutable.of(); MutableList<Integer> collection = SingletonListTest.newWith(1); collection.forEach(CollectionAddProcedure.on(result)); Assert.assertEquals(FastList.newListWith(1), result); }
@Test public void selectAndRejectWith() { MutableList<Integer> objects = SingletonListTest.newWith(1); Twin<MutableList<Integer>> result = objects.selectAndRejectWith(Object::equals, 1); Verify.assertSize(1, result.getOne()); Verify.assertEmpty(result.getTwo()); }
@Test public void toMap() { MutableList<Integer> integers = SingletonListTest.newWith(1); MutableMap<Integer, Integer> map = integers.toMap(Functions.getIntegerPassThru(), Functions.getIntegerPassThru()); Verify.assertContainsAll(map.keySet(), 1); Verify.assertContainsAll(map.values(), 1); }
@Test public void toList() { MutableList<Integer> list = SingletonListTest.newWith(1).toList(); list.add(2); list.add(3); list.add(4); Verify.assertContainsAll(list, 1, 2, 3, 4); }
@Test public void toArray() { MutableList<Integer> objects = SingletonListTest.newWith(1); Object[] array = objects.toArray(); Verify.assertSize(1, array); Integer[] array2 = objects.toArray(new Integer[1]); Verify.assertSize(1, array2); }
@Test public void injectIntoWith() { MutableList<Integer> objects = SingletonListTest.newWith(1); Integer result = objects.injectIntoWith( 1, (injectedValued, item, parameter) -> injectedValued + item + parameter, 0); Assert.assertEquals(Integer.valueOf(2), result); }
@Test public void iterator() { MutableList<Integer> objects = SingletonListTest.newWith(1); Iterator<Integer> iterator = objects.iterator(); for (int i = objects.size(); i-- > 0; ) { Integer integer = iterator.next(); Assert.assertEquals(1, integer.intValue() + i); } }
@Test public void toSortedList() { MutableList<Integer> integers = SingletonListTest.newWith(1); MutableList<Integer> list = integers.toSortedList(Collections.<Integer>reverseOrder()); Verify.assertStartsWith(list, 1); Assert.assertNotSame(integers, list); MutableList<Integer> list2 = integers.toSortedList(); Verify.assertStartsWith(list2, 1); Assert.assertNotSame(integers, list2); }
@Test public void toSet() { MutableList<Integer> integers = SingletonListTest.newWith(1); MutableSet<Integer> set = integers.toSet(); Verify.assertContainsAll(set, 1); }
@Test public void removeAll() { MutableList<Integer> objects = SingletonListTest.newWith(1); Verify.assertThrows( UnsupportedOperationException.class, () -> objects.removeAll(Lists.fixedSize.of(1, 2))); }
@Test public void injectInto() { MutableList<Integer> objects = SingletonListTest.newWith(1); Integer result = objects.injectInto(1, AddFunction.INTEGER); Assert.assertEquals(Integer.valueOf(2), result); }
@Test public void clear() { MutableList<Integer> objects = SingletonListTest.newWith(1); Verify.assertThrows(UnsupportedOperationException.class, objects::clear); }
@Test public void getLast() { Assert.assertEquals(Integer.valueOf(1), SingletonListTest.newWith(1).getLast()); }
@Test public void retainAll() { MutableList<Integer> objects = SingletonListTest.newWith(1); Verify.assertThrows( UnsupportedOperationException.class, () -> objects.retainAll(SingletonListTest.newWith(2))); }
@Test public void isEmpty() { Verify.assertNotEmpty(SingletonListTest.newWith(1)); Assert.assertTrue(SingletonListTest.newWith(1).notEmpty()); }