Skip to content

Commit 20b6fee

Browse files
committed
Polish Tests
Issue gh-16251
1 parent fc19bf8 commit 20b6fee

File tree

1 file changed

+9
-17
lines changed

1 file changed

+9
-17
lines changed

oauth2/oauth2-jose/src/test/java/org/springframework/security/oauth2/jwt/NimbusJwtDecoderTests.java

+9-17
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2023 the original author or authors.
2+
* Copyright 2002-2025 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -60,7 +60,6 @@
6060

6161
import org.springframework.cache.Cache;
6262
import org.springframework.cache.concurrent.ConcurrentMapCache;
63-
import org.springframework.cache.support.SimpleValueWrapper;
6463
import org.springframework.core.ParameterizedTypeReference;
6564
import org.springframework.core.convert.converter.Converter;
6665
import org.springframework.http.HttpStatus;
@@ -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, String.class)).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, String.class)).isSameAs(JWK_SET);
810802
verifyNoInteractions(restOperations);
811803

812804
}

0 commit comments

Comments
 (0)