Annotation Interface JsonParameterSetTest
@Target(METHOD)
@Retention(RUNTIME)
@ArgumentsSource(JsonArgumentSetProvider.class)
public @interface JsonParameterSetTest
A parameterized test that uses a JSON file as input and apply custom converters to the JSON nodes.
-
Required Element Summary
Required Elements -
Optional Element Summary
Optional ElementsModifier and TypeOptional ElementDescriptionThe name of the field in the test class that contains a map of custom converters.
-
Element Details
-
value
String valueThe path to the JSON file containing the test data.it is recommended to replicate the java path structure in the resources.For example let's assume the following structure:
src/graderPrivate/java/h13/controller/scene/game/GameControllerTest.java src/graderPrivate/resources/h13/controller/scene/game/GameControllerDummyState.jsonThen a test case could look like this:
@ParameterizedTest @JsonParameterSetTest(value = "GameControllerDummyState.json", customConverters = "customConverters") public void testHandleKeyboardInputsEscapeLose(final JsonParameterSet params) throws InterruptedException, IOException { testHandleKeyboardInputsEscape(params, true); }- Returns:
- the path to the JSON file containing the test data.
-
-
-
customConverters
String customConvertersThe name of the field in the test class that contains a map of custom converters.For example let's assume we have a Field called customConverters in the test class:
@SuppressWarnings("unused") public final static Map<String, Function<JsonNode, ?>> customConverters = Map.ofEntries( Map.entry("GAME_BOUNDS", JsonConverter::toBounds), Map.entry("enemies", JsonConverter::toIDEnemyList), Map.entry("bullets", JsonConverter::toIDBulletList), Map.entry("player", JsonConverter::toIDPlayer), Map.entry("bulletOwners", JsonConverter::toIntMap), Map.entry("hits", JsonConverter::toIntMap), Map.entry("damaged", jsonNode -> JsonConverter.toMap(jsonNode, Integer::parseInt, JsonNode::asBoolean)) );Then a test case could look like this:
@ParameterizedTest @JsonParameterSetTest(value = "GameControllerDummyState.json", customConverters = "customConverters") public void testHandleKeyboardInputsEscapeLose(final JsonParameterSet params) throws InterruptedException, IOException { testHandleKeyboardInputsEscape(params, true); }- Returns:
- the name of the field in the test class that contains a map of custom converters.
- Default:
- ""
-