|
1 | 1 | /*
|
2 |
| - * Copyright 2002-2019 the original author or authors. |
| 2 | + * Copyright 2002-2021 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.
|
|
18 | 18 |
|
19 | 19 | import java.time.Instant;
|
20 | 20 | import java.util.Arrays;
|
| 21 | +import java.util.Collections; |
21 | 22 | import java.util.Date;
|
22 | 23 | import java.util.HashMap;
|
23 | 24 | import java.util.List;
|
|
27 | 28 | import org.junit.jupiter.api.Test;
|
28 | 29 |
|
29 | 30 | import static org.assertj.core.api.Assertions.assertThat;
|
| 31 | +import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException; |
| 32 | +import static org.assertj.core.api.Assertions.assertThatNullPointerException; |
30 | 33 | import static org.assertj.core.api.Assertions.assertThatObject;
|
31 | 34 |
|
32 | 35 | /**
|
@@ -102,6 +105,61 @@ public void getClaimAsStringWhenValueIsNullThenReturnNull() {
|
102 | 105 | assertThat(this.claimAccessor.getClaimAsString(claimName)).isNull();
|
103 | 106 | }
|
104 | 107 |
|
| 108 | + @Test |
| 109 | + public void getClaimAsMapWhenNotExistingThenReturnNull() { |
| 110 | + assertThat(this.claimAccessor.getClaimAsMap("map")).isNull(); |
| 111 | + } |
| 112 | + |
| 113 | + @Test |
| 114 | + public void getClaimAsMapWhenMapTypeThenReturnMap() { |
| 115 | + Map<Object, Object> expectedClaimValue = Collections.emptyMap(); |
| 116 | + String claimName = "map"; |
| 117 | + this.claims.put(claimName, expectedClaimValue); |
| 118 | + assertThat(this.claimAccessor.getClaimAsMap(claimName)).isEqualTo(expectedClaimValue); |
| 119 | + } |
| 120 | + |
| 121 | + @Test |
| 122 | + public void getClaimAsMapWhenValueIsNullThenThrowNullPointerException() { |
| 123 | + String claimName = "map"; |
| 124 | + this.claims.put(claimName, null); |
| 125 | + assertThatNullPointerException().isThrownBy(() -> this.claimAccessor.getClaimAsMap(claimName)); |
| 126 | + } |
| 127 | + |
| 128 | + @Test |
| 129 | + public void getClaimAsMapWhenNonMapTypeThenThrowIllegalArgumentException() { |
| 130 | + String claimName = "map"; |
| 131 | + this.claims.put(claimName, "map"); |
| 132 | + assertThatIllegalArgumentException().isThrownBy(() -> this.claimAccessor.getClaimAsMap(claimName)); |
| 133 | + } |
| 134 | + |
| 135 | + @Test |
| 136 | + public void getClaimAsStringListWhenNotExistingThenReturnNull() { |
| 137 | + assertThat(this.claimAccessor.getClaimAsStringList("list")).isNull(); |
| 138 | + } |
| 139 | + |
| 140 | + @Test |
| 141 | + public void getClaimAsStringListWhenStringListTypeThenReturnList() { |
| 142 | + List<String> expectedClaimValue = Collections.emptyList(); |
| 143 | + String claimName = "list"; |
| 144 | + this.claims.put(claimName, expectedClaimValue); |
| 145 | + assertThat(this.claimAccessor.getClaimAsStringList(claimName)).isEqualTo(expectedClaimValue); |
| 146 | + } |
| 147 | + |
| 148 | + @Test |
| 149 | + public void getClaimAsStringListWhenNonListTypeThenReturnList() { |
| 150 | + List<String> expectedClaimValue = Collections.singletonList("list"); |
| 151 | + String claimName = "list"; |
| 152 | + this.claims.put(claimName, expectedClaimValue.get(0)); |
| 153 | + assertThat(this.claimAccessor.getClaimAsStringList(claimName)).isEqualTo(expectedClaimValue); |
| 154 | + } |
| 155 | + |
| 156 | + @Test |
| 157 | + public void getClaimAsStringListWhenValueIsNullThenNullPointerException() { |
| 158 | + String claimName = "list"; |
| 159 | + this.claims.put(claimName, null); |
| 160 | + assertThatNullPointerException().isThrownBy(() -> this.claimAccessor.getClaimAsStringList(claimName)); |
| 161 | + } |
| 162 | + |
105 | 163 | @Test
|
106 | 164 | public void getClaimWhenNotExistingThenReturnNull() {
|
107 | 165 | String claimName = "list";
|
|
0 commit comments