|
3 | 3 | import static dev.openfeature.contrib.providers.flagd.resolver.process.TestUtils.INVALID_CFG;
|
4 | 4 | import static dev.openfeature.contrib.providers.flagd.resolver.process.TestUtils.INVALID_FLAG;
|
5 | 5 | import static dev.openfeature.contrib.providers.flagd.resolver.process.TestUtils.INVALID_FLAG_METADATA;
|
| 6 | +import static dev.openfeature.contrib.providers.flagd.resolver.process.TestUtils.INVALID_FLAG_MULTIPLE_ERRORS; |
6 | 7 | import static dev.openfeature.contrib.providers.flagd.resolver.process.TestUtils.INVALID_FLAG_SET_METADATA;
|
7 | 8 | import static dev.openfeature.contrib.providers.flagd.resolver.process.TestUtils.VALID_FLAG_SET_METADATA;
|
8 | 9 | import static dev.openfeature.contrib.providers.flagd.resolver.process.TestUtils.VALID_LONG;
|
9 | 10 | import static dev.openfeature.contrib.providers.flagd.resolver.process.TestUtils.VALID_SIMPLE;
|
10 | 11 | import static dev.openfeature.contrib.providers.flagd.resolver.process.TestUtils.VALID_SIMPLE_EXTRA_FIELD;
|
11 | 12 | import static dev.openfeature.contrib.providers.flagd.resolver.process.TestUtils.getFlagsFromResource;
|
| 13 | +import static org.assertj.core.api.Assertions.assertThatThrownBy; |
12 | 14 | import static org.junit.jupiter.api.Assertions.assertEquals;
|
13 | 15 | import static org.junit.jupiter.api.Assertions.assertInstanceOf;
|
14 | 16 | import static org.junit.jupiter.api.Assertions.assertNotNull;
|
15 | 17 | import static org.junit.jupiter.api.Assertions.assertNull;
|
16 |
| -import static org.junit.jupiter.api.Assertions.assertThrows; |
17 | 18 |
|
18 | 19 | import java.io.IOException;
|
19 | 20 | import java.util.Map;
|
@@ -135,24 +136,39 @@ void validJsonConfigurationWithFlagMetadataParsing() throws IOException {
|
135 | 136 | @Test
|
136 | 137 | void invalidFlagThrowsError() throws IOException {
|
137 | 138 | String flagString = getFlagsFromResource(INVALID_FLAG);
|
138 |
| - assertThrows(IllegalArgumentException.class, () -> FlagParser.parseString(flagString, true)); |
| 139 | + assertThatThrownBy(() -> FlagParser.parseString(flagString, true)) |
| 140 | + .isInstanceOf(IllegalArgumentException.class); |
139 | 141 | }
|
140 | 142 |
|
141 | 143 | @Test
|
142 | 144 | void invalidFlagMetadataThrowsError() throws IOException {
|
143 | 145 | String flagString = getFlagsFromResource(INVALID_FLAG_METADATA);
|
144 |
| - assertThrows(IllegalArgumentException.class, () -> FlagParser.parseString(flagString, true)); |
| 146 | + assertThatThrownBy(() -> FlagParser.parseString(flagString, true)) |
| 147 | + .isInstanceOf(IllegalArgumentException.class); |
145 | 148 | }
|
146 | 149 |
|
147 | 150 | @Test
|
148 | 151 | void invalidFlagSetMetadataThrowsError() throws IOException {
|
149 | 152 | String flagString = getFlagsFromResource(INVALID_FLAG_SET_METADATA);
|
150 |
| - assertThrows(IllegalArgumentException.class, () -> FlagParser.parseString(flagString, true)); |
| 153 | + assertThatThrownBy(() -> FlagParser.parseString(flagString, true)) |
| 154 | + .isInstanceOf(IllegalArgumentException.class); |
151 | 155 | }
|
152 | 156 |
|
153 | 157 | @Test
|
154 | 158 | void invalidConfigurationsThrowsError() throws IOException {
|
155 | 159 | String flagString = getFlagsFromResource(INVALID_CFG);
|
156 |
| - assertThrows(IllegalArgumentException.class, () -> FlagParser.parseString(flagString, true)); |
| 160 | + assertThatThrownBy(() -> FlagParser.parseString(flagString, true)) |
| 161 | + .isInstanceOf(IllegalArgumentException.class); |
| 162 | + } |
| 163 | + |
| 164 | + @Test |
| 165 | + void invalidWithMulipleErrorsConfigurationsThrowsError() throws IOException { |
| 166 | + String flagString = getFlagsFromResource(INVALID_FLAG_MULTIPLE_ERRORS); |
| 167 | + assertThatThrownBy(() -> FlagParser.parseString(flagString, true)) |
| 168 | + .isInstanceOf(IllegalArgumentException.class) |
| 169 | + .hasMessageContaining("must be valid to one and only one schema") |
| 170 | + .hasMessageContaining("$.flags.myBoolFlag: required property 'defaultVariant' not found") |
| 171 | + .hasMessageContaining("$.flags.myBoolFlag: required property 'state' not found") |
| 172 | + .hasMessageContaining("$.flags.myBoolFlag.metadata.invalid: object found, [string, number, boolean] expected"); |
157 | 173 | }
|
158 | 174 | }
|
0 commit comments