EntityUtil { public static boolean areEqualByContent(EntityModel leftEntityModel, EntityModel rightEntityModel) { Set<FieldModel> leftFieldModels = leftEntityModel.getValues(); Set<FieldModel> rightFieldModels = rightEntityModel.getValues(); if(leftFieldModels.size() != rightFieldModels.size()){ return false; } for (FieldModel leftFieldModel : leftFieldModels) { FieldModel rightFieldModel = findByFieldName(rightFieldModels, leftFieldModel.getName()); if (rightFieldModel == null) { return false; } else if(!areFieldModelsEqualByContent(leftFieldModel, rightFieldModel)) { return false; } } return true; }  static boolean areEqualByIdAndType(EntityModel leftEntityModel, EntityModel rightEntityModel); static boolean areEqualByContent(EntityModel leftEntityModel, EntityModel rightEntityModel); static boolean areFieldModelsEqualByContent(FieldModel leftFieldModel, FieldModel rightFieldModel); static boolean containsEntityModel(Collection<EntityModel> collection, EntityModel entityModel); static boolean containsEntityModel(Collection<EntityModel> collection, EntityModel entityModel, EntityEquator entityEquator); static boolean containsAllEntityModels(Collection<EntityModel> baseCollection, Collection<EntityModel> sourceCollection, EntityEquator entityEquator); static boolean containsSameEntities(Collection<EntityModel> leftCollection, Collection<EntityModel> rightCollection, EntityEquator entityEquator); static boolean removeEntityModel(Collection<EntityModel> collection, EntityModel entityModel); static boolean removeEntityModel(Collection<EntityModel> collection, EntityModel entityModel, EntityEquator entityEquator);  }
@Test public void testReferenceFieldModelEqualsByContent() { EntityModel entityModelOne = new EntityModel(); EntityModel refEntityModelOne = new EntityModel(); refEntityModelOne.setValue(new LongFieldModel("newField", 1337L)); entityModelOne.setValue(new ReferenceFieldModel("refEntity", refEntityModelOne)); EntityModel entityModelTwo = new EntityModel(); EntityModel refEntityModelTwo = new EntityModel(); refEntityModelTwo.setValue(new LongFieldModel("newField", 1337L)); entityModelTwo.setValue(new ReferenceFieldModel("refEntity", refEntityModelTwo)); assertTrue(EntityUtil.areEqualByContent(entityModelOne, entityModelTwo)); EntityModel refRefEntityModelOne = new EntityModel(); refRefEntityModelOne.setValue(new BooleanFieldModel("potato", true)); refEntityModelOne.setValue(new ReferenceFieldModel("refRefEntity", refRefEntityModelOne)); assertFalse(EntityUtil.areEqualByContent(entityModelOne, entityModelTwo)); refEntityModelTwo.setValue(new ReferenceFieldModel("refRefEntity", refRefEntityModelOne)); assertTrue(EntityUtil.areEqualByContent(entityModelOne, entityModelTwo)); }
@Test public void testEntityModelEqualsByContent() { EntityModel entityModelOne = new EntityModel(); EntityModel entityModelTwo = new EntityModel(); assertTrue(EntityUtil.areEqualByContent(entityModelOne, entityModelTwo)); entityModelOne.setValue(new StringFieldModel("id", "ID_HERE")); assertFalse(EntityUtil.areEqualByContent(entityModelOne, entityModelTwo)); entityModelTwo.setValue(new StringFieldModel("id", "ID_HERE")); assertTrue(EntityUtil.areEqualByContent(entityModelOne, entityModelTwo)); entityModelOne.setValue(new LongFieldModel("newField", 1337L)); assertFalse(EntityUtil.areEqualByContent(entityModelOne, entityModelTwo)); entityModelTwo.setValue(new LongFieldModel("newField", 1337L)); assertTrue(EntityUtil.areEqualByContent(entityModelOne, entityModelTwo)); entityModelTwo.setValue(new LongFieldModel("newField", 1336L)); assertFalse(EntityUtil.areEqualByContent(entityModelOne, entityModelTwo)); entityModelTwo.setValue(new LongFieldModel("newField", 1337L)); assertTrue(EntityUtil.areEqualByContent(entityModelOne, entityModelTwo)); entityModelTwo.setValue(new DateFieldModel("newField", ZonedDateTime.now())); assertFalse(EntityUtil.areEqualByContent(entityModelOne, entityModelTwo)); }