@Test public void compare_via_introspector_if_introspectable() { when(introspectableResolver.isIntrospectable(node(buildRootPath()))).thenReturn(true); beanDiffer.compare(DiffNode.ROOT, instances); verify(introspector).introspect(instances.getType()); }
@Test public void return_untouched_node_if_working_and_base_are_the_same_instance() { when(instances.areNull()).thenReturn(true); final DiffNode node = beanDiffer.compare(DiffNode.ROOT, instances); assertThat(node).self().isUntouched(); }
@Test public void return_removed_node_if_working_is_null_and_base_is_not() { when(instances.hasBeenRemoved()).thenReturn(true); final DiffNode node = beanDiffer.compare(DiffNode.ROOT, instances); assertThat(node.getState(), is(DiffNode.State.REMOVED)); }
@Test public void compare_via_comparisonStrategy_if_present() { when(comparisonStrategyResolver.resolveComparisonStrategy(node(buildRootPath()))) .thenReturn(comparisonStrategy); beanDiffer.compare(DiffNode.ROOT, instances); verify(comparisonStrategy).compare(node(buildRootPath()), same(instances)); }
@Test public void do_not_add_property_nodes_to_bean_node_if_they_are_not_returnable() { given_root_node_is_introspectable(); final PropertyAwareAccessor propertyAccessor = given_introspector_returns_PropertyAccessor("foo"); final DiffNode propertyNode = given_DifferDispatcher_returns_Node_for_PropertyAccessor(propertyAccessor); given_Node_is_not_returnable(propertyNode); final DiffNode node = beanDiffer.compare(DiffNode.ROOT, instances); Assertions.assertThat(node.hasChildren()).isFalse(); }
@Test public void delegate_comparison_of_properties_when_comparing_via_introspector() { given_root_node_is_introspectable(); final PropertyAwareAccessor propertyAccessor = given_introspector_returns_PropertyAccessor("foo"); final DiffNode propertyNode = given_DifferDispatcher_returns_Node_for_PropertyAccessor(propertyAccessor); given_Node_is_returnable(propertyNode); final DiffNode node = beanDiffer.compare(DiffNode.ROOT, instances); Assertions.assertThat(node.getChild("foo")).isSameAs(propertyNode); }