|
| 1 | +package io.github.hapjava.characteristics.impl.valve; |
| 2 | + |
| 3 | +import static org.assertj.core.api.Assertions.assertThat; |
| 4 | + |
| 5 | +import io.github.hapjava.characteristics.impl.windowcovering.CurrentPositionCharacteristic; |
| 6 | +import java.util.concurrent.CompletableFuture; |
| 7 | +import javax.json.JsonObject; |
| 8 | +import org.junit.Test; |
| 9 | + |
| 10 | +/** Regression tests for https://github.com/hap-java/HAP-Java/issues/202 */ |
| 11 | +public class DurationCharacteristicFormatTest { |
| 12 | + |
| 13 | + @Test |
| 14 | + public void setDurationAdvertisesUint32() { |
| 15 | + SetDurationCharacteristic characteristic = |
| 16 | + new SetDurationCharacteristic( |
| 17 | + () -> CompletableFuture.completedFuture(300), value -> {}, callback -> {}, () -> {}); |
| 18 | + |
| 19 | + JsonObject json = characteristic.toJson(12).join(); |
| 20 | + |
| 21 | + assertThat(json.getString("type")).isEqualTo("D3"); |
| 22 | + assertThat(json.getString("format")).isEqualTo("uint32"); |
| 23 | + assertThat(json.getInt("value")).isEqualTo(300); |
| 24 | + assertThat(json.getInt("minValue")).isEqualTo(0); |
| 25 | + assertThat(json.getInt("maxValue")).isEqualTo(3600); |
| 26 | + assertThat(json.getInt("minStep")).isEqualTo(1); |
| 27 | + assertThat(json.getString("unit")).isEqualTo("s"); |
| 28 | + } |
| 29 | + |
| 30 | + @Test |
| 31 | + public void remainingDurationAdvertisesUint32() { |
| 32 | + RemainingDurationCharacteristic characteristic = |
| 33 | + new RemainingDurationCharacteristic( |
| 34 | + () -> CompletableFuture.completedFuture(180), callback -> {}, () -> {}); |
| 35 | + |
| 36 | + JsonObject json = characteristic.toJson(13).join(); |
| 37 | + |
| 38 | + assertThat(json.getString("type")).isEqualTo("D4"); |
| 39 | + assertThat(json.getString("format")).isEqualTo("uint32"); |
| 40 | + assertThat(json.getInt("value")).isEqualTo(180); |
| 41 | + assertThat(json.getInt("minValue")).isEqualTo(0); |
| 42 | + assertThat(json.getInt("maxValue")).isEqualTo(3600); |
| 43 | + assertThat(json.getString("unit")).isEqualTo("s"); |
| 44 | + } |
| 45 | + |
| 46 | + @Test |
| 47 | + public void otherIntegerCharacteristicsKeepIntFormat() { |
| 48 | + CurrentPositionCharacteristic characteristic = |
| 49 | + new CurrentPositionCharacteristic( |
| 50 | + () -> CompletableFuture.completedFuture(50), callback -> {}, () -> {}); |
| 51 | + |
| 52 | + JsonObject json = characteristic.toJson(14).join(); |
| 53 | + |
| 54 | + assertThat(json.getString("format")).isEqualTo("int"); |
| 55 | + } |
| 56 | +} |
0 commit comments