Merge branch 'tests' into 'dev'

More tests

See merge request sa4-2020/the-sanmarinoes/backend!148
This commit is contained in:
Claudio Maggioni 2020-05-18 13:16:59 +02:00
commit c2686f2f24
2 changed files with 59 additions and 0 deletions

View file

@ -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);
}
}

View file

@ -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();
}
}