@Test void getReference() { String entityTypeId = "entity"; EntityType entityType = when(mock(EntityType.class).getId()).thenReturn(entityTypeId).getMock(); Attribute idAttr = when(mock(Attribute.class).getName()).thenReturn("id").getMock(); Attribute lblAttr = when(mock(Attribute.class).getName()).thenReturn("label").getMock(); when(entityType.getIdAttribute()).thenReturn(idAttr); when(entityType.getLabelAttribute()).thenReturn(lblAttr); String label = "label"; Integer id = 0; Entity entity = when(mock(Entity.class).getLabelValue()).thenReturn(label).getMock(); when(dataService.findOneById(entityTypeId, id)).thenReturn(entity); Entity entityReference = entityManagerImpl.getReference(entityType, id); assertEquals(id, entityReference.getIdValue()); verifyNoMoreInteractions(dataService); assertEquals(entityReference.getLabelValue(), label); verify(dataService, times(1)).findOneById(entityTypeId, id); }
@Override public Entity getReference(EntityType entityType, Object id) { Entity lazyEntity = new LazyEntity(entityType, dataService, id); EntityFactory<? extends Entity, ?> entityFactory = entityFactoryRegistry.getEntityFactory(entityType); if (entityFactory != null) { lazyEntity = entityFactory.create(lazyEntity); } return lazyEntity; }
EntityReferenceCreatorImpl implements EntityReferenceCreator { @Override public Entity getReference(EntityType entityType, Object id) { Entity lazyEntity = new LazyEntity(entityType, dataService, id); EntityFactory<? extends Entity, ?> entityFactory = entityFactoryRegistry.getEntityFactory(entityType); if (entityFactory != null) { lazyEntity = entityFactory.create(lazyEntity); } return lazyEntity; } }
EntityReferenceCreatorImpl implements EntityReferenceCreator { @Override public Entity getReference(EntityType entityType, Object id) { Entity lazyEntity = new LazyEntity(entityType, dataService, id); EntityFactory<? extends Entity, ?> entityFactory = entityFactoryRegistry.getEntityFactory(entityType); if (entityFactory != null) { lazyEntity = entityFactory.create(lazyEntity); } return lazyEntity; } EntityReferenceCreatorImpl(
      DataService dataService, EntityFactoryRegistry entityFactoryRegistry); }
EntityReferenceCreatorImpl implements EntityReferenceCreator { @Override public Entity getReference(EntityType entityType, Object id) { Entity lazyEntity = new LazyEntity(entityType, dataService, id); EntityFactory<? extends Entity, ?> entityFactory = entityFactoryRegistry.getEntityFactory(entityType); if (entityFactory != null) { lazyEntity = entityFactory.create(lazyEntity); } return lazyEntity; } EntityReferenceCreatorImpl(
      DataService dataService, EntityFactoryRegistry entityFactoryRegistry); @Override Entity getReference(EntityType entityType, Object id); @Override Iterable<Entity> getReferences(EntityType entityType, Iterable<?> ids); }
EntityReferenceCreatorImpl implements EntityReferenceCreator { @Override public Entity getReference(EntityType entityType, Object id) { Entity lazyEntity = new LazyEntity(entityType, dataService, id); EntityFactory<? extends Entity, ?> entityFactory = entityFactoryRegistry.getEntityFactory(entityType); if (entityFactory != null) { lazyEntity = entityFactory.create(lazyEntity); } return lazyEntity; } EntityReferenceCreatorImpl(
      DataService dataService, EntityFactoryRegistry entityFactoryRegistry); @Override Entity getReference(EntityType entityType, Object id); @Override Iterable<Entity> getReferences(EntityType entityType, Iterable<?> ids);  }