]> git.basschouten.com Git - openhab-addons.git/blob
b3ea80a65fb1711db7e57f154272507418766333
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2021 Contributors to the openHAB project
3  *
4  * See the NOTICE file(s) distributed with this work for additional
5  * information.
6  *
7  * This program and the accompanying materials are made available under the
8  * terms of the Eclipse Public License 2.0 which is available at
9  * http://www.eclipse.org/legal/epl-2.0
10  *
11  * SPDX-License-Identifier: EPL-2.0
12  */
13 package org.openhab.binding.digitalstrom.internal.lib.structure.devices.impl;
14
15 import static org.hamcrest.MatcherAssert.assertThat;
16 import static org.hamcrest.core.Is.*;
17
18 import java.util.ArrayList;
19 import java.util.Arrays;
20 import java.util.List;
21
22 import org.eclipse.jdt.annotation.NonNullByDefault;
23 import org.junit.jupiter.api.Test;
24 import org.junit.jupiter.api.extension.ExtendWith;
25 import org.mockito.junit.jupiter.MockitoExtension;
26 import org.openhab.binding.digitalstrom.internal.lib.structure.devices.deviceparameters.constants.OutputChannelEnum;
27 import org.openhab.binding.digitalstrom.internal.lib.structure.devices.deviceparameters.constants.OutputModeEnum;
28 import org.openhab.binding.digitalstrom.internal.lib.util.JsonModel;
29 import org.openhab.binding.digitalstrom.internal.lib.util.OutputChannel;
30
31 import com.google.gson.Gson;
32 import com.google.gson.JsonObject;
33 import com.google.gson.JsonParser;
34
35 /**
36  * Test class for certain code in {@link DeviceImpl}
37  *
38  * @author Rouven Schürch - Initial contribution
39  *
40  */
41 @ExtendWith(MockitoExtension.class)
42 @NonNullByDefault
43 class DeviceImplTest {
44
45     private static final List<OutputChannel> EMPTY_CHANNEL = new ArrayList<>();
46
47     private static final List<OutputChannel> SHADE_ANGLE_CHANNELS = Arrays.asList(
48             new OutputChannel(OutputChannelEnum.SHADE_OPENING_ANGLE_OUTSIDE),
49             new OutputChannel(OutputChannelEnum.SHADE_OPENING_ANGLE_INDOOR));
50
51     private static final List<OutputChannel> SHADE_POSITION_CHANNELS = Arrays.asList(
52             new OutputChannel(OutputChannelEnum.SHADE_POSITION_INDOOR),
53             new OutputChannel(OutputChannelEnum.SHADE_POSITION_OUTSIDE));
54
55     private static final List<OutputChannel> NON_SHADE_CHANNEL = Arrays
56             .asList(new OutputChannel(OutputChannelEnum.BRIGHTNESS));
57
58     private static final List<OutputChannel> MIXED_SHADE_CHANNEL = Arrays.asList(
59             new OutputChannel(OutputChannelEnum.BRIGHTNESS),
60             new OutputChannel(OutputChannelEnum.SHADE_OPENING_ANGLE_OUTSIDE));
61
62     @Test
63     void isBlindSwitchShadeChannel() {
64         JsonObject jsonObject = createJsonObject(OutputModeEnum.SINGLE_SWITCH, SHADE_ANGLE_CHANNELS);
65         DeviceImpl deviceImpl = new DeviceImpl(jsonObject);
66         assertThat(deviceImpl.isBlind(), is(false));
67     }
68
69     @Test
70     void isBlindSwitchNoShadeChannel() {
71         JsonObject jsonObject = createJsonObject(OutputModeEnum.SINGLE_SWITCH, NON_SHADE_CHANNEL);
72         DeviceImpl deviceImpl = new DeviceImpl(jsonObject);
73         assertThat(deviceImpl.isBlind(), is(false));
74     }
75
76     @Test
77     void isBlindSwitchMixedShadeChannel() {
78         JsonObject jsonObject = createJsonObject(OutputModeEnum.SINGLE_SWITCH, MIXED_SHADE_CHANNEL);
79         DeviceImpl deviceImpl = new DeviceImpl(jsonObject);
80         assertThat(deviceImpl.isBlind(), is(false));
81     }
82
83     @Test
84     void isBlindPositionConUsNoChannel() {
85         JsonObject jsonObject = createJsonObject(OutputModeEnum.POSITION_CON_US, EMPTY_CHANNEL);
86         DeviceImpl deviceImpl = new DeviceImpl(jsonObject);
87         assertThat(deviceImpl.isBlind(), is(false));
88     }
89
90     @Test
91     void isBlindPositionConUsNonShadeChannel() {
92         JsonObject jsonObject = createJsonObject(OutputModeEnum.POSITION_CON_US, NON_SHADE_CHANNEL);
93         DeviceImpl deviceImpl = new DeviceImpl(jsonObject);
94         assertThat(deviceImpl.isBlind(), is(false));
95     }
96
97     @Test
98     void isBlindPositionConUsShadePositionChannels() {
99         JsonObject jsonObject = createJsonObject(OutputModeEnum.POSITION_CON_US, SHADE_POSITION_CHANNELS);
100         DeviceImpl deviceImpl = new DeviceImpl(jsonObject);
101         assertThat(deviceImpl.isBlind(), is(false));
102     }
103
104     @Test
105     void isBlindPositionConUsShadeAngleChannels() {
106         JsonObject jsonObject = createJsonObject(OutputModeEnum.POSITION_CON_US, SHADE_ANGLE_CHANNELS);
107         DeviceImpl deviceImpl = new DeviceImpl(jsonObject);
108         assertThat(deviceImpl.isBlind(), is(true));
109     }
110
111     @Test
112     void isBlindPositionConUsMixedChannels() {
113         JsonObject jsonObject = createJsonObject(OutputModeEnum.POSITION_CON_US, MIXED_SHADE_CHANNEL);
114         DeviceImpl deviceImpl = new DeviceImpl(jsonObject);
115         assertThat(deviceImpl.isBlind(), is(true));
116     }
117
118     @Test
119     void isBlindPositionConNoChannel() {
120         JsonObject jsonObject = createJsonObject(OutputModeEnum.POSITION_CON, EMPTY_CHANNEL);
121         DeviceImpl deviceImpl = new DeviceImpl(jsonObject);
122         assertThat(deviceImpl.isBlind(), is(false));
123     }
124
125     @Test
126     void isBlindPositionConNonShadeChannel() {
127         JsonObject jsonObject = createJsonObject(OutputModeEnum.POSITION_CON, NON_SHADE_CHANNEL);
128         DeviceImpl deviceImpl = new DeviceImpl(jsonObject);
129         assertThat(deviceImpl.isBlind(), is(false));
130     }
131
132     @Test
133     void isBlindPositionConShadePositionChannels() {
134         JsonObject jsonObject = createJsonObject(OutputModeEnum.POSITION_CON, SHADE_POSITION_CHANNELS);
135         DeviceImpl deviceImpl = new DeviceImpl(jsonObject);
136         assertThat(deviceImpl.isBlind(), is(false));
137     }
138
139     @Test
140     void isBlindPositionConShadeAngleChannels() {
141         JsonObject jsonObject = createJsonObject(OutputModeEnum.POSITION_CON, SHADE_ANGLE_CHANNELS);
142         DeviceImpl deviceImpl = new DeviceImpl(jsonObject);
143         assertThat(deviceImpl.isBlind(), is(true));
144     }
145
146     @Test
147     void isBlindPositionConMixedChannels() {
148         JsonObject jsonObject = createJsonObject(OutputModeEnum.POSITION_CON, MIXED_SHADE_CHANNEL);
149         DeviceImpl deviceImpl = new DeviceImpl(jsonObject);
150         assertThat(deviceImpl.isBlind(), is(true));
151     }
152
153     private static JsonObject createJsonObject(OutputModeEnum outputMode, List<OutputChannel> channels) {
154         JsonModel model = new JsonModel(outputMode.getMode(), channels);
155
156         Gson gson = new Gson();
157         String json = gson.toJson(model);
158
159         return JsonParser.parseString(json).getAsJsonObject();
160     }
161 }