2424import java .util .Map ;
2525import java .util .Objects ;
2626import java .util .Set ;
27-
2827import java .util .UUID ;
29- import org .junit .jupiter .api .Test ;
3028
29+ import org .assertj .core .api .SoftAssertions ;
30+ import org .junit .jupiter .api .Test ;
3131import org .springframework .beans .factory .annotation .Value ;
3232import org .springframework .core .convert .TypeDescriptor ;
3333import org .springframework .core .convert .converter .Converter ;
5252 * Unit tests for {@link MappingRelationalConverter}.
5353 *
5454 * @author Mark Paluch
55+ * @author Lukáš Křečan
56+ * @author Jens Schauder
5557 */
5658class MappingRelationalConverterUnitTests {
5759
@@ -92,7 +94,7 @@ void shouldEvaluateExpression() {
9294 }
9395
9496 @ Test
95- // GH-1689
97+ // GH-1689
9698 void shouldApplySimpleTypeConverterSimpleType () {
9799
98100 converter = new MappingRelationalConverter (converter .getMappingContext (),
@@ -214,25 +216,24 @@ void projectShouldReadProjectionWithNestedEntity() {
214216 assertThat (person .getAddresses ()).extracting (Address ::getStreet ).hasSize (1 ).containsOnly ("hwy" );
215217 }
216218
217- @ SuppressWarnings ("unchecked" )
218- @ Test
219+ @ Test // GH-1842
219220 void shouldApplyGenericTypeConverter () {
220221
221222 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" );
223228
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 -> {
226230
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 );
231233
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+ });
236237 }
237238
238239 static class SimpleType {
@@ -397,12 +398,9 @@ enum GenericTypeConverter implements GenericConverter {
397398
398399 @ Override
399400 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 ));
406404 }
407405
408406 @ Override
@@ -415,6 +413,7 @@ public Object convert(Object source, TypeDescriptor sourceType, TypeDescriptor t
415413
416414 }
417415
418- public record GenericClass <T >(T value ) { }
416+ public record GenericClass <T >(T value ) {
417+ }
419418
420419}
0 commit comments