Migrate tests to JUnit 5 (#8519)

Signed-off-by: Wouter Born <github@maindrain.net>
This commit is contained in:
Wouter Born
2020-09-21 18:21:26 +02:00
committed by GitHub
parent 6df6783b60
commit bd82ca82df
478 changed files with 3996 additions and 4419 deletions

View File

@@ -21,7 +21,6 @@
package org.openhab.binding.sleepiq.api.impl.typeadapters;
import java.time.LocalTime;
import java.time.format.DateTimeFormatter;
/**
* Type adapter for jsr310 {@link LocalTime} class.
@@ -30,7 +29,7 @@ import java.time.format.DateTimeFormatter;
*/
public class LocalTimeTypeAdapter extends TemporalTypeAdapter<LocalTime> {
public LocalTimeTypeAdapter() {
super(LocalTime::parse);
}
public LocalTimeTypeAdapter() {
super(LocalTime::parse);
}
}

View File

@@ -21,7 +21,6 @@
package org.openhab.binding.sleepiq.api.impl.typeadapters;
import java.time.OffsetDateTime;
import java.time.format.DateTimeFormatter;
/**
* Type adapter for jsr310 {@link OffsetDateTime} class.
@@ -30,7 +29,7 @@ import java.time.format.DateTimeFormatter;
*/
public class OffsetDateTimeTypeAdapter extends DateTimeTypeAdapter<OffsetDateTime> {
public OffsetDateTimeTypeAdapter() {
super(OffsetDateTime::parse);
}
public OffsetDateTimeTypeAdapter() {
super(OffsetDateTime::parse);
}
}

View File

@@ -21,7 +21,6 @@
package org.openhab.binding.sleepiq.api.impl.typeadapters;
import java.time.OffsetTime;
import java.time.format.DateTimeFormatter;
/**
* Type adapter for jsr310 {@link OffsetTime} class.
@@ -30,7 +29,7 @@ import java.time.format.DateTimeFormatter;
*/
public class OffsetTimeTypeAdapter extends TemporalTypeAdapter<OffsetTime> {
public OffsetTimeTypeAdapter() {
super(OffsetTime::parse);
}
public OffsetTimeTypeAdapter() {
super(OffsetTime::parse);
}
}

View File

@@ -20,16 +20,15 @@
*/
package org.openhab.binding.sleepiq.api.impl.typeadapters;
import java.io.IOException;
import java.util.Objects;
import java.util.function.Function;
import com.google.gson.TypeAdapter;
import com.google.gson.stream.JsonReader;
import com.google.gson.stream.JsonToken;
import com.google.gson.stream.JsonWriter;
import java.io.IOException;
import java.time.temporal.TemporalAccessor;
import java.util.Objects;
import java.util.function.Function;
/**
* Abstract type adapter for jsr310 date-time types.
*
@@ -37,33 +36,33 @@ import java.util.function.Function;
*/
abstract class TemporalTypeAdapter<T> extends TypeAdapter<T> {
Function<String, T> parseFunction;
Function<String, T> parseFunction;
TemporalTypeAdapter(Function<String, T> parseFunction) {
Objects.requireNonNull(parseFunction);
this.parseFunction = parseFunction;
}
@Override
public void write(JsonWriter out, T value) throws IOException {
if (value == null) {
out.nullValue();
} else {
out.value(value.toString());
TemporalTypeAdapter(Function<String, T> parseFunction) {
Objects.requireNonNull(parseFunction);
this.parseFunction = parseFunction;
}
}
@Override
public T read(JsonReader in) throws IOException {
if (in.peek() == JsonToken.NULL) {
in.nextNull();
return null;
@Override
public void write(JsonWriter out, T value) throws IOException {
if (value == null) {
out.nullValue();
} else {
out.value(value.toString());
}
}
String temporalString = preProcess(in.nextString());
return parseFunction.apply(temporalString);
}
public String preProcess(String in) {
return in;
}
@Override
public T read(JsonReader in) throws IOException {
if (in.peek() == JsonToken.NULL) {
in.nextNull();
return null;
}
String temporalString = preProcess(in.nextString());
return parseFunction.apply(temporalString);
}
public String preProcess(String in) {
return in;
}
}

View File

@@ -21,7 +21,6 @@
package org.openhab.binding.sleepiq.api.impl.typeadapters;
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
/**
* Type adapter for jsr310 {@link ZonedDateTime} class.
@@ -30,7 +29,7 @@ import java.time.format.DateTimeFormatter;
*/
public class ZonedDateTimeTypeAdapter extends DateTimeTypeAdapter<ZonedDateTime> {
public ZonedDateTimeTypeAdapter() {
super(ZonedDateTime::parse);
}
public ZonedDateTimeTypeAdapter() {
super(ZonedDateTime::parse);
}
}

View File

@@ -15,50 +15,36 @@
*/
package org.openhab.binding.sleepiq.api.model;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.jupiter.api.Assertions.*;
import java.io.FileReader;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.openhab.binding.sleepiq.api.impl.GsonGenerator;
import org.openhab.binding.sleepiq.api.model.BedSideStatus;
import org.openhab.binding.sleepiq.api.model.TimeSince;
import org.openhab.binding.sleepiq.api.test.AbstractTest;
import com.google.gson.Gson;
public class BedSideStatusTest extends AbstractTest
{
public class BedSideStatusTest extends AbstractTest {
private static Gson gson;
@BeforeClass
public static void setUpBeforeClass()
{
@BeforeAll
public static void setUpBeforeClass() {
gson = GsonGenerator.create(true);
}
@Test
public void testSerializeAllFields() throws Exception
{
BedSideStatus bedSideStatus = new BedSideStatus().withAlertDetailedMessage("No Alert")
.withAlertId(0L)
.withInBed(false)
.withLastLink(new TimeSince().withDuration(3,
5,
4,
38))
.withPressure(573)
.withSleepNumber(55);
public void testSerializeAllFields() throws Exception {
BedSideStatus bedSideStatus = new BedSideStatus().withAlertDetailedMessage("No Alert").withAlertId(0L)
.withInBed(false).withLastLink(new TimeSince().withDuration(3, 5, 4, 38)).withPressure(573)
.withSleepNumber(55);
assertEquals(readJson("bed-side-status.json"), gson.toJson(bedSideStatus));
}
@Test
public void testDeserializeAllFields() throws Exception
{
try (FileReader reader = new FileReader(getTestDataFile("bed-side-status.json")))
{
public void testDeserializeAllFields() throws Exception {
try (FileReader reader = new FileReader(getTestDataFile("bed-side-status.json"))) {
BedSideStatus bedSideStatus = gson.fromJson(reader, BedSideStatus.class);
assertEquals("No Alert", bedSideStatus.getAlertDetailedMessage());
assertEquals(Long.valueOf(0L), bedSideStatus.getAlertId());

View File

@@ -15,47 +15,36 @@
*/
package org.openhab.binding.sleepiq.api.model;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.junit.jupiter.api.Assertions.*;
import java.io.FileReader;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.openhab.binding.sleepiq.api.impl.GsonGenerator;
import org.openhab.binding.sleepiq.api.model.BedSideStatus;
import org.openhab.binding.sleepiq.api.model.BedStatus;
import org.openhab.binding.sleepiq.api.test.AbstractTest;
import com.google.gson.Gson;
public class BedStatusTest extends AbstractTest
{
public class BedStatusTest extends AbstractTest {
private static Gson gson;
@BeforeClass
public static void setUpBeforeClass()
{
@BeforeAll
public static void setUpBeforeClass() {
gson = GsonGenerator.create(true);
}
@Test
public void testSerializeAllFields() throws Exception
{
public void testSerializeAllFields() throws Exception {
BedStatus bedStatus = new BedStatus().withBedId("-9999999999999999999")
.withLeftSide(new BedSideStatus().withInBed(true))
.withRightSide(new BedSideStatus().withInBed(false))
.withStatus(1L);
.withLeftSide(new BedSideStatus().withInBed(true)).withRightSide(new BedSideStatus().withInBed(false))
.withStatus(1L);
assertEquals(readJson("bed-status.json"), gson.toJson(bedStatus));
}
@Test
public void testDeserializeAllFields() throws Exception
{
try (FileReader reader = new FileReader(getTestDataFile("bed-status.json")))
{
public void testDeserializeAllFields() throws Exception {
try (FileReader reader = new FileReader(getTestDataFile("bed-status.json"))) {
BedStatus bedStatus = gson.fromJson(reader, BedStatus.class);
assertEquals("-9999999999999999999", bedStatus.getBedId());
assertEquals(Long.valueOf(1L), bedStatus.getStatus());

View File

@@ -15,76 +15,43 @@
*/
package org.openhab.binding.sleepiq.api.model;
import static org.junit.Assert.assertEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;
import java.io.FileReader;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.openhab.binding.sleepiq.api.impl.GsonGenerator;
import org.openhab.binding.sleepiq.api.model.Bed;
import org.openhab.binding.sleepiq.api.test.AbstractTest;
import com.google.gson.Gson;
public class BedTest extends AbstractTest
{
public class BedTest extends AbstractTest {
private static Gson gson;
@BeforeClass
public static void setUpBeforeClass()
{
@BeforeAll
public static void setUpBeforeClass() {
gson = GsonGenerator.create(true);
}
@Test
public void testSerializeAllFields() throws Exception
{
Bed bed = new Bed().withAccountId("-8888888888888888888")
.withBase("MODULAR")
.withBedId("-9999999999999999999")
.withDualSleep(true)
.withKidsBed(false)
.withMacAddress("AABBCCDDEEFF")
.withModel("P5")
.withName("Bed")
.withPurchaseDate(ZonedDateTime.of(2017,
2,
2,
0,
0,
1,
0,
ZoneId.of("Z").normalized()))
.withReference("55555555555-5")
.withRegistrationDate(ZonedDateTime.of(2017,
2,
17,
2,
14,
10,
0,
ZoneId.of("Z").normalized()))
.withReturnRequestStatus(0L)
.withSerial("")
.withSize("QUEEN")
.withSku("QP5")
.withSleeperLeftId("-2222222222222222222")
.withSleeperRightId("-1111111111111111111")
.withStatus(1L)
.withTimezone("US/Pacific")
.withVersion("")
.withZipCode("90210");
public void testSerializeAllFields() throws Exception {
Bed bed = new Bed().withAccountId("-8888888888888888888").withBase("MODULAR").withBedId("-9999999999999999999")
.withDualSleep(true).withKidsBed(false).withMacAddress("AABBCCDDEEFF").withModel("P5").withName("Bed")
.withPurchaseDate(ZonedDateTime.of(2017, 2, 2, 0, 0, 1, 0, ZoneId.of("Z").normalized()))
.withReference("55555555555-5")
.withRegistrationDate(ZonedDateTime.of(2017, 2, 17, 2, 14, 10, 0, ZoneId.of("Z").normalized()))
.withReturnRequestStatus(0L).withSerial("").withSize("QUEEN").withSku("QP5")
.withSleeperLeftId("-2222222222222222222").withSleeperRightId("-1111111111111111111").withStatus(1L)
.withTimezone("US/Pacific").withVersion("").withZipCode("90210");
assertEquals(readJson("bed.json"), gson.toJson(bed));
}
@Test
public void testDeserializeAllFields() throws Exception
{
try (FileReader reader = new FileReader(getTestDataFile("bed.json")))
{
public void testDeserializeAllFields() throws Exception {
try (FileReader reader = new FileReader(getTestDataFile("bed.json"))) {
Bed bed = gson.fromJson(reader, Bed.class);
assertEquals("-8888888888888888888", bed.getAccountId());
assertEquals("MODULAR", bed.getBase());
@@ -94,11 +61,10 @@ public class BedTest extends AbstractTest
assertEquals("AABBCCDDEEFF", bed.getMacAddress());
assertEquals("P5", bed.getModel());
assertEquals("Bed", bed.getName());
assertEquals(ZonedDateTime.of(2017, 2, 2, 0, 0, 1, 0, ZoneId.of("Z").normalized()),
bed.getPurchaseDate());
assertEquals(ZonedDateTime.of(2017, 2, 2, 0, 0, 1, 0, ZoneId.of("Z").normalized()), bed.getPurchaseDate());
assertEquals("55555555555-5", bed.getReference());
assertEquals(ZonedDateTime.of(2017, 2, 17, 2, 14, 10, 0, ZoneId.of("Z").normalized()),
bed.getRegistrationDate());
bed.getRegistrationDate());
assertEquals(Long.valueOf(0L), bed.getReturnRequestStatus());
assertEquals("", bed.getSerial());
assertEquals("QUEEN", bed.getSize());

View File

@@ -15,45 +15,37 @@
*/
package org.openhab.binding.sleepiq.api.model;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.jupiter.api.Assertions.*;
import java.io.FileReader;
import java.util.Arrays;
import java.util.List;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.openhab.binding.sleepiq.api.impl.GsonGenerator;
import org.openhab.binding.sleepiq.api.model.Bed;
import org.openhab.binding.sleepiq.api.model.BedsResponse;
import org.openhab.binding.sleepiq.api.test.AbstractTest;
import com.google.gson.Gson;
public class BedsResponseTest extends AbstractTest
{
public class BedsResponseTest extends AbstractTest {
private static Gson gson;
@BeforeClass
public static void setUpBeforeClass()
{
@BeforeAll
public static void setUpBeforeClass() {
gson = GsonGenerator.create(true);
}
@Test
public void testSerializeAllFields() throws Exception
{
BedsResponse bedsResponse = new BedsResponse().withBeds(Arrays.asList(new Bed().withName("Bed1"),
new Bed().withName("Bed2")));
public void testSerializeAllFields() throws Exception {
BedsResponse bedsResponse = new BedsResponse()
.withBeds(Arrays.asList(new Bed().withName("Bed1"), new Bed().withName("Bed2")));
assertEquals(readJson("beds-response.json"), gson.toJson(bedsResponse));
}
@Test
public void testDeserializeAllFields() throws Exception
{
try (FileReader reader = new FileReader(getTestDataFile("beds-response.json")))
{
public void testDeserializeAllFields() throws Exception {
try (FileReader reader = new FileReader(getTestDataFile("beds-response.json"))) {
BedsResponse bedsResponse = gson.fromJson(reader, BedsResponse.class);
List<Bed> beds = bedsResponse.getBeds();

View File

@@ -15,44 +15,36 @@
*/
package org.openhab.binding.sleepiq.api.model;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.jupiter.api.Assertions.*;
import java.io.FileReader;
import java.util.Arrays;
import java.util.List;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.openhab.binding.sleepiq.api.impl.GsonGenerator;
import org.openhab.binding.sleepiq.api.model.BedStatus;
import org.openhab.binding.sleepiq.api.model.FamilyStatus;
import org.openhab.binding.sleepiq.api.test.AbstractTest;
import com.google.gson.Gson;
public class FamilyStatusTest extends AbstractTest
{
public class FamilyStatusTest extends AbstractTest {
private static Gson gson;
@BeforeClass
public static void setUpBeforeClass()
{
@BeforeAll
public static void setUpBeforeClass() {
gson = GsonGenerator.create(true);
}
@Test
public void testSerializeAllFields() throws Exception
{
public void testSerializeAllFields() throws Exception {
FamilyStatus familyStatus = new FamilyStatus().withBeds(Arrays.asList(new BedStatus().withStatus(1L)));
assertEquals(readJson("family-status.json"), gson.toJson(familyStatus));
}
@Test
public void testDeserializeAllFields() throws Exception
{
try (FileReader reader = new FileReader(getTestDataFile("family-status.json")))
{
public void testDeserializeAllFields() throws Exception {
try (FileReader reader = new FileReader(getTestDataFile("family-status.json"))) {
FamilyStatus familyStatus = gson.fromJson(reader, FamilyStatus.class);
List<BedStatus> beds = familyStatus.getBeds();

View File

@@ -15,42 +15,35 @@
*/
package org.openhab.binding.sleepiq.api.model;
import static org.junit.Assert.assertEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;
import java.io.FileReader;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.openhab.binding.sleepiq.api.impl.GsonGenerator;
import org.openhab.binding.sleepiq.api.model.PauseMode;
import org.openhab.binding.sleepiq.api.test.AbstractTest;
import com.google.gson.Gson;
public class PauseModeTest extends AbstractTest
{
public class PauseModeTest extends AbstractTest {
private static Gson gson;
@BeforeClass
public static void setUpBeforeClass()
{
@BeforeAll
public static void setUpBeforeClass() {
gson = GsonGenerator.create(true);
}
@Test
public void testSerializeAllFields() throws Exception
{
PauseMode pauseMode = new PauseMode().withAccountId("-8888888888888888888")
.withBedId("-9999999999999999999")
.withPauseMode("off");
public void testSerializeAllFields() throws Exception {
PauseMode pauseMode = new PauseMode().withAccountId("-8888888888888888888").withBedId("-9999999999999999999")
.withPauseMode("off");
assertEquals(readJson("pause-mode.json"), gson.toJson(pauseMode));
}
@Test
public void testDeserializeAllFields() throws Exception
{
try (FileReader reader = new FileReader(getTestDataFile("pause-mode.json")))
{
public void testDeserializeAllFields() throws Exception {
try (FileReader reader = new FileReader(getTestDataFile("pause-mode.json"))) {
PauseMode pauseMode = gson.fromJson(reader, PauseMode.class);
assertEquals("-8888888888888888888", pauseMode.getAccountId());
assertEquals("-9999999999999999999", pauseMode.getBedId());

View File

@@ -15,69 +15,45 @@
*/
package org.openhab.binding.sleepiq.api.model;
import static org.junit.Assert.assertEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;
import java.io.FileReader;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.openhab.binding.sleepiq.api.impl.GsonGenerator;
import org.openhab.binding.sleepiq.api.model.Sleeper;
import org.openhab.binding.sleepiq.api.test.AbstractTest;
import com.google.gson.Gson;
public class SleeperTest extends AbstractTest
{
public class SleeperTest extends AbstractTest {
private static Gson gson;
@BeforeClass
public static void setUpBeforeClass()
{
@BeforeAll
public static void setUpBeforeClass() {
gson = GsonGenerator.create(true);
}
@Test
public void testSerializeAllFields() throws Exception
{
Sleeper sleeper = new Sleeper().withAccountId("-5555555555555555555")
.withAccountOwner(true)
.withActive(true)
.withAvatar("")
.withBedId("-9999999999999999999")
.withBirthMonth(6)
.withBirthYear("1970")
.withChild(false)
.withDuration("")
.withEmail("alice@domain.com")
.withEmailValidated(true)
.withFirstName("Alice")
.withHeight(64)
.withLastLogin("2017-02-17 20:19:36 CST")
.withLicenseVersion(6L)
.withMale(false)
.withSide(1)
.withSleeperId("-1111111111111111111")
.withSleepGoal(450)
.withTimezone("US/Pacific")
.withUsername("alice@domain.com")
.withWeight(110)
.withZipCode("90210");
public void testSerializeAllFields() throws Exception {
Sleeper sleeper = new Sleeper().withAccountId("-5555555555555555555").withAccountOwner(true).withActive(true)
.withAvatar("").withBedId("-9999999999999999999").withBirthMonth(6).withBirthYear("1970")
.withChild(false).withDuration("").withEmail("alice@domain.com").withEmailValidated(true)
.withFirstName("Alice").withHeight(64).withLastLogin("2017-02-17 20:19:36 CST").withLicenseVersion(6L)
.withMale(false).withSide(1).withSleeperId("-1111111111111111111").withSleepGoal(450)
.withTimezone("US/Pacific").withUsername("alice@domain.com").withWeight(110).withZipCode("90210");
assertEquals(readJson("sleeper.json"), gson.toJson(sleeper));
}
@Test
public void testSerializeLastLoginNull() throws Exception
{
public void testSerializeLastLoginNull() throws Exception {
Sleeper sleeper = new Sleeper().withLastLogin("null");
assertEquals(readJson("sleeper-lastlogin-null.json"), gson.toJson(sleeper));
}
@Test
public void testDeserializeAllFields() throws Exception
{
try (FileReader reader = new FileReader(getTestDataFile("sleeper.json")))
{
public void testDeserializeAllFields() throws Exception {
try (FileReader reader = new FileReader(getTestDataFile("sleeper.json"))) {
Sleeper sleeper = gson.fromJson(reader, Sleeper.class);
assertEquals("-5555555555555555555", sleeper.getAccountId());
assertEquals(true, sleeper.isAccountOwner());
@@ -106,10 +82,8 @@ public class SleeperTest extends AbstractTest
}
@Test
public void testDeserializeLastLoginNull() throws Exception
{
try (FileReader reader = new FileReader(getTestDataFile("sleeper-lastlogin-null.json")))
{
public void testDeserializeLastLoginNull() throws Exception {
try (FileReader reader = new FileReader(getTestDataFile("sleeper-lastlogin-null.json"))) {
Sleeper sleeper = gson.fromJson(reader, Sleeper.class);
assertEquals("null", sleeper.getLastLogin());
}

View File

@@ -15,45 +15,37 @@
*/
package org.openhab.binding.sleepiq.api.model;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.jupiter.api.Assertions.*;
import java.io.FileReader;
import java.util.Arrays;
import java.util.List;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.openhab.binding.sleepiq.api.impl.GsonGenerator;
import org.openhab.binding.sleepiq.api.model.Sleeper;
import org.openhab.binding.sleepiq.api.model.SleepersResponse;
import org.openhab.binding.sleepiq.api.test.AbstractTest;
import com.google.gson.Gson;
public class SleepersResponseTest extends AbstractTest
{
public class SleepersResponseTest extends AbstractTest {
private static Gson gson;
@BeforeClass
public static void setUpBeforeClass()
{
@BeforeAll
public static void setUpBeforeClass() {
gson = GsonGenerator.create(true);
}
@Test
public void testSerializeAllFields() throws Exception
{
SleepersResponse sleepersResponse = new SleepersResponse().withSleepers(Arrays.asList(new Sleeper().withFirstName("Alice"),
new Sleeper().withFirstName("Bob")));
public void testSerializeAllFields() throws Exception {
SleepersResponse sleepersResponse = new SleepersResponse()
.withSleepers(Arrays.asList(new Sleeper().withFirstName("Alice"), new Sleeper().withFirstName("Bob")));
assertEquals(readJson("sleepers-response.json"), gson.toJson(sleepersResponse));
}
@Test
public void testDeserializeAllFields() throws Exception
{
try (FileReader reader = new FileReader(getTestDataFile("sleepers-response.json")))
{
public void testDeserializeAllFields() throws Exception {
try (FileReader reader = new FileReader(getTestDataFile("sleepers-response.json"))) {
SleepersResponse sleepersResponse = gson.fromJson(reader, SleepersResponse.class);
List<Sleeper> sleepers = sleepersResponse.getSleepers();

View File

@@ -15,53 +15,42 @@
*/
package org.openhab.binding.sleepiq.api.model;
import static org.junit.Assert.assertEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;
import java.time.Duration;
import org.junit.Test;
import org.openhab.binding.sleepiq.api.model.TimeSince;
import org.junit.jupiter.api.Test;
public class TimeSinceTest
{
public class TimeSinceTest {
@Test
public void testWithDuration()
{
public void testWithDuration() {
assertEquals(new TimeSince().withDuration(0, 0, 0, 0).getDuration(),
new TimeSince().withDuration(Duration.parse("PT00H00M00S")).getDuration());
new TimeSince().withDuration(Duration.parse("PT00H00M00S")).getDuration());
assertEquals(new TimeSince().withDuration(0, 2, 3, 4).getDuration(),
new TimeSince().withDuration(Duration.parse("PT02H03M04S")).getDuration());
new TimeSince().withDuration(Duration.parse("PT02H03M04S")).getDuration());
assertEquals(new TimeSince().withDuration(0, 12, 34, 56).getDuration(),
new TimeSince().withDuration(Duration.parse("PT12H34M56S")).getDuration());
new TimeSince().withDuration(Duration.parse("PT12H34M56S")).getDuration());
assertEquals(new TimeSince().withDuration(1, 2, 3, 4).getDuration(),
new TimeSince().withDuration(Duration.parse("P1DT02H03M04S")).getDuration());
new TimeSince().withDuration(Duration.parse("P1DT02H03M04S")).getDuration());
assertEquals(new TimeSince().withDuration(12, 23, 34, 45).getDuration(),
new TimeSince().withDuration(Duration.parse("P12DT23H34M45S")).getDuration());
new TimeSince().withDuration(Duration.parse("P12DT23H34M45S")).getDuration());
}
@Test
public void testToString()
{
assertEquals("00:00:00",
new TimeSince().withDuration(Duration.parse("PT00H00M00S")).toString());
assertEquals("02:03:04",
new TimeSince().withDuration(Duration.parse("PT02H03M04S")).toString());
assertEquals("12:34:56",
new TimeSince().withDuration(Duration.parse("PT12H34M56S")).toString());
assertEquals("1 d 02:03:04",
new TimeSince().withDuration(Duration.parse("P1DT02H03M04S")).toString());
assertEquals("12 d 23:34:45",
new TimeSince().withDuration(Duration.parse("P12DT23H34M45S")).toString());
public void testToString() {
assertEquals("00:00:00", new TimeSince().withDuration(Duration.parse("PT00H00M00S")).toString());
assertEquals("02:03:04", new TimeSince().withDuration(Duration.parse("PT02H03M04S")).toString());
assertEquals("12:34:56", new TimeSince().withDuration(Duration.parse("PT12H34M56S")).toString());
assertEquals("1 d 02:03:04", new TimeSince().withDuration(Duration.parse("P1DT02H03M04S")).toString());
assertEquals("12 d 23:34:45", new TimeSince().withDuration(Duration.parse("P12DT23H34M45S")).toString());
}
@Test
public void testParse()
{
public void testParse() {
assertEquals(Duration.parse("PT00H00M00S"), TimeSince.parse("00:00:00").getDuration());
assertEquals(Duration.parse("PT2H3M4S"), TimeSince.parse("02:03:04").getDuration());
assertEquals(Duration.parse("PT12H34M56S"), TimeSince.parse("12:34:56").getDuration());
assertEquals(Duration.parse("P1DT2H3M4S"), TimeSince.parse("1 d 02:03:04").getDuration());
assertEquals(Duration.parse("P12DT23H34M45S"),
TimeSince.parse("12 d 23:34:45").getDuration());
assertEquals(Duration.parse("P12DT23H34M45S"), TimeSince.parse("12 d 23:34:45").getDuration());
}
}