@Test public void copySet() { Verify.assertInstanceOf(ImmutableSet.class, Sets.immutable.ofAll(Sets.fixedSize.of())); MutableSet<Integer> set = Sets.fixedSize.of(1); ImmutableSet<Integer> immutableSet = set.toImmutable(); Verify.assertInstanceOf(ImmutableSet.class, Sets.immutable.ofAll(set)); Verify.assertInstanceOf( ImmutableSet.class, Sets.immutable.ofAll(UnifiedSet.newSetWith(1, 2, 3, 4, 5))); Assert.assertSame(Sets.immutable.ofAll(immutableSet.castToSet()), immutableSet); }
@Test public void fixedSize() { FixedSizeSetFactory setFactory = Sets.fixedSize; Assert.assertEquals(UnifiedSet.newSet(), setFactory.of()); Verify.assertInstanceOf(FixedSizeSet.class, setFactory.of()); Assert.assertEquals(UnifiedSet.newSetWith(1), setFactory.of(1)); Verify.assertInstanceOf(FixedSizeSet.class, setFactory.of(1)); Assert.assertEquals(UnifiedSet.newSetWith(1, 2), setFactory.of(1, 2)); Verify.assertInstanceOf(FixedSizeSet.class, setFactory.of(1, 2)); Assert.assertEquals(UnifiedSet.newSetWith(1, 2, 3), setFactory.of(1, 2, 3)); Verify.assertInstanceOf(FixedSizeSet.class, setFactory.of(1, 2, 3)); Assert.assertEquals(UnifiedSet.newSetWith(1, 2, 3, 4), setFactory.of(1, 2, 3, 4)); Verify.assertInstanceOf(FixedSizeSet.class, setFactory.of(1, 2, 3, 4)); }
@Override @Test public void testClone() { MutableList<Integer> integers = this.newWith(1, 2, 3, 4); MutableList<Integer> clone = integers.clone(); Assert.assertEquals(integers, clone); Verify.assertInstanceOf(MultiReaderFastList.class, clone); }
@Test public void without() { MutableList<Integer> list = new SingletonList<>(2); Assert.assertSame(list, list.without(9)); list = list.without(2); Verify.assertListsEqual(Lists.mutable.of(), list); Verify.assertInstanceOf(EmptyList.class, list); }
@Override @Test public void testClone() { MutableSortedMap<Integer, String> map = this.newMapWithKeysValues(1, "1", 2, "2", 3, "3", 4, "4"); Assert.assertSame(map, map.clone()); Verify.assertInstanceOf(UnmodifiableTreeMap.class, map.clone()); }
@Override @Test public void subMap() { MutableSortedMap<Integer, String> map = this.newMapWithKeysValues(1, "1", 2, "2", 3, "3", 4, "4"); Verify.assertInstanceOf(UnmodifiableTreeMap.class, map.subMap(1, 3)); this.checkMutability(map.subMap(1, 3)); }
@Test public void sortThisOnListWithLessThan10Elements() { MutableList<Integer> integers = this.newWith(2, 3, 4, 1, 7, 9, 6, 8, 5); Verify.assertStartsWith(integers.sortThis(), 1, 2, 3, 4, 5, 6, 7, 8, 9); MutableList<Integer> integers2 = this.newWith(1, 2, 3, 4, 5, 6, 7, 8, 9); Verify.assertStartsWith( integers2.sortThis(Collections.reverseOrder()), 9, 8, 7, 6, 5, 4, 3, 2, 1); MutableList<Integer> integers3 = this.newWith(1, 2, 3, 4, 5, 6, 7, 8, 9); Verify.assertStartsWith(integers3.sortThis(), 1, 2, 3, 4, 5, 6, 7, 8, 9); Verify.assertInstanceOf(MultiReaderFastList.class, integers3.sortThis()); }
@Test public void mutables() { MutableSetFactory setFactory = Sets.mutable; Assert.assertEquals(UnifiedSet.newSet(), setFactory.of()); Verify.assertInstanceOf(MutableSet.class, setFactory.of()); Assert.assertEquals(UnifiedSet.newSetWith(1), setFactory.of(1)); Verify.assertInstanceOf(MutableSet.class, setFactory.of(1)); Assert.assertEquals(UnifiedSet.newSetWith(1, 2), setFactory.of(1, 2)); Verify.assertInstanceOf(MutableSet.class, setFactory.of(1, 2)); Assert.assertEquals(UnifiedSet.newSetWith(1, 2, 3), setFactory.of(1, 2, 3)); Verify.assertInstanceOf(MutableSet.class, setFactory.of(1, 2, 3)); Assert.assertEquals(UnifiedSet.newSetWith(1, 2, 3, 4), setFactory.of(1, 2, 3, 4)); Verify.assertInstanceOf(MutableSet.class, setFactory.of(1, 2, 3, 4)); Assert.assertEquals(UnifiedSet.newSetWith(1, 2, 3, 4, 5), setFactory.of(1, 2, 3, 4, 5)); Verify.assertInstanceOf(MutableSet.class, setFactory.of(1, 2, 3, 4, 5)); Assert.assertEquals( UnifiedSet.newSetWith(1, 2, 3, 4, 5), setFactory.ofAll(UnifiedSet.newSetWith(1, 2, 3, 4, 5))); Verify.assertInstanceOf( MutableSet.class, setFactory.ofAll(UnifiedSet.newSetWith(1, 2, 3, 4, 5))); }
@Override @Test public void newEmpty() { Verify.assertInstanceOf(MultiReaderFastList.class, MultiReaderFastList.newList().newEmpty()); Verify.assertEmpty(MultiReaderFastList.<Integer>newListWith(null, null).newEmpty()); }
@Override public void reject() { ImmutableMap<Integer, String> map = this.classUnderTest(); ImmutableMap<Integer, String> actual = map.reject((ignored1, ignored2) -> false); Verify.assertInstanceOf(ImmutableEmptyMapWithHashingStrategy.class, actual); }
@Test public void testClone() { MutableList<String> clone = this.list.clone(); Verify.assertEqualsAndHashCode(this.list, clone); Verify.assertInstanceOf(SingletonList.class, clone); }
@Test public void asSynchronized() { Verify.assertInstanceOf(SynchronizedMutableList.class, this.list.asSynchronized()); }