24
24
import java .util .Map ;
25
25
import java .util .Objects ;
26
26
import java .util .Set ;
27
-
28
27
import java .util .UUID ;
29
- import org .junit .jupiter .api .Test ;
30
28
29
+ import org .assertj .core .api .SoftAssertions ;
30
+ import org .junit .jupiter .api .Test ;
31
31
import org .springframework .beans .factory .annotation .Value ;
32
32
import org .springframework .core .convert .TypeDescriptor ;
33
33
import org .springframework .core .convert .converter .Converter ;
52
52
* Unit tests for {@link MappingRelationalConverter}.
53
53
*
54
54
* @author Mark Paluch
55
+ * @author Lukáš Křečan
56
+ * @author Jens Schauder
55
57
*/
56
58
class MappingRelationalConverterUnitTests {
57
59
@@ -92,7 +94,7 @@ void shouldEvaluateExpression() {
92
94
}
93
95
94
96
@ Test
95
- // GH-1689
97
+ // GH-1689
96
98
void shouldApplySimpleTypeConverterSimpleType () {
97
99
98
100
converter = new MappingRelationalConverter (converter .getMappingContext (),
@@ -214,25 +216,24 @@ void projectShouldReadProjectionWithNestedEntity() {
214
216
assertThat (person .getAddresses ()).extracting (Address ::getStreet ).hasSize (1 ).containsOnly ("hwy" );
215
217
}
216
218
217
- @ SuppressWarnings ("unchecked" )
218
- @ Test
219
+ @ Test // GH-1842
219
220
void shouldApplyGenericTypeConverter () {
220
221
221
222
converter = new MappingRelationalConverter (converter .getMappingContext (),
222
- new CustomConversions (StoreConversions .NONE , List .of (GenericTypeConverter .INSTANCE )));
223
+ new CustomConversions (StoreConversions .NONE , List .of (GenericTypeConverter .INSTANCE )));
224
+
225
+ UUID uuid = UUID .randomUUID ();
226
+ GenericClass <UUID > wrappedUuid = new GenericClass <>(uuid );
227
+ GenericClass <String > wrappedString = new GenericClass <>("test" );
223
228
224
- var stringResult = (GenericClass <String >) converter .writeValue ("test" , TypeInformation .of (GenericClass .class ));
225
- var uuidResult = (GenericClass <UUID >) converter .writeValue (UUID .fromString ("1234567-8910-1112-1314-151617181920" ), TypeInformation .of (GenericClass .class ));
229
+ SoftAssertions .assertSoftly (softly -> {
226
230
227
- var stringGeneric = new GenericClass <>("test" );
228
- var stringGenericResult = (String ) converter .writeValue (stringGeneric , TypeInformation .of (String .class ));
229
- var uuidGeneric = new GenericClass <>(UUID .fromString ("1234567-8910-1112-1314-151617181920" ));
230
- var uuidGenericResult = (UUID ) converter .writeValue (uuidGeneric , TypeInformation .of (UUID .class ));
231
+ softly .assertThat (converter .writeValue (uuid , TypeInformation .of (GenericClass .class ))).isEqualTo (wrappedUuid );
232
+ softly .assertThat (converter .writeValue (wrappedUuid , TypeInformation .of (UUID .class ))).isEqualTo (uuid );
231
233
232
- assertThat (stringResult .value ()).isEqualTo ("test" );
233
- assertThat (uuidResult .value ()).isEqualTo (UUID .fromString ("1234567-8910-1112-1314-151617181920" ));
234
- assertThat (stringGenericResult ).isEqualTo ("test" );
235
- assertThat (uuidGenericResult ).isEqualTo (UUID .fromString ("1234567-8910-1112-1314-151617181920" ));
234
+ softly .assertThat (converter .writeValue ("test" , TypeInformation .of (GenericClass .class ))).isEqualTo (wrappedString );
235
+ softly .assertThat (converter .writeValue (wrappedString , TypeInformation .of (String .class ))).isEqualTo ("test" );
236
+ });
236
237
}
237
238
238
239
static class SimpleType {
@@ -397,12 +398,9 @@ enum GenericTypeConverter implements GenericConverter {
397
398
398
399
@ Override
399
400
public Set <ConvertiblePair > getConvertibleTypes () {
400
- return Set .of (
401
- new ConvertiblePair (String .class , GenericClass .class ),
402
- new ConvertiblePair (UUID .class , GenericClass .class ),
403
- new ConvertiblePair (GenericClass .class , String .class ),
404
- new ConvertiblePair (GenericClass .class , UUID .class )
405
- );
401
+ return Set .of (new ConvertiblePair (String .class , GenericClass .class ),
402
+ new ConvertiblePair (UUID .class , GenericClass .class ), new ConvertiblePair (GenericClass .class , String .class ),
403
+ new ConvertiblePair (GenericClass .class , UUID .class ));
406
404
}
407
405
408
406
@ Override
@@ -415,6 +413,7 @@ public Object convert(Object source, TypeDescriptor sourceType, TypeDescriptor t
415
413
416
414
}
417
415
418
- public record GenericClass <T >(T value ) { }
416
+ public record GenericClass <T >(T value ) {
417
+ }
419
418
420
419
}
0 commit comments