@@ -311,18 +311,18 @@ void redisSessionGetAttributes() {
311
311
}
312
312
313
313
@ Test
314
- @ SuppressWarnings ("unchecked" )
315
314
void delete () {
316
315
String attrName = "attrName" ;
317
316
MapSession expected = new MapSession ();
318
317
expected .setLastAccessedTime (Instant .now ().minusSeconds (60 ));
319
318
expected .setAttribute (attrName , "attrValue" );
320
319
given (this .redisOperations .<String , Object >boundHashOps (anyString ())).willReturn (this .boundHashOperations );
321
320
given (this .redisOperations .boundSetOps (anyString ())).willReturn (this .boundSetOperations );
322
- Map map = map (RedisIndexedSessionRepository .getSessionAttrNameKey (attrName ), expected .getAttribute (attrName ),
323
- RedisSessionMapper .CREATION_TIME_KEY , expected .getCreationTime ().toEpochMilli (),
324
- RedisSessionMapper .MAX_INACTIVE_INTERVAL_KEY , (int ) expected .getMaxInactiveInterval ().getSeconds (),
325
- RedisSessionMapper .LAST_ACCESSED_TIME_KEY , expected .getLastAccessedTime ().toEpochMilli ());
321
+ Map <String , Object > map = map (RedisIndexedSessionRepository .getSessionAttrNameKey (attrName ),
322
+ expected .getAttribute (attrName ), RedisSessionMapper .CREATION_TIME_KEY ,
323
+ expected .getCreationTime ().toEpochMilli (), RedisSessionMapper .MAX_INACTIVE_INTERVAL_KEY ,
324
+ (int ) expected .getMaxInactiveInterval ().getSeconds (), RedisSessionMapper .LAST_ACCESSED_TIME_KEY ,
325
+ expected .getLastAccessedTime ().toEpochMilli ());
326
326
given (this .boundHashOperations .entries ()).willReturn (map );
327
327
given (this .redisOperations .boundSetOps (anyString ())).willReturn (this .boundSetOperations );
328
328
@@ -345,7 +345,6 @@ void deleteNullSession() {
345
345
}
346
346
347
347
@ Test
348
- @ SuppressWarnings ("unchecked" )
349
348
void getSessionNotFound () {
350
349
String id = "abc" ;
351
350
given (this .redisOperations .<String , Object >boundHashOps (getKey (id ))).willReturn (this .boundHashOperations );
@@ -355,7 +354,6 @@ void getSessionNotFound() {
355
354
}
356
355
357
356
@ Test
358
- @ SuppressWarnings ("unchecked" )
359
357
void getSessionFound () {
360
358
String attribute1 = "attribute1" ;
361
359
String attribute2 = "attribute2" ;
@@ -365,7 +363,7 @@ void getSessionFound() {
365
363
expected .setAttribute (attribute2 , null );
366
364
given (this .redisOperations .<String , Object >boundHashOps (getKey (expected .getId ())))
367
365
.willReturn (this .boundHashOperations );
368
- Map map = map (RedisIndexedSessionRepository .getSessionAttrNameKey (attribute1 ),
366
+ Map < String , Object > map = map (RedisIndexedSessionRepository .getSessionAttrNameKey (attribute1 ),
369
367
expected .getAttribute (attribute1 ), RedisIndexedSessionRepository .getSessionAttrNameKey (attribute2 ),
370
368
expected .getAttribute (attribute2 ), RedisSessionMapper .CREATION_TIME_KEY ,
371
369
expected .getCreationTime ().toEpochMilli (), RedisSessionMapper .MAX_INACTIVE_INTERVAL_KEY ,
@@ -386,27 +384,27 @@ void getSessionFound() {
386
384
}
387
385
388
386
@ Test
389
- @ SuppressWarnings ("unchecked" )
390
387
void getSessionExpired () {
391
388
String expiredId = "expired-id" ;
392
389
given (this .redisOperations .<String , Object >boundHashOps (getKey (expiredId )))
393
390
.willReturn (this .boundHashOperations );
394
- Map map = map (RedisSessionMapper .MAX_INACTIVE_INTERVAL_KEY , 1 , RedisSessionMapper .LAST_ACCESSED_TIME_KEY ,
391
+ Map <String , Object > map = map (RedisSessionMapper .CREATION_TIME_KEY , Instant .EPOCH .toEpochMilli (),
392
+ RedisSessionMapper .MAX_INACTIVE_INTERVAL_KEY , 1 , RedisSessionMapper .LAST_ACCESSED_TIME_KEY ,
395
393
Instant .now ().minus (5 , ChronoUnit .MINUTES ).toEpochMilli ());
396
394
given (this .boundHashOperations .entries ()).willReturn (map );
397
395
398
396
assertThat (this .redisRepository .findById (expiredId )).isNull ();
399
397
}
400
398
401
399
@ Test
402
- @ SuppressWarnings ("unchecked" )
403
400
void findByPrincipalNameExpired () {
404
401
String expiredId = "expired-id" ;
405
402
given (this .redisOperations .boundSetOps (anyString ())).willReturn (this .boundSetOperations );
406
403
given (this .boundSetOperations .members ()).willReturn (Collections .singleton (expiredId ));
407
404
given (this .redisOperations .<String , Object >boundHashOps (getKey (expiredId )))
408
405
.willReturn (this .boundHashOperations );
409
- Map map = map (RedisSessionMapper .MAX_INACTIVE_INTERVAL_KEY , 1 , RedisSessionMapper .LAST_ACCESSED_TIME_KEY ,
406
+ Map <String , Object > map = map (RedisSessionMapper .CREATION_TIME_KEY , Instant .EPOCH .toEpochMilli (),
407
+ RedisSessionMapper .MAX_INACTIVE_INTERVAL_KEY , 1 , RedisSessionMapper .LAST_ACCESSED_TIME_KEY ,
410
408
Instant .now ().minus (5 , ChronoUnit .MINUTES ).toEpochMilli ());
411
409
given (this .boundHashOperations .entries ()).willReturn (map );
412
410
@@ -416,7 +414,6 @@ void findByPrincipalNameExpired() {
416
414
}
417
415
418
416
@ Test
419
- @ SuppressWarnings ("unchecked" )
420
417
void findByPrincipalName () {
421
418
Instant lastAccessed = Instant .now ().minusMillis (10 );
422
419
Instant createdTime = lastAccessed .minusMillis (10 );
@@ -426,7 +423,7 @@ void findByPrincipalName() {
426
423
given (this .boundSetOperations .members ()).willReturn (Collections .singleton (sessionId ));
427
424
given (this .redisOperations .<String , Object >boundHashOps (getKey (sessionId )))
428
425
.willReturn (this .boundHashOperations );
429
- Map map = map (RedisSessionMapper .CREATION_TIME_KEY , createdTime .toEpochMilli (),
426
+ Map < String , Object > map = map (RedisSessionMapper .CREATION_TIME_KEY , createdTime .toEpochMilli (),
430
427
RedisSessionMapper .MAX_INACTIVE_INTERVAL_KEY , (int ) maxInactive .getSeconds (),
431
428
RedisSessionMapper .LAST_ACCESSED_TIME_KEY , lastAccessed .toEpochMilli ());
432
429
given (this .boundHashOperations .entries ()).willReturn (map );
@@ -468,7 +465,10 @@ void onMessageCreated() {
468
465
String channel = "spring:session:event:0:created:" + session .getId ();
469
466
JdkSerializationRedisSerializer defaultSerailizer = new JdkSerializationRedisSerializer ();
470
467
this .redisRepository .setDefaultSerializer (defaultSerailizer );
471
- byte [] body = defaultSerailizer .serialize (new HashMap ());
468
+ Map <String , Object > map = map (RedisSessionMapper .CREATION_TIME_KEY , Instant .EPOCH .toEpochMilli (),
469
+ RedisSessionMapper .MAX_INACTIVE_INTERVAL_KEY , 0 , RedisSessionMapper .LAST_ACCESSED_TIME_KEY ,
470
+ System .currentTimeMillis () - TimeUnit .MINUTES .toMillis (5 ));
471
+ byte [] body = defaultSerailizer .serialize (map );
472
472
DefaultMessage message = new DefaultMessage (channel .getBytes (StandardCharsets .UTF_8 ), body );
473
473
474
474
this .redisRepository .setApplicationEventPublisher (this .publisher );
@@ -485,7 +485,10 @@ void onMessageCreatedCustomSerializer() {
485
485
byte [] pattern = "" .getBytes (StandardCharsets .UTF_8 );
486
486
byte [] body = new byte [0 ];
487
487
String channel = "spring:session:event:0:created:" + session .getId ();
488
- given (this .defaultSerializer .deserialize (body )).willReturn (new HashMap <String , Object >());
488
+ Map <String , Object > map = map (RedisSessionMapper .CREATION_TIME_KEY , Instant .EPOCH .toEpochMilli (),
489
+ RedisSessionMapper .MAX_INACTIVE_INTERVAL_KEY , 0 , RedisSessionMapper .LAST_ACCESSED_TIME_KEY ,
490
+ System .currentTimeMillis () - TimeUnit .MINUTES .toMillis (5 ));
491
+ given (this .defaultSerializer .deserialize (body )).willReturn (map );
489
492
DefaultMessage message = new DefaultMessage (channel .getBytes (StandardCharsets .UTF_8 ), body );
490
493
this .redisRepository .setApplicationEventPublisher (this .publisher );
491
494
@@ -497,12 +500,12 @@ void onMessageCreatedCustomSerializer() {
497
500
}
498
501
499
502
@ Test
500
- @ SuppressWarnings ("unchecked" )
501
503
void onMessageDeletedSessionFound () {
502
504
String deletedId = "deleted-id" ;
503
505
given (this .redisOperations .<String , Object >boundHashOps (getKey (deletedId )))
504
506
.willReturn (this .boundHashOperations );
505
- Map map = map (RedisSessionMapper .MAX_INACTIVE_INTERVAL_KEY , 0 , RedisSessionMapper .LAST_ACCESSED_TIME_KEY ,
507
+ Map <String , Object > map = map (RedisSessionMapper .CREATION_TIME_KEY , Instant .EPOCH .toEpochMilli (),
508
+ RedisSessionMapper .MAX_INACTIVE_INTERVAL_KEY , 0 , RedisSessionMapper .LAST_ACCESSED_TIME_KEY ,
506
509
System .currentTimeMillis () - TimeUnit .MINUTES .toMillis (5 ));
507
510
given (this .boundHashOperations .entries ()).willReturn (map );
508
511
@@ -525,7 +528,6 @@ void onMessageDeletedSessionFound() {
525
528
}
526
529
527
530
@ Test
528
- @ SuppressWarnings ("unchecked" )
529
531
void onMessageDeletedSessionNotFound () {
530
532
String deletedId = "deleted-id" ;
531
533
given (this .redisOperations .<String , Object >boundHashOps (getKey (deletedId )))
@@ -549,12 +551,12 @@ void onMessageDeletedSessionNotFound() {
549
551
}
550
552
551
553
@ Test
552
- @ SuppressWarnings ("unchecked" )
553
554
void onMessageExpiredSessionFound () {
554
555
String expiredId = "expired-id" ;
555
556
given (this .redisOperations .<String , Object >boundHashOps (getKey (expiredId )))
556
557
.willReturn (this .boundHashOperations );
557
- Map map = map (RedisSessionMapper .MAX_INACTIVE_INTERVAL_KEY , 1 , RedisSessionMapper .LAST_ACCESSED_TIME_KEY ,
558
+ Map <String , Object > map = map (RedisSessionMapper .CREATION_TIME_KEY , Instant .EPOCH .toEpochMilli (),
559
+ RedisSessionMapper .MAX_INACTIVE_INTERVAL_KEY , 1 , RedisSessionMapper .LAST_ACCESSED_TIME_KEY ,
558
560
System .currentTimeMillis () - TimeUnit .MINUTES .toMillis (5 ));
559
561
given (this .boundHashOperations .entries ()).willReturn (map );
560
562
@@ -577,7 +579,6 @@ void onMessageExpiredSessionFound() {
577
579
}
578
580
579
581
@ Test
580
- @ SuppressWarnings ("unchecked" )
581
582
void onMessageExpiredSessionNotFound () {
582
583
String expiredId = "expired-id" ;
583
584
given (this .redisOperations .<String , Object >boundHashOps (getKey (expiredId )))
@@ -813,7 +814,7 @@ void onMessageCreatedInOtherDatabase() {
813
814
814
815
MapSession session = this .cached ;
815
816
String channel = "spring:session:event:created:1:" + session .getId ();
816
- byte [] body = serializer .serialize (new HashMap ());
817
+ byte [] body = serializer .serialize (new HashMap <> ());
817
818
DefaultMessage message = new DefaultMessage (channel .getBytes (StandardCharsets .UTF_8 ), body );
818
819
819
820
this .redisRepository .onMessage (message , "" .getBytes (StandardCharsets .UTF_8 ));
@@ -913,7 +914,7 @@ private String getKey(String id) {
913
914
return "spring:session:sessions:" + id ;
914
915
}
915
916
916
- private Map map (Object ... objects ) {
917
+ private Map < String , Object > map (Object ... objects ) {
917
918
Map <String , Object > result = new HashMap <>();
918
919
if (objects == null ) {
919
920
return result ;
0 commit comments