@Test void testPretendingEntityIsCopy() { Entity entity = mock(Entity.class); EntityType entityType = mock(EntityType.class); when(entityType.getId()).thenReturn("oldId"); EntityType entityTypeCopy = mock(EntityType.class); when(entity.getEntityType()).thenReturn(entityType); Map<String, EntityType> copiedEntityTypes = ImmutableMap.of("oldId", entityTypeCopy); PretendingEntity pretendingEntity = new PretendingEntity(entity, copiedEntityTypes); assertEquals(entityTypeCopy, pretendingEntity.getEntityType()); }
@Override public EntityType getEntityType() { String id = delegate().getEntityType().getId(); if (copiedEntityTypes.containsKey(id)) { return copiedEntityTypes.get(id); } else { return delegate().getEntityType(); } }
PretendingEntity extends AbstractEntityDecorator { @Override public EntityType getEntityType() { String id = delegate().getEntityType().getId(); if (copiedEntityTypes.containsKey(id)) { return copiedEntityTypes.get(id); } else { return delegate().getEntityType(); } } }
PretendingEntity extends AbstractEntityDecorator { @Override public EntityType getEntityType() { String id = delegate().getEntityType().getId(); if (copiedEntityTypes.containsKey(id)) { return copiedEntityTypes.get(id); } else { return delegate().getEntityType(); } } PretendingEntity(Entity entity, Map<String, EntityType> copiedEntityTypes); }
PretendingEntity extends AbstractEntityDecorator { @Override public EntityType getEntityType() { String id = delegate().getEntityType().getId(); if (copiedEntityTypes.containsKey(id)) { return copiedEntityTypes.get(id); } else { return delegate().getEntityType(); } } PretendingEntity(Entity entity, Map<String, EntityType> copiedEntityTypes); @Override EntityType getEntityType(); @Override Entity getEntity(String attributeName); @Override @SuppressWarnings("unchecked") E getEntity(String attributeName, Class<E> clazz); @Override Iterable<Entity> getEntities(String attributeName); @Override @SuppressWarnings("unchecked") Iterable<E> getEntities(String attributeName, Class<E> clazz); }
PretendingEntity extends AbstractEntityDecorator { @Override public EntityType getEntityType() { String id = delegate().getEntityType().getId(); if (copiedEntityTypes.containsKey(id)) { return copiedEntityTypes.get(id); } else { return delegate().getEntityType(); } } PretendingEntity(Entity entity, Map<String, EntityType> copiedEntityTypes); @Override EntityType getEntityType(); @Override Entity getEntity(String attributeName); @Override @SuppressWarnings("unchecked") E getEntity(String attributeName, Class<E> clazz); @Override Iterable<Entity> getEntities(String attributeName); @Override @SuppressWarnings("unchecked") Iterable<E> getEntities(String attributeName, Class<E> clazz);  }