### Question:
EntityUtil { public static boolean isObjectsDifferent(Object original, Object compare, boolean consumeFieldsOnly) { boolean changed = false; if (original != null && compare == null) { changed = true; } else if (original == null && compare != null) { changed = true; } else if (original != null && compare != null) { if (original.getClass().isInstance(compare) || compare.getClass().isInstance(original)) { List<Field> fields = getAllFields(original.getClass()); for (Field field : fields) { boolean check = true; if (consumeFieldsOnly) { ConsumeField consume = field.getAnnotation(ConsumeField.class); if (consume == null) { check = false; } } if (check) { try { changed = isFieldsDifferent(BeanUtils.getProperty(original, field.getName()), BeanUtils.getProperty(compare, field.getName())); if (changed) { break; } } catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException ex) { throw new OpenStorefrontRuntimeException("Can't compare object types", ex); } } } } else { throw new OpenStorefrontRuntimeException("Can't compare different object types", "Check objects"); } } return changed; }  static void setDefaultsOnFields(Object entity); static boolean isObjectsDifferent(Object original, Object compare, boolean consumeFieldsOnly); @SuppressWarnings("unchecked") static int compareConsumeFields(Object original, Object compare); static Field getPKField(T entity); static boolean isPKFieldGenerated(T entity); static String getPKFieldValue(T entity); static Object getPKFieldObjectValue(T entity); static void updatePKFieldValue(T entity, String value); static Map<String, Object> findIdField(Class entityClass, Object id); static String getRealClassName(String className);  }### Answer:
@Test public void testIsObjectsDifferent() { System.out.println("isObjectsDifferent"); Component component = new Component(); component.setName("Test"); boolean consumeFieldsOnly = true; boolean expResult = false; boolean result = EntityUtil.isObjectsDifferent(component, component, consumeFieldsOnly); assertEquals(expResult, result); Component component2 = new Component(); component2.setName("Test_2"); expResult = true; result = EntityUtil.isObjectsDifferent(component, component2, consumeFieldsOnly); assertEquals(expResult, result); UserRecord userRecord1 = new UserRecord(); userRecord1.setFirstName("Bob"); userRecord1.setLastName("Test"); userRecord1.setOrganization("Test"); userRecord1.setEmail("Check@test.com"); userRecord1.setPhone("555-555-5555"); userRecord1.setUsername("Check"); UserRecord userRecord2 = new UserRecord(); userRecord2.setFirstName("Bob"); userRecord2.setLastName("Test"); userRecord2.setOrganization("Test"); userRecord2.setEmail("newemail@test.com"); userRecord2.setPhone("555-555-5555"); userRecord2.setUsername("Check"); expResult = true; result = EntityUtil.isObjectsDifferent(userRecord1, userRecord2, false); assertEquals(expResult, result); }
@Test(expected = OpenStorefrontRuntimeException.class) public void testIsObjectsDifferentFailure() { System.out.println("isObjectsDifferent"); UserRecord userRecord1 = new UserRecord(); userRecord1.setFirstName("Bob"); userRecord1.setLastName("Test"); userRecord1.setOrganization("Test"); userRecord1.setEmail("Check@test.com"); userRecord1.setPhone("555-555-5555"); userRecord1.setUsername("Check"); Component component = new Component(); component.setName("Test"); boolean expResult = true; boolean result = EntityUtil.isObjectsDifferent(userRecord1, component, false); assertEquals(expResult, result); }