13
13
* See the License for the specific language governing permissions and
14
14
* limitations under the License.
15
15
*/
16
-
17
16
package org .springframework .data .mapping .model ;
18
17
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 .*;
22
20
23
21
import java .io .Serializable ;
24
22
27
25
import org .springframework .data .mapping .PersistentEntity ;
28
26
import org .springframework .data .mapping .context .SampleMappingContext ;
29
27
import org .springframework .data .mapping .context .SamplePersistentProperty ;
28
+ import org .springframework .data .repository .core .EntityInformation ;
30
29
import org .springframework .data .repository .core .support .PersistentEntityInformation ;
31
30
32
31
/**
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.
35
33
*
36
34
* @author John Blum
37
- * @see DATACMNS-809
35
+ * @author Oliver Gierke
38
36
*/
39
37
public class ClassGeneratingPropertyAccessorFactoryEntityTypeTests {
40
38
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 ();
58
40
41
+ /**
42
+ * @see DATACMNS-853
43
+ */
59
44
@ Test
60
45
public void getIdentifierOfInterfaceBasedEntity () {
61
- PersistentEntityInformation <Object , ?> quickSortEntityInfo =
62
- getPersistentEntityInformation (Algorithm .class );
63
46
64
47
Algorithm quickSort = new QuickSort ();
65
48
66
- assertThat (String . valueOf ( quickSortEntityInfo . getId (quickSort )) , is (equalTo ( quickSort .getName () )));
49
+ assertThat (getEntityInformation ( Algorithm . class ). getId (quickSort ), is (( Object ) quickSort .getName ()));
67
50
}
68
51
52
+ /**
53
+ * @see DATACMNS-853
54
+ */
69
55
@ Test
70
56
public void getIdentifierOfClassBasedEntity () {
71
- Person jonDoe = Person .newPerson ("JonDoe" );
72
- PersistentEntityInformation <Object , ?> jonDoeEntityInfo = getPersistentEntityInformation (jonDoe );
73
57
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 );
75
67
}
76
68
77
69
interface Algorithm {
78
- @ Id String getName ();
70
+
71
+ @ Id
72
+ String getName ();
79
73
}
80
74
81
75
class QuickSort implements Algorithm {
76
+
82
77
@ Override
83
78
public String getName () {
84
79
return getClass ().toString ();
@@ -87,24 +82,10 @@ public String getName() {
87
82
88
83
static class Person {
89
84
90
- @ Id
91
- private final String name ;
92
-
93
- static Person newPerson (String name ) {
94
- return new Person (name );
95
- }
85
+ @ Id String name ;
96
86
97
87
Person (String name ) {
98
88
this .name = name ;
99
89
}
100
-
101
- public String getName () {
102
- return name ;
103
- }
104
-
105
- @ Override
106
- public String toString () {
107
- return getName ();
108
- }
109
90
}
110
91
}
0 commit comments