@Test void testPopulateIntInvalid() { EntityType entityType = mock(EntityType.class); Entity entity = mock(Entity.class); Attribute attribute = mock(Attribute.class); when(attribute.hasExpression()).thenReturn(false); when(attribute.isMappedBy()).thenReturn(false); when(attribute.getDataType()).thenReturn(INT); when(attribute.getName()).thenReturn("int"); when(entityType.getAtomicAttributes()).thenReturn(singletonList(attribute)); Map<String, Object> valueMap = new HashMap<>(); valueMap.put("int", "15.0"); assertThrows( InvalidAttributeValueException.class, () -> entityManagerV3.populate(entityType, entity, valueMap)); }
@Override public void populate(EntityType entityType, Entity entity, Map<String, Object> requestValues) { getModifiableAttributes(entityType) .forEach( attribute -> { String attributeName = attribute.getName(); if (requestValues.containsKey(attributeName)) { Object requestValue = requestValues.get(attributeName); Object value = convert(attribute, requestValue); entity.set(attributeName, value); } }); }
EntityManagerV3Impl implements EntityManagerV3 { @Override public void populate(EntityType entityType, Entity entity, Map<String, Object> requestValues) { getModifiableAttributes(entityType) .forEach( attribute -> { String attributeName = attribute.getName(); if (requestValues.containsKey(attributeName)) { Object requestValue = requestValues.get(attributeName); Object value = convert(attribute, requestValue); entity.set(attributeName, value); } }); } }
EntityManagerV3Impl implements EntityManagerV3 { @Override public void populate(EntityType entityType, Entity entity, Map<String, Object> requestValues) { getModifiableAttributes(entityType) .forEach( attribute -> { String attributeName = attribute.getName(); if (requestValues.containsKey(attributeName)) { Object requestValue = requestValues.get(attributeName); Object value = convert(attribute, requestValue); entity.set(attributeName, value); } }); } EntityManagerV3Impl(EntityManager entityManager); }
EntityManagerV3Impl implements EntityManagerV3 { @Override public void populate(EntityType entityType, Entity entity, Map<String, Object> requestValues) { getModifiableAttributes(entityType) .forEach( attribute -> { String attributeName = attribute.getName(); if (requestValues.containsKey(attributeName)) { Object requestValue = requestValues.get(attributeName); Object value = convert(attribute, requestValue); entity.set(attributeName, value); } }); } EntityManagerV3Impl(EntityManager entityManager); @Override Entity create(EntityType entityType); @Override void populate(EntityType entityType, Entity entity, Map<String, Object> requestValues); }
EntityManagerV3Impl implements EntityManagerV3 { @Override public void populate(EntityType entityType, Entity entity, Map<String, Object> requestValues) { getModifiableAttributes(entityType) .forEach( attribute -> { String attributeName = attribute.getName(); if (requestValues.containsKey(attributeName)) { Object requestValue = requestValues.get(attributeName); Object value = convert(attribute, requestValue); entity.set(attributeName, value); } }); } EntityManagerV3Impl(EntityManager entityManager); @Override Entity create(EntityType entityType); @Override void populate(EntityType entityType, Entity entity, Map<String, Object> requestValues);  }