public Entity build() { return new Entity(group, vertex, properties); } }
@Override protected Entity newElement(final String group) { return new Entity(group); }
@Override public Entity emptyClone() { return new Entity(this.getGroup(), this.getVertex()); }
@Test public void shouldPutMultipleEntities_2() { // Given final EntityMap entityMap = new EntityMap(); // When entityMap.putEntities(1, Sets.newHashSet(new Entity(TestGroups.ENTITY, 1), new Entity(TestGroups.ENTITY, 2), new Entity(TestGroups.ENTITY, 3))); entityMap.putEntities(1, Sets.newHashSet(new Entity(TestGroups.ENTITY, 4), new Entity(TestGroups.ENTITY, 5), new Entity(TestGroups.ENTITY, 6))); // Then assertThat(entityMap.containsVertex(1), is(true)); assertThat(entityMap.get(1), hasItems(new Entity(TestGroups.ENTITY, 1), new Entity(TestGroups.ENTITY, 2), new Entity(TestGroups.ENTITY, 3), new Entity(TestGroups.ENTITY, 4), new Entity(TestGroups.ENTITY, 5), new Entity(TestGroups.ENTITY, 6))); assertThat(entityMap.getVertices(), hasItems(1)); }
@Test public void shouldPutMultipleEntities_3() { // Given final EntityMap entityMap = new EntityMap(); // When entityMap.putEntities(1, Sets.newHashSet(new Entity(TestGroups.ENTITY, 1), new Entity(TestGroups.ENTITY, 2), new Entity(TestGroups.ENTITY, 3))); entityMap.putEntities(2, Sets.newHashSet(new Entity(TestGroups.ENTITY, 1), new Entity(TestGroups.ENTITY, 2), new Entity(TestGroups.ENTITY, 3))); // Then assertThat(entityMap.containsVertex(1), is(true)); assertThat(entityMap.get(1), hasItems(new Entity(TestGroups.ENTITY, 1), new Entity(TestGroups.ENTITY, 2), new Entity(TestGroups.ENTITY, 3))); assertThat(entityMap.get(2), hasItems(new Entity(TestGroups.ENTITY, 1), new Entity(TestGroups.ENTITY, 2), new Entity(TestGroups.ENTITY, 3))); assertThat(entityMap.getVertices(), hasItems(1, 2)); }
private EntityMap getEntityMap() { final EntityMap entityMap = new EntityMap(); entityMap.putEntity(1, new Entity(TestGroups.ENTITY, 1)); entityMap.putEntity(2, new Entity(TestGroups.ENTITY, 2)); entityMap.putEntity(3, new Entity(TestGroups.ENTITY, 3)); entityMap.putEntity(4, new Entity(TestGroups.ENTITY, 4)); entityMap.putEntity(5, new Entity(TestGroups.ENTITY, 5)); entityMap.putEntity(6, new Entity(TestGroups.ENTITY, 6)); return entityMap; } }
@Test public void shouldPutMultipleEntities() { // Given final EntityMap entityMap = new EntityMap(); // When entityMap.putEntities(1, Sets.newHashSet(new Entity(TestGroups.ENTITY, 1), new Entity(TestGroups.ENTITY, 2), new Entity(TestGroups.ENTITY, 3))); // Then assertThat(entityMap.containsVertex(1), is(true)); assertThat(entityMap.get(1), hasItems(new Entity(TestGroups.ENTITY, 1), new Entity(TestGroups.ENTITY, 2), new Entity(TestGroups.ENTITY, 3))); assertThat(entityMap.getVertices(), hasItems(1)); }
@Test public void shouldPutSingleEntity() { // Given final EntityMap entityMap = new EntityMap(); // When entityMap.putEntity(1, new Entity(TestGroups.ENTITY, 1)); // Then assertThat(entityMap.containsVertex(1), is(true)); assertThat(entityMap.get(1), hasItems(new Entity(TestGroups.ENTITY, 1))); assertThat(entityMap.getVertices(), hasItems(1)); }
@Test public void shouldDelegateGetGroupToEntity() { // Given final String group = "group"; final Entity entity = new Entity(group); final ElementValueLoader entityLoader = mock(ElementValueLoader.class); final LazyEntity lazyEntity = new LazyEntity(entity, entityLoader); // When final String groupResult = lazyEntity.getGroup(); // Then assertEquals(group, groupResult); }
@Test public void shouldUnwrapEntity() { // Given final Entity entity = new Entity("group"); final ElementValueLoader entityLoader = mock(ElementValueLoader.class); final LazyEntity lazyEntity = new LazyEntity(entity, entityLoader); // When final Entity result = lazyEntity.getElement(); // Then assertSame(entity, result); } }
private Entity cloneCoreFields(final Entity entity) { final Entity newEntity = new Entity(entity.getGroup()); newEntity.setVertex(entity.getVertex()); return newEntity; } }
@Test public void shouldCloneEntity() { // Given final String vertex = "vertex1"; final String propValue = "propValue"; // When final Entity entity = new Entity(TestGroups.ENTITY, vertex); final Entity clone = entity.emptyClone(); // Then assertEquals(clone, entity); }
@Test public void shouldDelegateSetIdentifierToEntity() { // Given final Entity entity = new Entity("group"); final ElementValueLoader entityLoader = mock(ElementValueLoader.class); final LazyEntity lazyEntity = new LazyEntity(entity, entityLoader); final String vertex = "vertex"; // When lazyEntity.setVertex(vertex); // Then verify(entityLoader, never()).loadIdentifiers(entity); assertEquals(vertex, entity.getVertex()); }
@Test public void shouldGetLazyProperties() { // Given final Entity entity = new Entity("group"); final ElementValueLoader entityLoader = mock(ElementValueLoader.class); final LazyEntity lazyEntity = new LazyEntity(entity, entityLoader); // When final LazyProperties result = lazyEntity.getProperties(); // Then assertNotNull(result); assertNotSame(entity.getProperties(), result); }
@Override @Test public void shouldReturnFalseForEqualsWhenGroupIsDifferent() { // Given final Entity entity1 = new Entity("group"); entity1.setVertex("vertex"); final Entity entity2 = new Entity("a different group"); entity2.setVertex(entity1.getVertex()); // When boolean isEqual = entity1.equals((Object) entity2); // Then assertFalse(isEqual); assertFalse(entity1.hashCode() == entity2.hashCode()); }
@Test public void shouldLoadPropertyFromLoader() { // Given final Entity entity = new Entity("group"); final ElementValueLoader entityLoader = mock(ElementValueLoader.class); final LazyEntity lazyEntity = new LazyEntity(entity, entityLoader); final String propertyName = "property name"; final String exceptedPropertyValue = "property value"; given(entityLoader.getProperty(propertyName, lazyEntity.getProperties())).willReturn(exceptedPropertyValue); // When Object propertyValue = lazyEntity.getProperty(propertyName); // Then assertEquals(exceptedPropertyValue, propertyValue); }
@Override @Test public void shouldReturnTrueForEqualsWithTheSameInstance() { // Given final Entity entity = new Entity("group"); entity.setVertex("identifier"); // When boolean isEqual = entity.equals(entity); // Then assertTrue(isEqual); assertEquals(entity.hashCode(), entity.hashCode()); }
@Test public void shouldConstructEntity() { // Given final String vertex = "vertex1"; final String propValue = "propValue"; // When final Entity entity = new Entity(TestGroups.ENTITY, vertex); entity.putProperty(TestPropertyNames.STRING, propValue); // Then assertEquals(TestGroups.ENTITY, entity.getGroup()); assertEquals(vertex, entity.getVertex()); assertEquals(propValue, entity.getProperty(TestPropertyNames.STRING)); }
@Test public void shouldReturnFalseForEqualsWhenIdentifierIsDifferent() { // Given final Entity entity1 = new Entity("group"); entity1.setVertex("vertex"); final Entity entity2 = cloneCoreFields(entity1); entity2.setVertex("different vertex"); // When boolean isEqual = entity1.equals((Object) entity2); // Then assertFalse(isEqual); assertFalse(entity1.hashCode() == entity2.hashCode()); }
@Test public void shouldReturnFalseForEqualsWhenPropertyIsDifferent() { // Given final Entity entity1 = new Entity("group"); entity1.setVertex("identifier"); entity1.putProperty("some property", "some value"); final Entity entity2 = cloneCoreFields(entity1); entity2.putProperty("some property", "some other value"); // When boolean isEqual = entity1.equals((Object) entity2); // Then assertFalse(isEqual); assertNotEquals(entity1.hashCode(), entity2.hashCode()); }