mirror of
https://github.com/ebean-orm/ebean.git
synced 2026-12-01 15:37:14 +00:00
#1229 - Implement equals and hashCode on ModifyAwareMap, ModifyAwareList and ModifyAwareSet
This commit is contained in:
1 parent
db5db26fca
commit
3c7ef7d46e
6 files changed
+171
-65
No files matched your search
@@ -5,6 +5,7 @@ import java.util.Iterator;
|
|||||||
import java.util.LinkedHashSet;
|
import java.util.LinkedHashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.ListIterator;
|
import java.util.ListIterator;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Modify aware wrapper of a list.
|
* Modify aware wrapper of a list.
|
||||||
@@ -32,6 +33,19 @@ public class ModifyAwareList<E> implements List<E>, ModifyAwareOwner {
|
|||||||
return list.toString();
|
return list.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object o) {
|
||||||
|
if (this == o) return true;
|
||||||
|
if (!(o instanceof ModifyAwareList)) return false;
|
||||||
|
ModifyAwareList<?> that = (ModifyAwareList<?>) o;
|
||||||
|
return Objects.equals(list, that.list);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
return Objects.hash(list);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isMarkedDirty() {
|
public boolean isMarkedDirty() {
|
||||||
return owner.isMarkedDirty();
|
return owner.isMarkedDirty();
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package io.ebeaninternal.json;
|
|||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.LinkedHashSet;
|
import java.util.LinkedHashSet;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Objects;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -34,6 +35,19 @@ public class ModifyAwareMap<K, V> implements Map<K, V>, ModifyAwareOwner {
|
|||||||
return map.toString();
|
return map.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object o) {
|
||||||
|
if (this == o) return true;
|
||||||
|
if (!(o instanceof ModifyAwareMap)) return false;
|
||||||
|
ModifyAwareMap<?, ?> that = (ModifyAwareMap<?, ?>) o;
|
||||||
|
return Objects.equals(map, that.map);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
return Objects.hash(map);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isMarkedDirty() {
|
public boolean isMarkedDirty() {
|
||||||
return owner.isMarkedDirty();
|
return owner.isMarkedDirty();
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package io.ebeaninternal.json;
|
|||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
|
import java.util.Objects;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -51,6 +52,19 @@ public class ModifyAwareSet<E> implements Set<E>, ModifyAwareOwner {
|
|||||||
return set.toString();
|
return set.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object o) {
|
||||||
|
if (this == o) return true;
|
||||||
|
if (!(o instanceof ModifyAwareSet)) return false;
|
||||||
|
ModifyAwareSet<?> that = (ModifyAwareSet<?>) o;
|
||||||
|
return Objects.equals(set, that.set);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
return Objects.hash(set);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean add(E o) {
|
public boolean add(E o) {
|
||||||
if (set.add(o)) {
|
if (set.add(o)) {
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
package io.ebeaninternal.json;
|
package io.ebeaninternal.json;
|
||||||
|
|
||||||
|
|
||||||
import org.assertj.core.api.Assertions;
|
|
||||||
import org.junit.Assert;
|
import org.junit.Assert;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
@@ -16,6 +15,10 @@ import java.util.LinkedHashMap;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import static org.junit.Assert.assertFalse;
|
||||||
|
|
||||||
public class ModifyAwareMapTest {
|
public class ModifyAwareMapTest {
|
||||||
|
|
||||||
private ModifyAwareMap<String, String> createMap() {
|
private ModifyAwareMap<String, String> createMap() {
|
||||||
@@ -34,96 +37,96 @@ public class ModifyAwareMapTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testToString() throws Exception {
|
public void testToString() {
|
||||||
|
|
||||||
ModifyAwareMap<String, String> map = createMap();
|
ModifyAwareMap<String, String> map = createMap();
|
||||||
Assert.assertEquals(map.map.toString(), map.toString());
|
assertEquals(map.map.toString(), map.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testIsMarkedDirty() throws Exception {
|
public void testIsMarkedDirty() {
|
||||||
|
|
||||||
ModifyAwareMap<String, String> map = createMap();
|
ModifyAwareMap<String, String> map = createMap();
|
||||||
Assert.assertFalse(map.isMarkedDirty());
|
assertFalse(map.isMarkedDirty());
|
||||||
|
|
||||||
map.put("A", "change");
|
map.put("A", "change");
|
||||||
Assert.assertTrue(map.isMarkedDirty());
|
Assert.assertTrue(map.isMarkedDirty());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testMarkAsModified() throws Exception {
|
public void testMarkAsModified() {
|
||||||
|
|
||||||
ModifyAwareMap<String, String> map = createMap();
|
ModifyAwareMap<String, String> map = createMap();
|
||||||
Assert.assertFalse(map.isMarkedDirty());
|
assertFalse(map.isMarkedDirty());
|
||||||
|
|
||||||
map.markAsModified();
|
map.markAsModified();
|
||||||
Assert.assertTrue(map.isMarkedDirty());
|
Assert.assertTrue(map.isMarkedDirty());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSize() throws Exception {
|
public void testSize() {
|
||||||
|
|
||||||
ModifyAwareMap<String, String> map = createMap();
|
ModifyAwareMap<String, String> map = createMap();
|
||||||
Assert.assertEquals(5, map.size());
|
assertEquals(5, map.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testIsEmpty() throws Exception {
|
public void testIsEmpty() {
|
||||||
|
|
||||||
Assert.assertFalse(createMap().isEmpty());
|
assertFalse(createMap().isEmpty());
|
||||||
Assert.assertTrue(createEmptyMap().isEmpty());
|
Assert.assertTrue(createEmptyMap().isEmpty());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testContainsKey() throws Exception {
|
public void testContainsKey() {
|
||||||
|
|
||||||
ModifyAwareMap<String, String> map = createMap();
|
ModifyAwareMap<String, String> map = createMap();
|
||||||
Assert.assertTrue(map.containsKey("A"));
|
Assert.assertTrue(map.containsKey("A"));
|
||||||
Assert.assertFalse(map.containsKey("Z"));
|
assertFalse(map.containsKey("Z"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testContainsValue() throws Exception {
|
public void testContainsValue() {
|
||||||
ModifyAwareMap<String, String> map = createMap();
|
ModifyAwareMap<String, String> map = createMap();
|
||||||
Assert.assertTrue(map.containsValue("one"));
|
Assert.assertTrue(map.containsValue("one"));
|
||||||
Assert.assertFalse(map.containsValue("junk"));
|
assertFalse(map.containsValue("junk"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGet() throws Exception {
|
public void testGet() {
|
||||||
|
|
||||||
ModifyAwareMap<String, String> map = createMap();
|
ModifyAwareMap<String, String> map = createMap();
|
||||||
|
|
||||||
Assert.assertEquals("two", map.get("B"));
|
assertEquals("two", map.get("B"));
|
||||||
Assert.assertNull(map.get("Z"));
|
Assert.assertNull(map.get("Z"));
|
||||||
Assert.assertFalse(map.isMarkedDirty());
|
assertFalse(map.isMarkedDirty());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testPut() throws Exception {
|
public void testPut() {
|
||||||
|
|
||||||
ModifyAwareMap<String, String> map = createMap();
|
ModifyAwareMap<String, String> map = createMap();
|
||||||
Assert.assertFalse(map.isMarkedDirty());
|
assertFalse(map.isMarkedDirty());
|
||||||
|
|
||||||
map.put("A", "mod");
|
map.put("A", "mod");
|
||||||
Assert.assertTrue(map.isMarkedDirty());
|
Assert.assertTrue(map.isMarkedDirty());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testRemove() throws Exception {
|
public void testRemove() {
|
||||||
|
|
||||||
ModifyAwareMap<String, String> map = createMap();
|
ModifyAwareMap<String, String> map = createMap();
|
||||||
Assert.assertFalse(map.isMarkedDirty());
|
assertFalse(map.isMarkedDirty());
|
||||||
|
|
||||||
map.remove("A");
|
map.remove("A");
|
||||||
Assert.assertTrue(map.isMarkedDirty());
|
Assert.assertTrue(map.isMarkedDirty());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testPutAllWithEmpty() throws Exception {
|
public void testPutAllWithEmpty() {
|
||||||
|
|
||||||
ModifyAwareMap<String, String> map = createMap();
|
ModifyAwareMap<String, String> map = createMap();
|
||||||
Assert.assertFalse(map.isMarkedDirty());
|
assertFalse(map.isMarkedDirty());
|
||||||
|
|
||||||
Map<String, String> other = new HashMap<>();
|
Map<String, String> other = new HashMap<>();
|
||||||
map.putAll(other);
|
map.putAll(other);
|
||||||
@@ -131,10 +134,10 @@ public class ModifyAwareMapTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testPutAll() throws Exception {
|
public void testPutAll() {
|
||||||
|
|
||||||
ModifyAwareMap<String, String> map = createMap();
|
ModifyAwareMap<String, String> map = createMap();
|
||||||
Assert.assertFalse(map.isMarkedDirty());
|
assertFalse(map.isMarkedDirty());
|
||||||
|
|
||||||
Map<String, String> other = new HashMap<>();
|
Map<String, String> other = new HashMap<>();
|
||||||
other.put("A", "one");
|
other.put("A", "one");
|
||||||
@@ -143,49 +146,49 @@ public class ModifyAwareMapTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testClear() throws Exception {
|
public void testClear() {
|
||||||
|
|
||||||
ModifyAwareMap<String, String> map = createMap();
|
ModifyAwareMap<String, String> map = createMap();
|
||||||
Assert.assertFalse(map.isMarkedDirty());
|
assertFalse(map.isMarkedDirty());
|
||||||
|
|
||||||
map.clear();
|
map.clear();
|
||||||
Assert.assertTrue(map.isMarkedDirty());
|
Assert.assertTrue(map.isMarkedDirty());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testKeySet() throws Exception {
|
public void testKeySet() {
|
||||||
|
|
||||||
ModifyAwareMap<String, String> map = createMap();
|
ModifyAwareMap<String, String> map = createMap();
|
||||||
Assert.assertFalse(map.isMarkedDirty());
|
assertFalse(map.isMarkedDirty());
|
||||||
|
|
||||||
Set<String> keys = map.keySet();
|
Set<String> keys = map.keySet();
|
||||||
Assert.assertEquals(map.size(), keys.size());
|
assertEquals(map.size(), keys.size());
|
||||||
Assert.assertTrue(keys.contains("A"));
|
Assert.assertTrue(keys.contains("A"));
|
||||||
Assert.assertFalse(map.isMarkedDirty());
|
assertFalse(map.isMarkedDirty());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testValues() throws Exception {
|
public void testValues() {
|
||||||
|
|
||||||
ModifyAwareMap<String, String> map = createMap();
|
ModifyAwareMap<String, String> map = createMap();
|
||||||
Assert.assertFalse(map.isMarkedDirty());
|
assertFalse(map.isMarkedDirty());
|
||||||
|
|
||||||
Collection<String> values = map.values();
|
Collection<String> values = map.values();
|
||||||
Assert.assertEquals(map.size(), values.size());
|
assertEquals(map.size(), values.size());
|
||||||
Assert.assertTrue(values.contains("one"));
|
Assert.assertTrue(values.contains("one"));
|
||||||
Assert.assertFalse(map.isMarkedDirty());
|
assertFalse(map.isMarkedDirty());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testEntrySet() throws Exception {
|
public void testEntrySet() {
|
||||||
|
|
||||||
ModifyAwareMap<String, String> map = createMap();
|
ModifyAwareMap<String, String> map = createMap();
|
||||||
Set<Map.Entry<String, String>> entries = map.entrySet();
|
Set<Map.Entry<String, String>> entries = map.entrySet();
|
||||||
|
|
||||||
Assert.assertFalse(map.isMarkedDirty());
|
assertFalse(map.isMarkedDirty());
|
||||||
|
|
||||||
Assert.assertEquals(map.size(), entries.size());
|
assertEquals(map.size(), entries.size());
|
||||||
Assert.assertFalse(map.isMarkedDirty());
|
assertFalse(map.isMarkedDirty());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -204,6 +207,27 @@ public class ModifyAwareMapTest {
|
|||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
ModifyAwareMap<String, String> read = (ModifyAwareMap<String, String>) ois.readObject();
|
ModifyAwareMap<String, String> read = (ModifyAwareMap<String, String>) ois.readObject();
|
||||||
Assertions.assertThat(read).hasSize(orig.size());
|
assertThat(read).hasSize(orig.size());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void equalsWhenEqual() {
|
||||||
|
|
||||||
|
ModifyAwareMap<String, String> mapA = createMap();
|
||||||
|
ModifyAwareMap<String, String> mapB = createMap();
|
||||||
|
|
||||||
|
assertThat(mapA).isEqualTo(mapB);
|
||||||
|
assertThat(mapA.hashCode()).isEqualTo(mapB.hashCode());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void equalsWhenNotEqual() {
|
||||||
|
|
||||||
|
ModifyAwareMap<String, String> mapA = createMap();
|
||||||
|
ModifyAwareMap<String, String> mapB = createMap();
|
||||||
|
mapB.put("F", "Six");
|
||||||
|
|
||||||
|
assertThat(mapA).isNotEqualTo(mapB);
|
||||||
|
assertThat(mapA.hashCode()).isNotEqualTo(mapB.hashCode());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -24,9 +24,7 @@ import static org.junit.Assert.assertTrue;
|
|||||||
public class ModifyAwareListTest {
|
public class ModifyAwareListTest {
|
||||||
|
|
||||||
private ModifyAwareList<String> createList() {
|
private ModifyAwareList<String> createList() {
|
||||||
ArrayList<String> list = new ArrayList<>();
|
return new ModifyAwareList<>(new ArrayList<>(Arrays.asList("A", "B", "C", "D", "E")));
|
||||||
list.addAll(Arrays.asList("A", "B", "C", "D", "E"));
|
|
||||||
return new ModifyAwareList<>(list);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private ModifyAwareList<String> createEmptyList() {
|
private ModifyAwareList<String> createEmptyList() {
|
||||||
@@ -34,27 +32,27 @@ public class ModifyAwareListTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSize() throws Exception {
|
public void testSize() {
|
||||||
|
|
||||||
assertEquals(5, createList().size());
|
assertEquals(5, createList().size());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testIsEmpty() throws Exception {
|
public void testIsEmpty() {
|
||||||
|
|
||||||
assertFalse(createList().isEmpty());
|
assertFalse(createList().isEmpty());
|
||||||
assertTrue(createEmptyList().isEmpty());
|
assertTrue(createEmptyList().isEmpty());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testContains() throws Exception {
|
public void testContains() {
|
||||||
|
|
||||||
assertTrue(createList().contains("B"));
|
assertTrue(createList().contains("B"));
|
||||||
assertFalse(createList().contains("Z"));
|
assertFalse(createList().contains("Z"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testIterator() throws Exception {
|
public void testIterator() {
|
||||||
|
|
||||||
ModifyAwareList<String> list = createList();
|
ModifyAwareList<String> list = createList();
|
||||||
Iterator<String> iterator = list.iterator();
|
Iterator<String> iterator = list.iterator();
|
||||||
@@ -67,7 +65,7 @@ public class ModifyAwareListTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testToArray() throws Exception {
|
public void testToArray() {
|
||||||
|
|
||||||
Object[] objects = createList().toArray();
|
Object[] objects = createList().toArray();
|
||||||
assertEquals(5, objects.length);
|
assertEquals(5, objects.length);
|
||||||
@@ -76,7 +74,7 @@ public class ModifyAwareListTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testToArray1() throws Exception {
|
public void testToArray1() {
|
||||||
|
|
||||||
String[] objects = createList().toArray(new String[5]);
|
String[] objects = createList().toArray(new String[5]);
|
||||||
assertEquals(5, objects.length);
|
assertEquals(5, objects.length);
|
||||||
@@ -85,7 +83,7 @@ public class ModifyAwareListTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testAdd() throws Exception {
|
public void testAdd() {
|
||||||
|
|
||||||
ModifyAwareList<String> list = createList();
|
ModifyAwareList<String> list = createList();
|
||||||
assertFalse(list.isMarkedDirty());
|
assertFalse(list.isMarkedDirty());
|
||||||
@@ -95,7 +93,7 @@ public class ModifyAwareListTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testRemove() throws Exception {
|
public void testRemove() {
|
||||||
|
|
||||||
ModifyAwareList<String> list = createList();
|
ModifyAwareList<String> list = createList();
|
||||||
assertFalse(list.isMarkedDirty());
|
assertFalse(list.isMarkedDirty());
|
||||||
@@ -105,7 +103,7 @@ public class ModifyAwareListTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testContainsAll() throws Exception {
|
public void testContainsAll() {
|
||||||
|
|
||||||
ModifyAwareList<String> list = createList();
|
ModifyAwareList<String> list = createList();
|
||||||
|
|
||||||
@@ -114,7 +112,7 @@ public class ModifyAwareListTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testAddAll() throws Exception {
|
public void testAddAll() {
|
||||||
|
|
||||||
ModifyAwareList<String> list = createList();
|
ModifyAwareList<String> list = createList();
|
||||||
assertFalse(list.isMarkedDirty());
|
assertFalse(list.isMarkedDirty());
|
||||||
@@ -125,7 +123,7 @@ public class ModifyAwareListTest {
|
|||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testRemoveAll() throws Exception {
|
public void testRemoveAll() {
|
||||||
|
|
||||||
ModifyAwareList<String> list = createList();
|
ModifyAwareList<String> list = createList();
|
||||||
assertFalse(list.isMarkedDirty());
|
assertFalse(list.isMarkedDirty());
|
||||||
@@ -135,7 +133,7 @@ public class ModifyAwareListTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testRetainAll() throws Exception {
|
public void testRetainAll() {
|
||||||
|
|
||||||
ModifyAwareList<String> list = createList();
|
ModifyAwareList<String> list = createList();
|
||||||
assertFalse(list.isMarkedDirty());
|
assertFalse(list.isMarkedDirty());
|
||||||
@@ -146,7 +144,7 @@ public class ModifyAwareListTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testClear() throws Exception {
|
public void testClear() {
|
||||||
|
|
||||||
ModifyAwareList<String> list = createList();
|
ModifyAwareList<String> list = createList();
|
||||||
assertFalse(list.isMarkedDirty());
|
assertFalse(list.isMarkedDirty());
|
||||||
@@ -158,7 +156,7 @@ public class ModifyAwareListTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGet() throws Exception {
|
public void testGet() {
|
||||||
|
|
||||||
ModifyAwareList<String> list = createList();
|
ModifyAwareList<String> list = createList();
|
||||||
|
|
||||||
@@ -168,7 +166,7 @@ public class ModifyAwareListTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSet() throws Exception {
|
public void testSet() {
|
||||||
|
|
||||||
ModifyAwareList<String> list = createList();
|
ModifyAwareList<String> list = createList();
|
||||||
assertFalse(list.isMarkedDirty());
|
assertFalse(list.isMarkedDirty());
|
||||||
@@ -179,7 +177,7 @@ public class ModifyAwareListTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testIndexOf() throws Exception {
|
public void testIndexOf() {
|
||||||
|
|
||||||
ModifyAwareList<String> list = createList();
|
ModifyAwareList<String> list = createList();
|
||||||
assertFalse(list.isMarkedDirty());
|
assertFalse(list.isMarkedDirty());
|
||||||
@@ -190,7 +188,7 @@ public class ModifyAwareListTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testLastIndexOf() throws Exception {
|
public void testLastIndexOf() {
|
||||||
|
|
||||||
ModifyAwareList<String> list = createList();
|
ModifyAwareList<String> list = createList();
|
||||||
assertFalse(list.isMarkedDirty());
|
assertFalse(list.isMarkedDirty());
|
||||||
@@ -201,7 +199,7 @@ public class ModifyAwareListTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testListIterator() throws Exception {
|
public void testListIterator() {
|
||||||
|
|
||||||
ModifyAwareList<String> list = createList();
|
ModifyAwareList<String> list = createList();
|
||||||
ListIterator<String> iterator = list.listIterator();
|
ListIterator<String> iterator = list.listIterator();
|
||||||
@@ -214,7 +212,7 @@ public class ModifyAwareListTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testListIterator1() throws Exception {
|
public void testListIterator1() {
|
||||||
|
|
||||||
ModifyAwareList<String> list = createList();
|
ModifyAwareList<String> list = createList();
|
||||||
ListIterator<String> iterator = list.listIterator(2);
|
ListIterator<String> iterator = list.listIterator(2);
|
||||||
@@ -228,7 +226,7 @@ public class ModifyAwareListTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSubList() throws Exception {
|
public void testSubList() {
|
||||||
|
|
||||||
ModifyAwareList<String> list = createList();
|
ModifyAwareList<String> list = createList();
|
||||||
List<String> sub = list.subList(1, 3);
|
List<String> sub = list.subList(1, 3);
|
||||||
@@ -242,7 +240,7 @@ public class ModifyAwareListTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testAsSet() throws Exception {
|
public void testAsSet() {
|
||||||
|
|
||||||
ModifyAwareList<String> list = createList();
|
ModifyAwareList<String> list = createList();
|
||||||
ModifyAwareSet<String> set = list.asSet();
|
ModifyAwareSet<String> set = list.asSet();
|
||||||
@@ -271,4 +269,25 @@ public class ModifyAwareListTest {
|
|||||||
ModifyAwareList<String> read = (ModifyAwareList<String>)ois.readObject();
|
ModifyAwareList<String> read = (ModifyAwareList<String>)ois.readObject();
|
||||||
assertThat(read).contains("A", "B", "C", "D", "E");
|
assertThat(read).contains("A", "B", "C", "D", "E");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void equalsWhenEqual() {
|
||||||
|
|
||||||
|
ModifyAwareList<String> listA = createList();
|
||||||
|
ModifyAwareList<String> listB = createList();
|
||||||
|
|
||||||
|
assertThat(listA).isEqualTo(listB);
|
||||||
|
assertThat(listA.hashCode()).isEqualTo(listB.hashCode());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void equalsWhenNotEqual() {
|
||||||
|
|
||||||
|
ModifyAwareList<String> listA = createList();
|
||||||
|
ModifyAwareList<String> listB = createList();
|
||||||
|
listB.add("F");
|
||||||
|
|
||||||
|
assertThat(listA).isNotEqualTo(listB);
|
||||||
|
assertThat(listA.hashCode()).isNotEqualTo(listB.hashCode());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -38,4 +38,25 @@ public class ModifyAwareSetTest {
|
|||||||
ModifyAwareSet<String> read = (ModifyAwareSet<String>)ois.readObject();
|
ModifyAwareSet<String> read = (ModifyAwareSet<String>)ois.readObject();
|
||||||
assertThat(read).contains("A", "B", "C", "D", "E");
|
assertThat(read).contains("A", "B", "C", "D", "E");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void equalsWhenEqual() {
|
||||||
|
|
||||||
|
ModifyAwareSet<String> setA = createSet();
|
||||||
|
ModifyAwareSet<String> setB = createSet();
|
||||||
|
|
||||||
|
assertThat(setA).isEqualTo(setB);
|
||||||
|
assertThat(setA.hashCode()).isEqualTo(setB.hashCode());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void equalsWhenNotEqual() {
|
||||||
|
|
||||||
|
ModifyAwareSet<String> setA = createSet();
|
||||||
|
ModifyAwareSet<String> setB = createSet();
|
||||||
|
setB.add("F");
|
||||||
|
|
||||||
|
assertThat(setA).isNotEqualTo(setB);
|
||||||
|
assertThat(setA.hashCode()).isNotEqualTo(setB.hashCode());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user