@Override public void equalsAndHashCode() { super.equalsAndHashCode(); Verify.assertInstanceOf( UnmodifiableSortedBag.class, SerializeTestHelper.serializeDeserialize( this.newWith(Comparators.reverseNaturalOrder(), 1, 2, 3))); Verify.assertInstanceOf( UnmodifiableSortedBag.class, SerializeTestHelper.serializeDeserialize(this.newWith(1, 2, 3))); }
@Test public void testBAOSSize() { MutableList<Integer> mutableArrayList = ArrayListAdapter.newList(); ByteArrayOutputStream stream1 = SerializeTestHelper.getByteArrayOutputStream(mutableArrayList); LOGGER.info("ArrayListAdapter size: {}", stream1.size()); LOGGER.info("{}", stream1); Assert.assertTrue(stream1.size() > 0); List<Integer> arrayList = new ArrayList<>(); ByteArrayOutputStream stream2 = SerializeTestHelper.getByteArrayOutputStream(arrayList); LOGGER.info("ArrayList size: {}", stream2.size()); LOGGER.info("{}", stream2); Assert.assertTrue(stream2.size() > 0); }
@Test public void serialization() { ImmutableSortedMap<Integer, String> map = this.classUnderTest(); ImmutableSortedMap<Integer, String> deserialized = SerializeTestHelper.serializeDeserialize(map); Assert.assertSame(ImmutableEmptySortedMap.INSTANCE, map); Assert.assertSame(map, deserialized); ImmutableSortedMap<Integer, String> revMap = this.classUnderTest(Comparators.<Integer>reverseNaturalOrder()); ImmutableSortedMap<Integer, String> revDeserialized = SerializeTestHelper.serializeDeserialize(revMap); Verify.assertInstanceOf(ImmutableSortedMap.class, revDeserialized); Assert.assertNotNull(revDeserialized.comparator()); }
@Test public void serialization() { Multimap<Integer, String> original = this.newMultimapWithKeysValues(1, "1", 2, "2", 3, "3"); Multimap<Integer, String> copy = SerializeTestHelper.serializeDeserialize(original); Verify.assertSize(3, copy); Verify.assertEqualsAndHashCode(original, copy); }
@Test public void testEqualsAndHashCode() { Verify.assertEqualsAndHashCode(this.mutableSet, this.unmodifiableSet); Verify.assertPostSerializedEqualsAndHashCode(this.unmodifiableSet); Verify.assertInstanceOf( UnmodifiableMutableSet.class, SerializeTestHelper.serializeDeserialize(this.unmodifiableSet)); }
@Test public void valuesCollection_PostSerializedEquality_chainedMap() { MutableMap<Integer, Integer> map = this.mapWithCollisionsOfSize(2); Collection<Integer> values = map.values(); Collection<Integer> revived = SerializeTestHelper.serializeDeserialize(values); Assert.assertNotNull(revived); Verify.assertSize(values.size(), revived); Assert.assertTrue(revived.containsAll(values)); }
@Test public void valuesCollection_PostSerializedEquality() { MutableMap<Integer, Integer> map = this.newMapWithKeysValues(1, 1, 2, 2, 3, 3); Collection<Integer> values = map.values(); // This test is not using Verify.assertPostSerializedEqualsAndHashCode b/c the deserialized form // of the values view is a FastList, which will not be equals to the original view (a // Collection). Collection<Integer> revived = SerializeTestHelper.serializeDeserialize(values); Assert.assertNotNull(revived); Verify.assertSize(values.size(), revived); Assert.assertTrue(revived.containsAll(values)); }
@Test public void valuesCollection_PostSerializedEquality_chainedMapWithEmptySlot() { MutableMap<Integer, Integer> map = this.mapWithCollisionsOfSize(4); map.put(42, 42); // add non-colliding key Collection<Integer> values = map.values(); // This test is not using Verify.assertPostSerializedEqualsAndHashCode b/c the deserialized form // of the values view is a FastList, which will not be equals to the orginal view (a // Collection). Collection<Integer> revived = SerializeTestHelper.serializeDeserialize(values); Assert.assertNotNull(revived); Verify.assertSize(values.size(), revived); Assert.assertTrue(revived.containsAll(values)); }
private static void runUnifiedSetSerialize(int shift) { MultiReaderUnifiedSet<CollidingInt> set = MultiReaderUnifiedSet.newSet(); int size = 100000; for (int i = 0; i < size; i++) { set.add(new CollidingInt(i, shift)); } set.add(null); set = SerializeTestHelper.serializeDeserialize(set); Verify.assertSize(size + 1, set); for (int i = 0; i < size; i++) { Verify.assertContains(new CollidingInt(i, shift), set); } Verify.assertContains(null, set); }
@Test public void serializable() { MutableSet<String> copyOfSet = SerializeTestHelper.serializeDeserialize(this.set); Verify.assertSetsEqual(this.set, copyOfSet); Assert.assertNotSame(this.set, copyOfSet); }