|
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,36 @@ 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)).isInstanceOf(IllegalArgumentException.class); |
139 | 140 | }
|
140 | 141 |
|
141 | 142 | @Test
|
142 | 143 | void invalidFlagMetadataThrowsError() throws IOException {
|
143 | 144 | String flagString = getFlagsFromResource(INVALID_FLAG_METADATA);
|
144 |
| - assertThrows(IllegalArgumentException.class, () -> FlagParser.parseString(flagString, true)); |
| 145 | + assertThatThrownBy(() -> FlagParser.parseString(flagString, true)).isInstanceOf(IllegalArgumentException.class); |
145 | 146 | }
|
146 | 147 |
|
147 | 148 | @Test
|
148 | 149 | void invalidFlagSetMetadataThrowsError() throws IOException {
|
149 | 150 | String flagString = getFlagsFromResource(INVALID_FLAG_SET_METADATA);
|
150 |
| - assertThrows(IllegalArgumentException.class, () -> FlagParser.parseString(flagString, true)); |
| 151 | + assertThatThrownBy(() -> FlagParser.parseString(flagString, true)).isInstanceOf(IllegalArgumentException.class); |
151 | 152 | }
|
152 | 153 |
|
153 | 154 | @Test
|
154 | 155 | void invalidConfigurationsThrowsError() throws IOException {
|
155 | 156 | String flagString = getFlagsFromResource(INVALID_CFG);
|
156 |
| - assertThrows(IllegalArgumentException.class, () -> FlagParser.parseString(flagString, true)); |
| 157 | + assertThatThrownBy(() -> FlagParser.parseString(flagString, true)).isInstanceOf(IllegalArgumentException.class); |
| 158 | + } |
| 159 | + |
| 160 | + @Test |
| 161 | + void invalidWithMulipleErrorsConfigurationsThrowsError() throws IOException { |
| 162 | + String flagString = getFlagsFromResource(INVALID_FLAG_MULTIPLE_ERRORS); |
| 163 | + assertThatThrownBy(() -> FlagParser.parseString(flagString, true)) |
| 164 | + .isInstanceOf(IllegalArgumentException.class) |
| 165 | + .hasMessageContaining("must be valid to one and only one schema") |
| 166 | + .hasMessageContaining("$.flags.myBoolFlag: required property 'defaultVariant' not found") |
| 167 | + .hasMessageContaining("$.flags.myBoolFlag: required property 'state' not found") |
| 168 | + .hasMessageContaining( |
| 169 | + "$.flags.myBoolFlag.metadata.invalid: object found, [string, number, boolean] expected"); |
157 | 170 | }
|
158 | 171 | }
|
0 commit comments