Skip to content

Commit f29cbf5

Browse files
committed
DATACMNS-853 - Polishing.
Simplified test case. Formatting in ClassGeneratingPropertyAccessorFactory. Related tickets: DATACMNS-809. Original pull request: #161. Related pull request: #160.
1 parent db52592 commit f29cbf5

File tree

2 files changed

+29
-48
lines changed

2 files changed

+29
-48
lines changed

src/main/java/org/springframework/data/mapping/model/ClassGeneratingPropertyAccessorFactory.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -881,7 +881,7 @@ private static void visitGetProperty0(PersistentEntity<?, ?> entity, PersistentP
881881
Class<?> declaringClass = getter.getDeclaringClass();
882882
boolean interfaceDefinition = declaringClass.isInterface();
883883

884-
if(interfaceDefinition){
884+
if (interfaceDefinition) {
885885
invokeOpCode = INVOKEINTERFACE;
886886
}
887887

@@ -1065,7 +1065,7 @@ private static void visitSetProperty0(PersistentEntity<?, ?> entity, PersistentP
10651065
Class<?> declaringClass = setter.getDeclaringClass();
10661066
boolean interfaceDefinition = declaringClass.isInterface();
10671067

1068-
if(interfaceDefinition){
1068+
if (interfaceDefinition) {
10691069
invokeOpCode = INVOKEINTERFACE;
10701070
}
10711071

src/test/java/org/springframework/data/mapping/model/ClassGeneratingPropertyAccessorFactoryEntityTypeTests.java

Lines changed: 27 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,10 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
1716
package org.springframework.data.mapping.model;
1817

19-
import static org.hamcrest.Matchers.equalTo;
20-
import static org.hamcrest.Matchers.is;
21-
import static org.junit.Assert.assertThat;
18+
import static org.hamcrest.Matchers.*;
19+
import static org.junit.Assert.*;
2220

2321
import java.io.Serializable;
2422

@@ -27,58 +25,55 @@
2725
import org.springframework.data.mapping.PersistentEntity;
2826
import org.springframework.data.mapping.context.SampleMappingContext;
2927
import org.springframework.data.mapping.context.SamplePersistentProperty;
28+
import org.springframework.data.repository.core.EntityInformation;
3029
import org.springframework.data.repository.core.support.PersistentEntityInformation;
3130

3231
/**
33-
* Unit tests for {@link ClassGeneratingPropertyAccessorFactory} covering interface
34-
* and concrete class entity types.
32+
* Unit tests for {@link ClassGeneratingPropertyAccessorFactory} covering interface and concrete class entity types.
3533
*
3634
* @author John Blum
37-
* @see DATACMNS-809
35+
* @author Oliver Gierke
3836
*/
3937
public class ClassGeneratingPropertyAccessorFactoryEntityTypeTests {
4038

41-
private final SampleMappingContext mappingContext = new SampleMappingContext();
42-
43-
protected PersistentEntity<Object, SamplePersistentProperty> getPersistentEntity(Object entity) {
44-
return getPersistentEntity(entity.getClass());
45-
}
46-
47-
protected PersistentEntity<Object, SamplePersistentProperty> getPersistentEntity(Class<?> entityType) {
48-
return mappingContext.getPersistentEntity(entityType);
49-
}
50-
51-
protected PersistentEntityInformation<Object, ?> getPersistentEntityInformation(Object entity) {
52-
return new PersistentEntityInformation<Object, Serializable>(getPersistentEntity(entity));
53-
}
54-
55-
protected PersistentEntityInformation<Object, ?> getPersistentEntityInformation(Class<?> entityType) {
56-
return new PersistentEntityInformation<Object, Serializable>(getPersistentEntity(entityType));
57-
}
39+
SampleMappingContext mappingContext = new SampleMappingContext();
5840

41+
/**
42+
* @see DATACMNS-853
43+
*/
5944
@Test
6045
public void getIdentifierOfInterfaceBasedEntity() {
61-
PersistentEntityInformation<Object, ?> quickSortEntityInfo =
62-
getPersistentEntityInformation(Algorithm.class);
6346

6447
Algorithm quickSort = new QuickSort();
6548

66-
assertThat(String.valueOf(quickSortEntityInfo.getId(quickSort)), is(equalTo(quickSort.getName())));
49+
assertThat(getEntityInformation(Algorithm.class).getId(quickSort), is((Object) quickSort.getName()));
6750
}
6851

52+
/**
53+
* @see DATACMNS-853
54+
*/
6955
@Test
7056
public void getIdentifierOfClassBasedEntity() {
71-
Person jonDoe = Person.newPerson("JonDoe");
72-
PersistentEntityInformation<Object, ?> jonDoeEntityInfo = getPersistentEntityInformation(jonDoe);
7357

74-
assertThat(String.valueOf(jonDoeEntityInfo.getId(jonDoe)), is(equalTo(jonDoe.getName())));
58+
Person jonDoe = new Person("JonDoe");
59+
60+
assertThat(getEntityInformation(Person.class).getId(jonDoe), is((Object) jonDoe.name));
61+
}
62+
63+
private EntityInformation<Object, ?> getEntityInformation(Class<?> type) {
64+
65+
PersistentEntity<Object, SamplePersistentProperty> entity = mappingContext.getPersistentEntity(type);
66+
return new PersistentEntityInformation<Object, Serializable>(entity);
7567
}
7668

7769
interface Algorithm {
78-
@Id String getName();
70+
71+
@Id
72+
String getName();
7973
}
8074

8175
class QuickSort implements Algorithm {
76+
8277
@Override
8378
public String getName() {
8479
return getClass().toString();
@@ -87,24 +82,10 @@ public String getName() {
8782

8883
static class Person {
8984

90-
@Id
91-
private final String name;
92-
93-
static Person newPerson(String name) {
94-
return new Person(name);
95-
}
85+
@Id String name;
9686

9787
Person(String name) {
9888
this.name = name;
9989
}
100-
101-
public String getName() {
102-
return name;
103-
}
104-
105-
@Override
106-
public String toString() {
107-
return getName();
108-
}
10990
}
11091
}

0 commit comments

Comments
 (0)