|
1 | 1 | package net.joshka.junit.json.params; |
2 | 2 |
|
| 3 | +import java.lang.reflect.Method; |
| 4 | +import java.util.List; |
| 5 | +import javax.json.JsonArray; |
3 | 6 | import org.junit.jupiter.api.DisplayName; |
4 | 7 | import org.junit.jupiter.api.Test; |
5 | 8 | import org.junit.jupiter.api.extension.ExtensionContext; |
@@ -71,13 +74,47 @@ void arrayOfStrings(JsonString string) { |
71 | 74 | assertThat(string.getString()).startsWith("value"); |
72 | 75 | } |
73 | 76 |
|
| 77 | + /** |
| 78 | + * When passed <code>[{"key":"value1"},{"key","value2"}]</code> |
| 79 | + * and argument is a JsonArray, test is executed only once. |
| 80 | + * @param object the parsed JsonArray object |
| 81 | + */ |
| 82 | + @ParameterizedTest |
| 83 | + @JsonFileSource(resources = "/array-of-objects.json") |
| 84 | + void jsonArray(JsonArray object) { |
| 85 | + assertThat(object).hasSize(2); |
| 86 | + } |
| 87 | + |
| 88 | + /** |
| 89 | + * When passed <code>[{"key":"value1"},{"key","value2"}]</code> |
| 90 | + * and argument is a List, test is executed only once. |
| 91 | + * @param object the parsed List object |
| 92 | + */ |
| 93 | + @ParameterizedTest |
| 94 | + @JsonFileSource(resources = "/array-of-objects.json") |
| 95 | + void listJsonObject(List<JsonObject> object) { |
| 96 | + assertThat(object).hasSize(2); |
| 97 | + } |
| 98 | + |
| 99 | + /** |
| 100 | + * When passed <code>[{"key":"value1"},{"key","value2"}]</code> |
| 101 | + * and argument is a List, test is executed only once. |
| 102 | + * @param object the parsed List object |
| 103 | + */ |
| 104 | + @ParameterizedTest |
| 105 | + @JsonFileSource(resources = "/array-of-objects.json") |
| 106 | + void listString(List<String> object) { |
| 107 | + assertThat(object).hasSize(2); |
| 108 | + } |
| 109 | + |
74 | 110 | @Test |
75 | 111 | @DisplayName("missing resource throws exception") |
76 | | - void missingResource() { |
| 112 | + void missingResource() throws Exception { |
77 | 113 | BiFunction<Class, String, InputStream> inputStreamProvider = (aClass, resource) -> null; |
78 | 114 | ExtensionContext context = mock(ExtensionContext.class); |
79 | 115 | JsonFileSource source = mock(JsonFileSource.class); |
80 | 116 | when(source.resources()).thenReturn(new String[]{"not-found.json"}); |
| 117 | + when(context.getRequiredTestMethod()).thenReturn(this.getClass().getDeclaredMethod("missingResource")); |
81 | 118 | JsonFileArgumentsProvider provider = new JsonFileArgumentsProvider(inputStreamProvider); |
82 | 119 | provider.accept(source); |
83 | 120 |
|
|
0 commit comments