|
1 | 1 | /*
|
2 |
| - * Copyright 2002-2018 the original author or authors. |
| 2 | + * Copyright 2002-2019 the original author or authors. |
3 | 3 | *
|
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License");
|
5 | 5 | * you may not use this file except in compliance with the License.
|
|
19 | 19 | import org.junit.Test;
|
20 | 20 |
|
21 | 21 | import java.time.Instant;
|
| 22 | +import java.util.Arrays; |
22 | 23 | import java.util.Date;
|
23 | 24 | import java.util.HashMap;
|
| 25 | +import java.util.List; |
24 | 26 | import java.util.Map;
|
25 | 27 |
|
26 | 28 | import static org.assertj.core.api.Assertions.assertThat;
|
| 29 | +import static org.assertj.core.api.Assertions.catchThrowable; |
27 | 30 |
|
28 | 31 | /**
|
29 | 32 | * Tests for {@link ClaimAccessor}.
|
@@ -101,4 +104,44 @@ public void getClaimAsStringWhenValueIsNullThenReturnNull() {
|
101 | 104 |
|
102 | 105 | assertThat(this.claimAccessor.getClaimAsString(claimName)).isNull();
|
103 | 106 | }
|
| 107 | + |
| 108 | + @Test |
| 109 | + public void getClaimWhenNotExistingThenReturnNull() { |
| 110 | + String claimName = "list"; |
| 111 | + List<String> actualClaimValue = this.claimAccessor.getClaim(claimName); |
| 112 | + assertThat(actualClaimValue).isNull(); |
| 113 | + } |
| 114 | + |
| 115 | + @Test |
| 116 | + public void getClaimWhenValueIsConvertedThenReturnList() { |
| 117 | + List<String> expectedClaimValue = Arrays.asList("item1", "item2"); |
| 118 | + String claimName = "list"; |
| 119 | + this.claims.put(claimName, expectedClaimValue); |
| 120 | + |
| 121 | + List<String> actualClaimValue = this.claimAccessor.getClaim(claimName); |
| 122 | + |
| 123 | + assertThat(actualClaimValue).containsOnlyElementsOf(expectedClaimValue); |
| 124 | + } |
| 125 | + |
| 126 | + @Test |
| 127 | + public void getClaimWhenValueIsConvertedThenReturnBoolean() { |
| 128 | + boolean expectedClaimValue = true; |
| 129 | + String claimName = "boolean"; |
| 130 | + this.claims.put(claimName, expectedClaimValue); |
| 131 | + |
| 132 | + boolean actualClaimValue = this.claimAccessor.getClaim(claimName); |
| 133 | + |
| 134 | + assertThat(actualClaimValue).isEqualTo(expectedClaimValue); |
| 135 | + } |
| 136 | + |
| 137 | + @Test |
| 138 | + public void getClaimWhenValueIsNotConvertedThenThrowClassCastException() { |
| 139 | + String expectedClaimValue = "true"; |
| 140 | + String claimName = "boolean"; |
| 141 | + this.claims.put(claimName, expectedClaimValue); |
| 142 | + |
| 143 | + Throwable thrown = catchThrowable(() -> { boolean actualClaimValue = this.claimAccessor.getClaim(claimName); }); |
| 144 | + |
| 145 | + assertThat(thrown).isInstanceOf(ClassCastException.class); |
| 146 | + } |
104 | 147 | }
|
0 commit comments