SerializableNodeList extends NodeList<T> { @Override protected void add(int index, T item) { assert !(item instanceof StateNode); super.add(index, item); } protected  SerializableNodeList(StateNode node);   }
@Test public void testSerializable() { nodeList.add("bar"); nodeList.add(null); List<Serializable> values = new ArrayList<>(); int size = nodeList.size(); for (int i = 0; i < size; i++) { values.add(nodeList.get(i)); } NodeList<Serializable> copy = SerializationUtils .deserialize(SerializationUtils.serialize(nodeList)); Assert.assertNotSame(nodeList, copy); Assert.assertEquals(values.size(), copy.size()); for (int i = 0; i < size; i++) { Assert.assertEquals(values.get(i), copy.get(i)); } Assert.assertEquals(values.size(), nodeList.size()); for (int i = 0; i < size; i++) { Assert.assertEquals(values.get(i), nodeList.get(i)); } }
@Test public void testRemoveUsingIterator() { nodeList.add("1"); nodeList.add("2"); nodeList.add("3"); nodeList.add("4"); nodeList.add("5"); collectChanges(nodeList); Iterator<String> i = nodeList.iterator(); i.next(); i.remove(); List<NodeChange> changes = collectChanges(nodeList); Assert.assertEquals(1, changes.size()); Assert.assertEquals(0, ((ListRemoveChange<?>) changes.get(0)).getIndex()); i.next(); i.next(); i.remove(); changes = collectChanges(nodeList); Assert.assertEquals(1, changes.size()); Assert.assertEquals(1, ((ListRemoveChange<?>) changes.get(0)).getIndex()); List<String> actual = new ArrayList<>(); for (int j = 0; j < nodeList.size(); j++) { actual.add(nodeList.get(j)); } Assert.assertArrayEquals(new String[] { "2", "4", "5" }, actual.toArray()); }
@Test public void clearUsingIterator() { nodeList.add("1"); nodeList.add("2"); collectChanges(nodeList); Iterator<String> i = nodeList.iterator(); i.next(); i.remove(); i.next(); i.remove(); List<NodeChange> changes = collectChanges(nodeList); Assert.assertEquals(2, changes.size()); Assert.assertEquals(0, ((ListRemoveChange<?>) changes.get(0)).getIndex()); Assert.assertEquals(0, ((ListRemoveChange<?>) changes.get(1)).getIndex()); Assert.assertEquals(0, nodeList.size()); }