StateNodeNodeList extends NodeList<StateNode> { @Override protected void add(int index, StateNode item) { assert item != null; super.add(index, item); attachPotentialChild(item); } protected  StateNodeNodeList(StateNode node); @Override void forEachChild(Consumer<StateNode> action);  }
@Test public void testChangesAfterReset() { StateNode value1 = StateNodeTest.createEmptyNode("value1"); StateNode value2 = StateNodeTest.createEmptyNode("value2"); nodeList.add(value1); nodeList.add(value2); nodeList.getNode().clearChanges(); nodeList.generateChangesFromEmpty(); List<NodeChange> changes = collectChanges(nodeList); Assert.assertEquals(1, changes.size()); ListAddChange<?> change = (ListAddChange<?>) changes.get(0); Assert.assertEquals(0, change.getIndex()); Assert.assertEquals(Arrays.asList(value1, value2), change.getNewItems()); }
@Test public void testIndexOf() { StateNode one = StateNodeTest.createEmptyNode("one"); StateNode two = StateNodeTest.createEmptyNode("two"); StateNode three = StateNodeTest.createEmptyNode("three"); nodeList.add(one); nodeList.add(two); Assert.assertEquals(0, nodeList.indexOf(one)); Assert.assertEquals(1, nodeList.indexOf(two)); Assert.assertEquals(-1, nodeList.indexOf(three)); }
@Test(expected = AssertionError.class) public void nullNotAllowed() { nodeList.add(null); }
@Test public void testSerializable() { StateNode one = StateNodeTest.createTestNode("one", ElementClassList.class); one.getFeature(ElementClassList.class).add("foo"); one.getFeature(ElementClassList.class).add("bar"); StateNode two = StateNodeTest.createTestNode("two", ElementClassList.class); two.getFeature(ElementClassList.class).add("baz"); nodeList.add(one); nodeList.add(two); List<StateNode> values = new ArrayList<>(); int size = nodeList.size(); for (int i = 0; i < size; i++) { values.add(nodeList.get(i)); } NodeList<StateNode> copy = SerializationUtils .deserialize(SerializationUtils.serialize(nodeList)); Assert.assertNotSame(nodeList, copy); Assert.assertEquals(values.size(), copy.size()); for (int i = 0; i < size; i++) { assertNodeEquals(values.get(i), copy.get(i)); } Assert.assertEquals(values.size(), nodeList.size()); for (int i = 0; i < size; i++) { assertNodeEquals(values.get(i), nodeList.get(i)); } }