From f29cbf5752fb455399486ff5d217d7a155c710ec Mon Sep 17 00:00:00 2001 From: Oliver Gierke Date: Thu, 12 May 2016 15:34:18 +0200 Subject: [PATCH] DATACMNS-853 - Polishing. Simplified test case. Formatting in ClassGeneratingPropertyAccessorFactory. Related tickets: DATACMNS-809. Original pull request: #161. Related pull request: #160. --- ...lassGeneratingPropertyAccessorFactory.java | 4 +- ...ropertyAccessorFactoryEntityTypeTests.java | 73 +++++++------------ 2 files changed, 29 insertions(+), 48 deletions(-) diff --git a/src/main/java/org/springframework/data/mapping/model/ClassGeneratingPropertyAccessorFactory.java b/src/main/java/org/springframework/data/mapping/model/ClassGeneratingPropertyAccessorFactory.java index cf5e321bf..afe545c75 100644 --- a/src/main/java/org/springframework/data/mapping/model/ClassGeneratingPropertyAccessorFactory.java +++ b/src/main/java/org/springframework/data/mapping/model/ClassGeneratingPropertyAccessorFactory.java @@ -881,7 +881,7 @@ public class ClassGeneratingPropertyAccessorFactory implements PersistentPropert Class declaringClass = getter.getDeclaringClass(); boolean interfaceDefinition = declaringClass.isInterface(); - if(interfaceDefinition){ + if (interfaceDefinition) { invokeOpCode = INVOKEINTERFACE; } @@ -1065,7 +1065,7 @@ public class ClassGeneratingPropertyAccessorFactory implements PersistentPropert Class declaringClass = setter.getDeclaringClass(); boolean interfaceDefinition = declaringClass.isInterface(); - if(interfaceDefinition){ + if (interfaceDefinition) { invokeOpCode = INVOKEINTERFACE; } diff --git a/src/test/java/org/springframework/data/mapping/model/ClassGeneratingPropertyAccessorFactoryEntityTypeTests.java b/src/test/java/org/springframework/data/mapping/model/ClassGeneratingPropertyAccessorFactoryEntityTypeTests.java index 0cca4b882..ecd8bd498 100644 --- a/src/test/java/org/springframework/data/mapping/model/ClassGeneratingPropertyAccessorFactoryEntityTypeTests.java +++ b/src/test/java/org/springframework/data/mapping/model/ClassGeneratingPropertyAccessorFactoryEntityTypeTests.java @@ -13,12 +13,10 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package org.springframework.data.mapping.model; -import static org.hamcrest.Matchers.equalTo; -import static org.hamcrest.Matchers.is; -import static org.junit.Assert.assertThat; +import static org.hamcrest.Matchers.*; +import static org.junit.Assert.*; import java.io.Serializable; @@ -27,58 +25,55 @@ import org.springframework.data.annotation.Id; import org.springframework.data.mapping.PersistentEntity; import org.springframework.data.mapping.context.SampleMappingContext; import org.springframework.data.mapping.context.SamplePersistentProperty; +import org.springframework.data.repository.core.EntityInformation; import org.springframework.data.repository.core.support.PersistentEntityInformation; /** - * Unit tests for {@link ClassGeneratingPropertyAccessorFactory} covering interface - * and concrete class entity types. + * Unit tests for {@link ClassGeneratingPropertyAccessorFactory} covering interface and concrete class entity types. * * @author John Blum - * @see DATACMNS-809 + * @author Oliver Gierke */ public class ClassGeneratingPropertyAccessorFactoryEntityTypeTests { - private final SampleMappingContext mappingContext = new SampleMappingContext(); - - protected PersistentEntity getPersistentEntity(Object entity) { - return getPersistentEntity(entity.getClass()); - } - - protected PersistentEntity getPersistentEntity(Class entityType) { - return mappingContext.getPersistentEntity(entityType); - } - - protected PersistentEntityInformation getPersistentEntityInformation(Object entity) { - return new PersistentEntityInformation(getPersistentEntity(entity)); - } - - protected PersistentEntityInformation getPersistentEntityInformation(Class entityType) { - return new PersistentEntityInformation(getPersistentEntity(entityType)); - } + SampleMappingContext mappingContext = new SampleMappingContext(); + /** + * @see DATACMNS-853 + */ @Test public void getIdentifierOfInterfaceBasedEntity() { - PersistentEntityInformation quickSortEntityInfo = - getPersistentEntityInformation(Algorithm.class); Algorithm quickSort = new QuickSort(); - assertThat(String.valueOf(quickSortEntityInfo.getId(quickSort)), is(equalTo(quickSort.getName()))); + assertThat(getEntityInformation(Algorithm.class).getId(quickSort), is((Object) quickSort.getName())); } + /** + * @see DATACMNS-853 + */ @Test public void getIdentifierOfClassBasedEntity() { - Person jonDoe = Person.newPerson("JonDoe"); - PersistentEntityInformation jonDoeEntityInfo = getPersistentEntityInformation(jonDoe); - assertThat(String.valueOf(jonDoeEntityInfo.getId(jonDoe)), is(equalTo(jonDoe.getName()))); + Person jonDoe = new Person("JonDoe"); + + assertThat(getEntityInformation(Person.class).getId(jonDoe), is((Object) jonDoe.name)); + } + + private EntityInformation getEntityInformation(Class type) { + + PersistentEntity entity = mappingContext.getPersistentEntity(type); + return new PersistentEntityInformation(entity); } interface Algorithm { - @Id String getName(); + + @Id + String getName(); } class QuickSort implements Algorithm { + @Override public String getName() { return getClass().toString(); @@ -87,24 +82,10 @@ public class ClassGeneratingPropertyAccessorFactoryEntityTypeTests { static class Person { - @Id - private final String name; - - static Person newPerson(String name) { - return new Person(name); - } + @Id String name; Person(String name) { this.name = name; } - - public String getName() { - return name; - } - - @Override - public String toString() { - return getName(); - } } }