@Test public void testAssertThat_child_at_property_path_does_exist_succeeds_when_child_exists() { final ObjectWithString working = new ObjectWithString("foo"); final ObjectWithString base = new ObjectWithString("bar"); final Node node = ObjectDifferFactory.getInstance().compare(working, base); assertThat(node).child(PropertyPath.buildWith("value")).doesExist(); }
@Test(expected = AssertionError.class) public void testAssertThat_child_at_property_path_builder_does_exist_fails_when_child_doesnt_exist() { assertThat(null) .child(PropertyPath.createBuilder().withRoot().withPropertyName("value")) .doesExist(); }
@Test public void testCompareWithRemovedItem() throws Exception { final Collection<String> working = new LinkedList<String>(); final Collection<String> base = new LinkedList<String>(Arrays.asList("foo")); final CollectionNode node = differ.compare(working, base); assertThat(node.hasChanges(), is(true)); final Node child = node.getChild(PropertyPath.createBuilder().withRoot().withCollectionItem("foo").build()); assertThat(child.getState(), is(Node.State.REMOVED)); }
@Test public void testCompareWithChangedItem() throws Exception { final List<ObjectWithHashCodeAndEquals> working = Arrays.asList(new ObjectWithHashCodeAndEquals("foo", "1")); final List<ObjectWithHashCodeAndEquals> base = Arrays.asList(new ObjectWithHashCodeAndEquals("foo", "2")); final CollectionNode node = differ.compare(working, base); assertThat(node.hasChanges(), is(true)); final PropertyPath propertyPath = PropertyPath.createBuilder() .withRoot() .withCollectionItem(new ObjectWithHashCodeAndEquals("foo")) .build(); final Node child = node.getChild(propertyPath); assertThat(child.getState(), is(Node.State.CHANGED)); }
@Test(expected = AssertionError.class) public void testAssertThat_child_at_property_path_does_exist_fails_when_child_doesnt_exist() { assertThat(null).child(PropertyPath.buildWith("value")).doesExist(); }