claimNameToConverter.putAll(claimConverters); return new MappedJwtClaimSetConverter(claimNameToConverter);
@Test public void convertWhenUsingConstructorThenOnlyConvertersInThatMapAreUsedForConversion() { Converter<Object, String> claimConverter = mock(Converter.class); MappedJwtClaimSetConverter converter = new MappedJwtClaimSetConverter( Collections.singletonMap(JwtClaimNames.SUB, claimConverter)); when(claimConverter.convert(any(Object.class))).thenReturn("1234"); Map<String, Object> source = new HashMap<>(); source.put(JwtClaimNames.JTI, new Object()); source.put(JwtClaimNames.AUD, new Object()); source.put(JwtClaimNames.EXP, Instant.ofEpochSecond(1L)); source.put(JwtClaimNames.IAT, Instant.ofEpochSecond(1L)); source.put(JwtClaimNames.ISS, new Object()); source.put(JwtClaimNames.NBF, new Object()); source.put(JwtClaimNames.SUB, new Object()); Map<String, Object> target = converter.convert(source); assertThat(target.get(JwtClaimNames.JTI)).isEqualTo(source.get(JwtClaimNames.JTI)); assertThat(target.get(JwtClaimNames.AUD)).isEqualTo(source.get(JwtClaimNames.AUD)); assertThat(target.get(JwtClaimNames.EXP)).isEqualTo(source.get(JwtClaimNames.EXP)); assertThat(target.get(JwtClaimNames.IAT)).isEqualTo(source.get(JwtClaimNames.IAT)); assertThat(target.get(JwtClaimNames.ISS)).isEqualTo(source.get(JwtClaimNames.ISS)); assertThat(target.get(JwtClaimNames.NBF)).isEqualTo(source.get(JwtClaimNames.NBF)); assertThat(target.get(JwtClaimNames.SUB)).isEqualTo("1234"); }
@Test public void constructWhenAnyParameterIsNullThenIllegalArgumentException() { assertThatCode(() -> new MappedJwtClaimSetConverter(null)) .isInstanceOf(IllegalArgumentException.class); }
claimNameToConverter.putAll(claimConverters); return new MappedJwtClaimSetConverter(claimNameToConverter);