feat: implemented proper deserialization for EntityID and IntVector2

This commit is contained in:
2021-05-30 17:00:59 +02:00
parent 42e57daa54
commit d0829f3948
4 changed files with 70 additions and 0 deletions

View File

@ -0,0 +1,37 @@
package uulm.teamname.marvelous.gamelibrary.json.ingame;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import net.jqwik.api.*;
import net.jqwik.api.lifecycle.BeforeProperty;
import uulm.teamname.marvelous.gamelibrary.IntVector2;
import static org.mockito.Mockito.*;
import static org.junit.jupiter.api.Assertions.*;
import static org.assertj.core.api.Assertions.*;
class IntVector2SerializerTest {
ObjectMapper mapper = new ObjectMapper();
@BeforeProperty
void setup() {
mapper = new ObjectMapper();
}
@Property
void vectorsGetProperlyDeserialized(@ForAll @From("positions") IntVector2 vector) throws JsonProcessingException {
var jsonRepresentingVector = String.format("[%d,%d]", vector.getX(), vector.getY());
assertThat(mapper.writeValueAsString(vector))
.isEqualTo(jsonRepresentingVector);
}
@Provide("positions")
Arbitrary<IntVector2> positions() {
return Arbitraries.integers()
.tuple2()
.map(pos -> new IntVector2(pos.get1(), pos.get2()));
}
}