コード例 #1
0
 @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));
 }
コード例 #2
0
 @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));
 }
コード例 #3
0
 @Test
 public void anySatisfyWith() {
   Assert.assertFalse(
       SingletonListTest.newWith(1).anySatisfyWith(Predicates2.instanceOf(), String.class));
   Assert.assertTrue(
       SingletonListTest.newWith(1).anySatisfyWith(Predicates2.instanceOf(), Integer.class));
 }
コード例 #4
0
 @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);
 }
コード例 #5
0
 @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);
   }
 }
コード例 #6
0
 @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()));
 }
コード例 #7
0
 @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");
 }
コード例 #8
0
 @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));
 }
コード例 #9
0
 @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()));
 }
コード例 #10
0
 @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());
 }
コード例 #11
0
 @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);
 }
コード例 #12
0
 @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);
 }
コード例 #13
0
 @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);
 }
コード例 #14
0
 @Test
 public void removeIfWith() {
   MutableList<Integer> objects = SingletonListTest.newWith(1);
   Verify.assertThrows(
       UnsupportedOperationException.class,
       () -> objects.removeIfWith(Predicates2.isNull(), null));
 }
コード例 #15
0
 @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);
 }
コード例 #16
0
 @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);
 }
コード例 #17
0
 @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());
 }
コード例 #18
0
 @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);
 }
コード例 #19
0
 @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);
 }
コード例 #20
0
 @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);
 }
コード例 #21
0
 @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);
 }
コード例 #22
0
 @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);
   }
 }
コード例 #23
0
 @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);
 }
コード例 #24
0
 @Test
 public void toSet() {
   MutableList<Integer> integers = SingletonListTest.newWith(1);
   MutableSet<Integer> set = integers.toSet();
   Verify.assertContainsAll(set, 1);
 }
コード例 #25
0
 @Test
 public void removeAll() {
   MutableList<Integer> objects = SingletonListTest.newWith(1);
   Verify.assertThrows(
       UnsupportedOperationException.class, () -> objects.removeAll(Lists.fixedSize.of(1, 2)));
 }
コード例 #26
0
 @Test
 public void injectInto() {
   MutableList<Integer> objects = SingletonListTest.newWith(1);
   Integer result = objects.injectInto(1, AddFunction.INTEGER);
   Assert.assertEquals(Integer.valueOf(2), result);
 }
コード例 #27
0
 @Test
 public void clear() {
   MutableList<Integer> objects = SingletonListTest.newWith(1);
   Verify.assertThrows(UnsupportedOperationException.class, objects::clear);
 }
コード例 #28
0
 @Test
 public void getLast() {
   Assert.assertEquals(Integer.valueOf(1), SingletonListTest.newWith(1).getLast());
 }
コード例 #29
0
 @Test
 public void retainAll() {
   MutableList<Integer> objects = SingletonListTest.newWith(1);
   Verify.assertThrows(
       UnsupportedOperationException.class, () -> objects.retainAll(SingletonListTest.newWith(2)));
 }
コード例 #30
0
 @Test
 public void isEmpty() {
   Verify.assertNotEmpty(SingletonListTest.newWith(1));
   Assert.assertTrue(SingletonListTest.newWith(1).notEmpty());
 }