15
15
*/
16
16
package org .springframework .data .jdbc .core .convert ;
17
17
18
+ import static org .assertj .core .api .Assertions .*;
19
+
20
+ import org .junit .jupiter .api .BeforeEach ;
18
21
import org .junit .jupiter .api .Test ;
22
+
19
23
import org .springframework .core .ResolvableType ;
20
24
import org .springframework .core .convert .TypeDescriptor ;
25
+ import org .springframework .core .convert .support .ConfigurableConversionService ;
21
26
import org .springframework .core .convert .support .DefaultConversionService ;
22
27
import org .springframework .data .jdbc .core .mapping .AggregateReference ;
23
28
24
- import static org .assertj .core .api .Assertions .*;
25
-
26
29
/**
27
30
* Tests for converters from an to {@link org.springframework.data.jdbc.core.mapping.AggregateReference}.
28
31
*
29
32
* @author Jens Schauder
33
+ * @author Mark Paluch
30
34
*/
31
35
class AggregateReferenceConvertersUnitTests {
32
36
33
- AggregateReferenceConverters .SimpleTypeToAggregateReferenceConverter simpleToAggregate = new AggregateReferenceConverters .SimpleTypeToAggregateReferenceConverter (DefaultConversionService .getSharedInstance ());
34
- AggregateReferenceConverters .AggregateReferenceToSimpleTypeConverter aggregateToSimple = new AggregateReferenceConverters .AggregateReferenceToSimpleTypeConverter (DefaultConversionService .getSharedInstance ());
37
+ ConfigurableConversionService conversionService ;
38
+
39
+ @ BeforeEach
40
+ void setUp () {
41
+ conversionService = new DefaultConversionService ();
42
+ AggregateReferenceConverters .getConvertersToRegister (DefaultConversionService .getSharedInstance ())
43
+ .forEach (it -> conversionService .addConverter (it ));
44
+ }
35
45
36
- @ Test // # 992
46
+ @ Test // GH- 992
37
47
void convertsFromSimpleValue () {
38
48
39
49
ResolvableType aggregateReferenceWithIdTypeInteger = ResolvableType .forClassWithGenerics (AggregateReference .class , String .class , Integer .class );
40
- final Object converted = simpleToAggregate .convert (23 , TypeDescriptor .forObject (23 ), new TypeDescriptor (aggregateReferenceWithIdTypeInteger , null , null ));
50
+ Object converted = conversionService .convert (23 , TypeDescriptor .forObject (23 ),
51
+ new TypeDescriptor (aggregateReferenceWithIdTypeInteger , null , null ));
41
52
42
53
assertThat (converted ).isEqualTo (AggregateReference .to (23 ));
43
54
}
44
55
45
- @ Test // # 992
56
+ @ Test // GH- 992
46
57
void convertsFromSimpleValueThatNeedsSeparateConversion () {
47
58
48
59
ResolvableType aggregateReferenceWithIdTypeInteger = ResolvableType .forClassWithGenerics (AggregateReference .class , String .class , Long .class );
49
- final Object converted = simpleToAggregate .convert (23 , TypeDescriptor .forObject (23 ), new TypeDescriptor (aggregateReferenceWithIdTypeInteger , null , null ));
60
+ Object converted = conversionService .convert (23 , TypeDescriptor .forObject (23 ),
61
+ new TypeDescriptor (aggregateReferenceWithIdTypeInteger , null , null ));
50
62
51
63
assertThat (converted ).isEqualTo (AggregateReference .to (23L ));
52
64
}
53
65
54
- @ Test // # 992
66
+ @ Test // GH- 992
55
67
void convertsFromSimpleValueWithMissingTypeInformation () {
56
68
57
- final Object converted = simpleToAggregate .convert (23 , TypeDescriptor .forObject (23 ), TypeDescriptor .valueOf (AggregateReference .class ));
69
+ Object converted = conversionService .convert (23 , TypeDescriptor .forObject (23 ),
70
+ TypeDescriptor .valueOf (AggregateReference .class ));
58
71
59
72
assertThat (converted ).isEqualTo (AggregateReference .to (23 ));
60
73
}
61
74
62
- @ Test // # 992
75
+ @ Test // GH- 992
63
76
void convertsToSimpleValue () {
64
77
65
- final AggregateReference <Object , Integer > source = AggregateReference .to (23 );
78
+ AggregateReference <Object , Integer > source = AggregateReference .to (23 );
66
79
67
- final Object converted = aggregateToSimple .convert (source , TypeDescriptor .forObject (source ), TypeDescriptor .valueOf (Integer .class ));
80
+ Object converted = conversionService .convert (source , TypeDescriptor .forObject (source ),
81
+ TypeDescriptor .valueOf (Integer .class ));
68
82
69
83
assertThat (converted ).isEqualTo (23 );
70
84
}
71
85
72
- @ Test // # 992
86
+ @ Test // GH- 992
73
87
void convertsToSimpleValueThatNeedsSeparateConversion () {
74
88
75
- final AggregateReference <Object , Integer > source = AggregateReference .to (23 );
89
+ AggregateReference <Object , Integer > source = AggregateReference .to (23 );
76
90
77
- final Object converted = aggregateToSimple .convert (source , TypeDescriptor .forObject (source ), TypeDescriptor .valueOf (Long .class ));
91
+ Object converted = conversionService .convert (source , TypeDescriptor .forObject (source ),
92
+ TypeDescriptor .valueOf (Long .class ));
78
93
79
94
assertThat (converted ).isEqualTo (23L );
80
95
}
81
96
82
-
83
- }
97
+ }
0 commit comments