6060
6161import org .springframework .cache .Cache ;
6262import org .springframework .cache .concurrent .ConcurrentMapCache ;
63- import org .springframework .cache .support .SimpleValueWrapper ;
6463import org .springframework .core .ParameterizedTypeReference ;
6564import org .springframework .core .convert .converter .Converter ;
6665import org .springframework .http .HttpStatus ;
@@ -664,7 +663,7 @@ public void decodeWhenCacheThenStoreRetrievedJwkSetToCache() {
664663 .build ();
665664 // @formatter:on
666665 jwtDecoder .decode (SIGNED_JWT );
667- assertThat (cache .get (JWK_SET_URI , String . class )).isEqualTo (JWK_SET );
666+ assertThat (cache .get (JWK_SET_URI ). get ( )).isEqualTo (JWK_SET );
668667 ArgumentCaptor <RequestEntity > requestEntityCaptor = ArgumentCaptor .forClass (RequestEntity .class );
669668 verify (restOperations ).exchange (requestEntityCaptor .capture (), eq (String .class ));
670669 verifyNoMoreInteractions (restOperations );
@@ -685,7 +684,7 @@ public void decodeWhenCacheStoredThenAbleToRetrieveJwkSetFromCache() {
685684 .build ();
686685 // @formatter:on
687686 jwtDecoder1 .decode (SIGNED_JWT );
688- assertThat (cache .get (JWK_SET_URI , String . class )).isEqualTo (JWK_SET );
687+ assertThat (cache .get (JWK_SET_URI ). get ( )).isEqualTo (JWK_SET );
689688 verify (restOperations ).exchange (any (RequestEntity .class ), eq (String .class ));
690689
691690 // @formatter:off
@@ -702,29 +701,25 @@ public void decodeWhenCacheStoredThenAbleToRetrieveJwkSetFromCache() {
702701 @ Test
703702 public void decodeWhenCacheThenRetrieveFromCache () throws Exception {
704703 RestOperations restOperations = mock (RestOperations .class );
705- Cache cache = mock (Cache .class );
706- given (cache .get (eq (JWK_SET_URI ), eq (String .class ))).willReturn (JWK_SET );
707- given (cache .get (eq (JWK_SET_URI ))).willReturn (mock (Cache .ValueWrapper .class ));
704+ Cache cache = new ConcurrentMapCache ("cache" );
705+ cache .put (JWK_SET_URI , JWK_SET );
708706 // @formatter:off
709707 NimbusJwtDecoder jwtDecoder = NimbusJwtDecoder .withJwkSetUri (JWK_SET_URI )
710708 .cache (cache )
711709 .restOperations (restOperations )
712710 .build ();
713711 // @formatter:on
714712 jwtDecoder .decode (SIGNED_JWT );
715- verify (cache ).get (eq (JWK_SET_URI ), eq (String .class ));
716- verify (cache , times (2 )).get (eq (JWK_SET_URI ));
717- verifyNoMoreInteractions (cache );
713+ assertThat (cache .get (JWK_SET_URI ).get ()).isSameAs (JWK_SET );
718714 verifyNoInteractions (restOperations );
719715 }
720716
721717 // gh-11621
722718 @ Test
723719 public void decodeWhenCacheAndUnknownKidShouldTriggerFetchOfJwkSet () throws JOSEException {
724720 RestOperations restOperations = mock (RestOperations .class );
725- Cache cache = mock (Cache .class );
726- given (cache .get (eq (JWK_SET_URI ), eq (String .class ))).willReturn (JWK_SET );
727- given (cache .get (eq (JWK_SET_URI ))).willReturn (new SimpleValueWrapper (JWK_SET ));
721+ Cache cache = new ConcurrentMapCache ("cache" );
722+ cache .put (JWK_SET_URI , JWK_SET );
728723 given (restOperations .exchange (any (RequestEntity .class ), eq (String .class )))
729724 .willReturn (new ResponseEntity <>(NEW_KID_JWK_SET , HttpStatus .OK ));
730725
@@ -794,19 +789,16 @@ public void decodeWhenCacheIsConfiguredAndValueLoaderErrorsThenThrowsJwtExceptio
794789 @ Test
795790 public void decodeWhenCacheIsConfiguredAndParseFailsOnCachedValueThenExceptionIgnored () {
796791 RestOperations restOperations = mock (RestOperations .class );
797- Cache cache = mock (Cache .class );
798- given (cache .get (eq (JWK_SET_URI ), eq (String .class ))).willReturn (JWK_SET );
799- given (cache .get (eq (JWK_SET_URI ))).willReturn (mock (Cache .ValueWrapper .class ));
792+ Cache cache = new ConcurrentMapCache ("cache" );
793+ cache .put (JWK_SET_URI , JWK_SET );
800794 // @formatter:off
801795 NimbusJwtDecoder jwtDecoder = NimbusJwtDecoder .withJwkSetUri (JWK_SET_URI )
802796 .cache (cache )
803797 .restOperations (restOperations )
804798 .build ();
805799 // @formatter:on
806800 jwtDecoder .decode (SIGNED_JWT );
807- verify (cache ).get (eq (JWK_SET_URI ), eq (String .class ));
808- verify (cache , times (2 )).get (eq (JWK_SET_URI ));
809- verifyNoMoreInteractions (cache );
801+ assertThat (cache .get (JWK_SET_URI ).get ()).isSameAs (JWK_SET );
810802 verifyNoInteractions (restOperations );
811803
812804 }
0 commit comments