19
19
import static org .mockito .ArgumentMatchers .*;
20
20
import static org .mockito .Mockito .*;
21
21
22
- import java .text .DateFormat ;
23
- import java .text .Format ;
24
- import java .text .SimpleDateFormat ;
25
22
import java .util .Arrays ;
26
23
import java .util .Collections ;
27
24
import java .util .Date ;
33
30
import org .jmolecules .ddd .types .Identifier ;
34
31
import org .joda .time .DateTime ;
35
32
import org .junit .jupiter .api .Test ;
33
+
36
34
import org .springframework .aop .framework .ProxyFactory ;
37
35
import org .springframework .core .convert .converter .Converter ;
38
36
import org .springframework .core .convert .converter .ConverterFactory ;
48
46
import org .springframework .data .convert .ThreeTenBackPortConverters .LocalDateTimeToJavaTimeInstantConverter ;
49
47
import org .springframework .data .geo .Point ;
50
48
import org .springframework .data .mapping .model .SimpleTypeHolder ;
49
+
51
50
import org .threeten .bp .LocalDateTime ;
52
51
53
52
/**
@@ -163,8 +162,8 @@ void shouldSelectPropertCustomWriteTargetForCglibProxiedType() {
163
162
void shouldSelectPropertCustomReadTargetForCglibProxiedType () {
164
163
165
164
CustomConversions conversions = new CustomConversions (StoreConversions .NONE ,
166
- Arrays .asList (CustomObjectToStringConverter .INSTANCE ));
167
- assertThat (conversions .hasCustomReadTarget (createProxyTypeFor (Object .class ), String .class )).isTrue ();
165
+ Arrays .asList (CustomTypeToStringConverter .INSTANCE ));
166
+ assertThat (conversions .hasCustomReadTarget (createProxyTypeFor (CustomType .class ), String .class )).isTrue ();
168
167
}
169
168
170
169
@ Test // DATAMONGO-1131, DATACMNS-1035
@@ -316,7 +315,7 @@ enum StringToFormatConverter implements Converter<String, Format> {
316
315
INSTANCE ;
317
316
318
317
public Format convert (String source ) {
319
- return DateFormat . getInstance ();
318
+ return new DateFormat ();
320
319
}
321
320
}
322
321
@@ -367,12 +366,13 @@ public Date convert(DateTime source) {
367
366
}
368
367
}
369
368
370
- enum CustomObjectToStringConverter implements Converter <Object , String > {
369
+ @ ReadingConverter
370
+ enum CustomTypeToStringConverter implements Converter <CustomType , String > {
371
371
372
372
INSTANCE ;
373
373
374
374
@ Override
375
- public String convert (Object source ) {
375
+ public String convert (CustomType source ) {
376
376
return source != null ? source .toString () : null ;
377
377
}
378
378
@@ -414,7 +414,7 @@ public T convert(String source) {
414
414
}
415
415
416
416
try {
417
- return targetType .newInstance ();
417
+ return targetType .getDeclaredConstructor (). newInstance ();
418
418
} catch (Exception e ) {
419
419
throw new IllegalArgumentException (e .getMessage (), e );
420
420
}
@@ -423,4 +423,11 @@ public T convert(String source) {
423
423
}
424
424
425
425
static class CustomType {}
426
+
427
+ static class Format {}
428
+
429
+ static class DateFormat extends Format {}
430
+
431
+ static class SimpleDateFormat extends DateFormat {}
432
+
426
433
}
0 commit comments