Repository navigation
Expand file tree
/
Copy pathCustomTiltAngleRangeTest.java
More file actions
92 lines (84 loc) · 5 KB
/
Copy pathCustomTiltAngleRangeTest.java
File metadata and controls
92 lines (84 loc) · 5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
package io.github.hapjava.characteristics.impl;
import static org.assertj.core.api.Assertions.assertThat;
import io.github.hapjava.characteristics.Characteristic;
import io.github.hapjava.characteristics.impl.slat.CurrentTiltAngleCharacteristic;
import io.github.hapjava.characteristics.impl.slat.TargetTiltAngleCharacteristic;
import io.github.hapjava.characteristics.impl.windowcovering.CurrentHorizontalTiltAngleCharacteristic;
import io.github.hapjava.characteristics.impl.windowcovering.CurrentVerticalTiltAngleCharacteristic;
import io.github.hapjava.characteristics.impl.windowcovering.TargetHorizontalTiltAngleCharacteristic;
import io.github.hapjava.characteristics.impl.windowcovering.TargetVerticalTiltAngleCharacteristic;
import java.util.Arrays;
import java.util.concurrent.CompletableFuture;
import javax.json.JsonObject;
import org.junit.Test;
/** Custom tilt angle ranges, see https://github.com/hap-java/HAP-Java/issues/162 */
public class CustomTiltAngleRangeTest {
@Test
public void defaultConstructorsKeepTheirSerializedOutput() {
// Serialized output captured before custom ranges were added.
for (Case c :
Arrays.asList(
Case.of(
new CurrentTiltAngleCharacteristic(
() -> CompletableFuture.completedFuture(50), cb -> {}, () -> {}),
"{\"iid\":7,\"type\":\"C1\",\"perms\":[\"pr\",\"ev\"],\"format\":\"int\",\"value\":50,\"minValue\":-90,\"maxValue\":90,\"minStep\":1,\"unit\":\"arcdegrees\"}"),
Case.of(
new TargetTiltAngleCharacteristic(
() -> CompletableFuture.completedFuture(50), v -> {}, cb -> {}, () -> {}),
"{\"iid\":7,\"type\":\"C2\",\"perms\":[\"pr\",\"pw\",\"ev\"],\"format\":\"int\",\"value\":50,\"minValue\":-90,\"maxValue\":90,\"minStep\":1,\"unit\":\"arcdegrees\"}"),
Case.of(
new CurrentHorizontalTiltAngleCharacteristic(
() -> CompletableFuture.completedFuture(50), cb -> {}, () -> {}),
"{\"iid\":7,\"type\":\"6C\",\"perms\":[\"pr\",\"ev\"],\"format\":\"int\",\"value\":50,\"minValue\":-90,\"maxValue\":90,\"minStep\":1,\"unit\":\"arcdegrees\"}"),
Case.of(
new TargetHorizontalTiltAngleCharacteristic(
() -> CompletableFuture.completedFuture(50), v -> {}, cb -> {}, () -> {}),
"{\"iid\":7,\"type\":\"7B\",\"perms\":[\"pr\",\"pw\",\"ev\"],\"format\":\"int\",\"value\":50,\"minValue\":-90,\"maxValue\":90,\"minStep\":1,\"unit\":\"arcdegrees\"}"),
Case.of(
new CurrentVerticalTiltAngleCharacteristic(
() -> CompletableFuture.completedFuture(50), cb -> {}, () -> {}),
"{\"iid\":7,\"type\":\"6E\",\"perms\":[\"pr\",\"ev\"],\"format\":\"int\",\"value\":50,\"minValue\":-90,\"maxValue\":90,\"minStep\":1,\"unit\":\"arcdegrees\"}"),
Case.of(
new TargetVerticalTiltAngleCharacteristic(
() -> CompletableFuture.completedFuture(50), v -> {}, cb -> {}, () -> {}),
"{\"iid\":7,\"type\":\"7D\",\"perms\":[\"pr\",\"pw\",\"ev\"],\"format\":\"int\",\"value\":50,\"minValue\":-90,\"maxValue\":90,\"minStep\":1,\"unit\":\"arcdegrees\"}"))) {
assertThat(c.characteristic.toJson(7).join().toString())
.as(c.characteristic.getClass().getSimpleName())
.isEqualTo(c.expected);
}
}
@Test
public void customRangeIsAdvertised() {
for (Characteristic c :
Arrays.<Characteristic>asList(
new CurrentTiltAngleCharacteristic(
0, 90, () -> CompletableFuture.completedFuture(50), cb -> {}, () -> {}),
new TargetTiltAngleCharacteristic(
0, 90, () -> CompletableFuture.completedFuture(50), v -> {}, cb -> {}, () -> {}),
new CurrentHorizontalTiltAngleCharacteristic(
0, 90, () -> CompletableFuture.completedFuture(50), cb -> {}, () -> {}),
new TargetHorizontalTiltAngleCharacteristic(
0, 90, () -> CompletableFuture.completedFuture(50), v -> {}, cb -> {}, () -> {}),
new CurrentVerticalTiltAngleCharacteristic(
0, 90, () -> CompletableFuture.completedFuture(50), cb -> {}, () -> {}),
new TargetVerticalTiltAngleCharacteristic(
0, 90, () -> CompletableFuture.completedFuture(50), v -> {}, cb -> {}, () -> {}))) {
JsonObject json = c.toJson(7).join();
String name = c.getClass().getSimpleName();
assertThat(json.getInt("minValue")).as(name).isEqualTo(0);
assertThat(json.getInt("maxValue")).as(name).isEqualTo(90);
assertThat(json.getInt("minStep")).as(name).isEqualTo(1);
}
}
private static class Case {
final Characteristic characteristic;
final String expected;
private Case(Characteristic characteristic, String expected) {
this.characteristic = characteristic;
this.expected = expected;
}
static Case of(Characteristic characteristic, String expected) {
return new Case(characteristic, expected);
}
}
}