More tests
This commit is contained in:
parent
08565bbc42
commit
0b1ff0f71e
2 changed files with 59 additions and 0 deletions
|
@ -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);
|
||||||
|
}
|
||||||
|
}
|
|
@ -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();
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue