@Test void getReferences() { 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 label0 = "label0"; Integer id0 = 0; Entity entity0 = when(mock(Entity.class).getLabelValue()).thenReturn(label0).getMock(); when(dataService.findOneById(entityTypeId, id0)).thenReturn(entity0); String label1 = "label1"; Integer id1 = 1; Entity entity1 = when(mock(Entity.class).getLabelValue()).thenReturn(label1).getMock(); when(dataService.findOneById(entityTypeId, id1)).thenReturn(entity1); Iterable<Entity> entityReferences = entityManagerImpl.getReferences(entityType, Arrays.asList(id0, id1)); Iterator<Entity> it = entityReferences.iterator(); assertTrue(it.hasNext()); Entity entityReference0 = it.next(); assertEquals(id0, entityReference0.getIdValue()); verifyNoMoreInteractions(dataService); assertEquals(label0, entityReference0.getLabelValue()); verify(dataService, times(1)).findOneById(entityTypeId, id0); assertTrue(it.hasNext()); Entity entityReference1 = it.next(); assertEquals(id1, entityReference1.getIdValue()); verifyNoMoreInteractions(dataService); assertEquals(label1, entityReference1.getLabelValue()); verify(dataService, times(1)).findOneById(entityTypeId, id1); assertFalse(it.hasNext()); }
@Override public Iterable<Entity> getReferences(EntityType entityType, Iterable<?> ids) { EntityFactory<? extends Entity, ?> entityFactory = entityFactoryRegistry.getEntityFactory(entityType); return () -> stream(ids) .map( id -> { Entity lazyEntity = getReference(entityType, id); if (entityFactory != null) { lazyEntity = entityFactory.create(lazyEntity); } return lazyEntity; }) .iterator(); }
EntityReferenceCreatorImpl implements EntityReferenceCreator { @Override public Iterable<Entity> getReferences(EntityType entityType, Iterable<?> ids) { EntityFactory<? extends Entity, ?> entityFactory = entityFactoryRegistry.getEntityFactory(entityType); return () -> stream(ids) .map( id -> { Entity lazyEntity = getReference(entityType, id); if (entityFactory != null) { lazyEntity = entityFactory.create(lazyEntity); } return lazyEntity; }) .iterator(); } }
EntityReferenceCreatorImpl implements EntityReferenceCreator { @Override public Iterable<Entity> getReferences(EntityType entityType, Iterable<?> ids) { EntityFactory<? extends Entity, ?> entityFactory = entityFactoryRegistry.getEntityFactory(entityType); return () -> stream(ids) .map( id -> { Entity lazyEntity = getReference(entityType, id); if (entityFactory != null) { lazyEntity = entityFactory.create(lazyEntity); } return lazyEntity; }) .iterator(); } EntityReferenceCreatorImpl(
      DataService dataService, EntityFactoryRegistry entityFactoryRegistry); }
EntityReferenceCreatorImpl implements EntityReferenceCreator { @Override public Iterable<Entity> getReferences(EntityType entityType, Iterable<?> ids) { EntityFactory<? extends Entity, ?> entityFactory = entityFactoryRegistry.getEntityFactory(entityType); return () -> stream(ids) .map( id -> { Entity lazyEntity = getReference(entityType, id); if (entityFactory != null) { lazyEntity = entityFactory.create(lazyEntity); } return lazyEntity; }) .iterator(); } 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 Iterable<Entity> getReferences(EntityType entityType, Iterable<?> ids) { EntityFactory<? extends Entity, ?> entityFactory = entityFactoryRegistry.getEntityFactory(entityType); return () -> stream(ids) .map( id -> { Entity lazyEntity = getReference(entityType, id); if (entityFactory != null) { lazyEntity = entityFactory.create(lazyEntity); } return lazyEntity; }) .iterator(); } EntityReferenceCreatorImpl(
      DataService dataService, EntityFactoryRegistry entityFactoryRegistry); @Override Entity getReference(EntityType entityType, Object id); @Override Iterable<Entity> getReferences(EntityType entityType, Iterable<?> ids);  }