From b2b963579e5c79c13dc82018330c9ded6b84d90f Mon Sep 17 00:00:00 2001 From: Yannik Bretschneider Date: Fri, 28 May 2021 14:47:15 +0200 Subject: [PATCH] test: wrote proptest for IntVector to practise proptesting --- .../json/ingame/IntVector2DeserializerTest.java | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/test/java/uulm/teamname/marvelous/gamelibrary/json/ingame/IntVector2DeserializerTest.java b/src/test/java/uulm/teamname/marvelous/gamelibrary/json/ingame/IntVector2DeserializerTest.java index ab7af08..d70c3a8 100644 --- a/src/test/java/uulm/teamname/marvelous/gamelibrary/json/ingame/IntVector2DeserializerTest.java +++ b/src/test/java/uulm/teamname/marvelous/gamelibrary/json/ingame/IntVector2DeserializerTest.java @@ -2,6 +2,9 @@ package uulm.teamname.marvelous.gamelibrary.json.ingame; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; +import net.jqwik.api.ForAll; +import net.jqwik.api.Property; +import net.jqwik.api.lifecycle.BeforeProperty; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -50,4 +53,18 @@ class IntVector2DeserializerTest { // System.out.println(jsonDescribingTarget); } } + + // A PropTest written to get comfortable with jqwik. It practically does the same as the test above, + // but took less than 1/30th of the time to write. Quite impressive indeed. + + @BeforeProperty + void beforeProperty() { + this.mapper = new ObjectMapper(); + } + + @Property + void deserializedVectorHasCorrectValues(@ForAll int someX, @ForAll int someY) throws JsonProcessingException { + assertThat(mapper.readValue(String.format("[%d, %d]", someX, someY), IntVector2.class)) + .isEqualTo(new IntVector2(someX, someY)); + } } \ No newline at end of file