19
19
20
20
import java .beans .PropertyDescriptor ;
21
21
import java .lang .reflect .Proxy ;
22
+ import java .time .LocalDateTime ;
23
+ import java .util .Calendar ;
22
24
import java .util .Collections ;
25
+ import java .util .Date ;
26
+ import java .util .GregorianCalendar ;
23
27
import java .util .HashMap ;
24
28
import java .util .List ;
25
29
import java .util .Map ;
37
41
* @author Oliver Gierke
38
42
* @author Wim Deblauwe
39
43
* @author Mark Paluch
44
+ * @author Jens Schauder
45
+ * @author Christoph Strobl
40
46
*/
41
47
class ProxyProjectionFactoryUnitTests {
42
48
@@ -276,17 +282,47 @@ void supportsOptionalWithProjectionAsReturnTypeIfPresent() {
276
282
});
277
283
}
278
284
285
+ @ Test // DATACMNS-1836
286
+ void supportsDateToLocalDateTimeConversion () {
287
+
288
+ Customer customer = new Customer ();
289
+ customer .firstname = "Dave" ;
290
+ customer .birthdate = new GregorianCalendar (1967 , Calendar .JANUARY , 9 ).getTime ();
291
+
292
+ customer .address = new Address ();
293
+ customer .address .city = "New York" ;
294
+ customer .address .zipCode = "ZIP" ;
295
+
296
+ CustomerWithLocalDateTime excerpt = factory .createProjection (CustomerWithLocalDateTime .class , customer );
297
+
298
+ assertThat (excerpt .getFirstname ()).isEqualTo ("Dave" );
299
+ assertThat (excerpt .getBirthdate ()).isEqualTo (LocalDateTime .of (1967 , 1 , 9 , 0 , 0 ));
300
+ }
301
+
302
+ @ Test // DATACMNS-1836
303
+ void supportsNullableWrapperDateToLocalDateTimeConversion () {
304
+
305
+ Customer customer = new Customer ();
306
+ customer .firstname = "Dave" ;
307
+ customer .birthdate = new GregorianCalendar (1967 , Calendar .JANUARY , 9 ).getTime ();
308
+
309
+ customer .address = new Address ();
310
+ customer .address .city = "New York" ;
311
+ customer .address .zipCode = "ZIP" ;
312
+
313
+ CustomerWithOptional excerpt = factory .createProjection (CustomerWithOptional .class , customer );
314
+
315
+ assertThat (excerpt .getFirstname ()).isEqualTo ("Dave" );
316
+ assertThat (excerpt .getBirthdate ()).contains (LocalDateTime .of (1967 , 1 , 9 , 0 , 0 ));
317
+ }
318
+
279
319
interface Contact {}
280
320
281
- static class Customer implements Contact {
321
+ interface CustomerWithLocalDateTime {
282
322
283
- Long id ;
284
- String firstname , lastname ;
285
- Address address ;
286
- byte [] picture ;
287
- Address [] shippingAddresses ;
288
- Map <String , Object > data ;
289
- Optional <String > optional ;
323
+ String getFirstname ();
324
+
325
+ LocalDateTime getBirthdate ();
290
326
}
291
327
292
328
static class Address {
@@ -328,6 +364,8 @@ interface CustomerWithOptional {
328
364
Optional <byte []> getPicture ();
329
365
330
366
Optional <String > getOptional ();
367
+
368
+ Optional <LocalDateTime > getBirthdate ();
331
369
}
332
370
333
371
interface CustomerWithOptionalHavingProjection {
@@ -336,4 +374,16 @@ interface CustomerWithOptionalHavingProjection {
336
374
337
375
Optional <AddressExcerpt > getAddress ();
338
376
}
377
+
378
+ static class Customer implements Contact {
379
+
380
+ Long id ;
381
+ String firstname , lastname ;
382
+ Date birthdate ;
383
+ Address address ;
384
+ byte [] picture ;
385
+ Address [] shippingAddresses ;
386
+ Map <String , Object > data ;
387
+ Optional <String > optional ;
388
+ }
339
389
}
0 commit comments