From 0b1ff0f71e4388ef858f915e479bbf936b600b8f Mon Sep 17 00:00:00 2001 From: "Claudio Maggioni (maggicl)" Date: Mon, 18 May 2020 13:16:34 +0200 Subject: [PATCH] More tests --- .../smarthut/config/GsonTests.java | 41 +++++++++++++++++++ .../smarthut/config/SpringFoxConfigTests.java | 18 ++++++++ 2 files changed, 59 insertions(+) create mode 100644 src/test/java/ch/usi/inf/sa4/sanmarinoes/smarthut/config/GsonTests.java create mode 100644 src/test/java/ch/usi/inf/sa4/sanmarinoes/smarthut/config/SpringFoxConfigTests.java diff --git a/src/test/java/ch/usi/inf/sa4/sanmarinoes/smarthut/config/GsonTests.java b/src/test/java/ch/usi/inf/sa4/sanmarinoes/smarthut/config/GsonTests.java new file mode 100644 index 0000000..dd48ae5 --- /dev/null +++ b/src/test/java/ch/usi/inf/sa4/sanmarinoes/smarthut/config/GsonTests.java @@ -0,0 +1,41 @@ +package ch.usi.inf.sa4.sanmarinoes.smarthut.config; + +import static org.assertj.core.api.Assertions.assertThat; + +import ch.usi.inf.sa4.sanmarinoes.smarthut.dto.AutomationFastUpdateRequest; +import ch.usi.inf.sa4.sanmarinoes.smarthut.models.BooleanTrigger; +import com.google.gson.Gson; +import com.google.gson.JsonObject; +import java.util.List; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.junit.jupiter.MockitoExtension; + +@ExtendWith(MockitoExtension.class) +public class GsonTests { + + private final Gson gson = GsonConfig.gson(); + + @Test + public void testGson() { + BooleanTrigger b = new BooleanTrigger(); + b.setId(1L); + String json = gson.toJson(b); + JsonObject o = gson.fromJson(json, JsonObject.class); + assertThat(o.get("kind")).isNotNull(); + assertThat(o.get("kind").getAsString()).isEqualTo("booleanTrigger"); + + AutomationFastUpdateRequest a = new AutomationFastUpdateRequest(); + AutomationFastUpdateRequest.BooleanTriggerDTO bt = + new AutomationFastUpdateRequest.BooleanTriggerDTO(); + bt.setDeviceId(42L); + a.setTriggers(List.of(bt)); + + AutomationFastUpdateRequest a2 = + gson.fromJson(gson.toJson(a), AutomationFastUpdateRequest.class); + AutomationFastUpdateRequest.TriggerDTO t = a2.getTriggers().get(0); + + assertThat(t).isExactlyInstanceOf(AutomationFastUpdateRequest.BooleanTriggerDTO.class); + assertThat(t.getDeviceId()).isEqualTo(42L); + } +} diff --git a/src/test/java/ch/usi/inf/sa4/sanmarinoes/smarthut/config/SpringFoxConfigTests.java b/src/test/java/ch/usi/inf/sa4/sanmarinoes/smarthut/config/SpringFoxConfigTests.java new file mode 100644 index 0000000..9b9cba3 --- /dev/null +++ b/src/test/java/ch/usi/inf/sa4/sanmarinoes/smarthut/config/SpringFoxConfigTests.java @@ -0,0 +1,18 @@ +package ch.usi.inf.sa4.sanmarinoes.smarthut.config; + +import static org.assertj.core.api.Assertions.assertThat; + +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.junit.jupiter.MockitoExtension; + +@ExtendWith(MockitoExtension.class) +public class SpringFoxConfigTests { + + private final SpringFoxConfig springFoxConfig = new SpringFoxConfig(); + + @Test + public void testApi() { + assertThat(springFoxConfig.api()).isNotNull(); + } +}