feat: implemented deserializer for IntVector2 and created a test for it
This commit is contained in:
@ -0,0 +1,53 @@
|
||||
package uulm.teamname.marvelous.gamelibrary.json.ingame;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import uulm.teamname.marvelous.gamelibrary.IntVector2;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.concurrent.ThreadLocalRandom;
|
||||
import java.util.stream.IntStream;
|
||||
|
||||
import static org.mockito.Mockito.*;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
|
||||
class IntVector2DeserializerTest {
|
||||
|
||||
ObjectMapper mapper;
|
||||
|
||||
@BeforeEach
|
||||
void beforeAll() {
|
||||
mapper = new ObjectMapper();
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
void simpleTest() throws JsonProcessingException {
|
||||
IntVector2 target = new IntVector2(4, 17);
|
||||
String jsonDescribingTarget = "[4, 17]";
|
||||
String jsonNotDescribingTarget = "[2, 21]";
|
||||
assertThat(mapper.readValue(jsonDescribingTarget, IntVector2.class))
|
||||
.isEqualTo(target);
|
||||
assertThat(mapper.readValue(jsonNotDescribingTarget, IntVector2.class))
|
||||
.isNotEqualTo(target);
|
||||
}
|
||||
|
||||
@Test
|
||||
void randomTests() throws JsonProcessingException {
|
||||
Iterator<Integer> randomIntegers = ThreadLocalRandom.current().ints().iterator();
|
||||
int repetitions = 50;
|
||||
for (int i = 0; i < repetitions; i++) {
|
||||
int x = randomIntegers.next();
|
||||
int y = randomIntegers.next();
|
||||
IntVector2 target = new IntVector2(x, y);
|
||||
String jsonDescribingTarget = "[" + x + ", " + y + "]";
|
||||
assertThat(mapper.readValue(jsonDescribingTarget, IntVector2.class))
|
||||
.isEqualTo(target);
|
||||
System.out.println(jsonDescribingTarget);
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user