]> git.basschouten.com Git - openhab-addons.git/blob
43e97b13c38471996bd57c349ed986f08ebfe318
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2023 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.yamahareceiver.internal.protocol.xml;
14
15 import static org.junit.jupiter.api.Assertions.*;
16 import static org.mockito.ArgumentMatchers.eq;
17 import static org.mockito.Mockito.*;
18 import static org.openhab.binding.yamahareceiver.internal.TestModels.HTR_4069;
19
20 import org.junit.jupiter.api.Test;
21 import org.mockito.ArgumentCaptor;
22 import org.openhab.binding.yamahareceiver.internal.state.ZoneControlState;
23
24 /**
25  * Unit test for {@link ZoneBControlXML}.
26  *
27  * @author Tomasz Maruszak - Initial contribution
28  */
29 public class ZoneBControlXMLTest extends AbstractZoneControlXMLTest {
30
31     private ZoneBControlXML subject;
32
33     private void given(String model) throws Exception {
34         ctx.prepareForModel(model);
35         when(con.sendReceive(eq("<Zone_2><Basic_Status>GetParam</Basic_Status></Zone_2>"))).thenReturn("<xml></xml>");
36
37         DeviceInformationXML deviceInformation = new DeviceInformationXML(con, deviceInformationState);
38         deviceInformation.update();
39
40         subject = new ZoneBControlXML(con, zoneConfig, zoneControlStateListener, deviceInformationState,
41                 () -> inputConverter);
42     }
43
44     @Test
45     public void given_HTR_4069_when_power_then_sendsProperCommand() throws Exception {
46         given(HTR_4069);
47
48         // when
49         subject.setPower(true);
50         subject.setPower(false);
51
52         // then
53         verify(con).send(eq("<Main_Zone><Power_Control><Zone_B_Power>On</Zone_B_Power></Power_Control></Main_Zone>"));
54         verify(con)
55                 .send(eq("<Main_Zone><Power_Control><Zone_B_Power>Standby</Zone_B_Power></Power_Control></Main_Zone>"));
56     }
57
58     @Test
59     public void given_HTR_4069_when_mute_then_sendsProperCommand() throws Exception {
60         given(HTR_4069);
61
62         // when
63         subject.setMute(true);
64         subject.setMute(false);
65
66         // then
67         verify(con).send(eq("<Main_Zone><Volume><Zone_B><Mute>On</Mute></Zone_B></Volume></Main_Zone>"));
68         verify(con).send(eq("<Main_Zone><Volume><Zone_B><Mute>Off</Mute></Zone_B></Volume></Main_Zone>"));
69     }
70
71     @Test
72     public void given_HTR_4069_when_volume_then_sendsProperCommand() throws Exception {
73         given(HTR_4069);
74
75         // when
76         subject.setVolumeDB(-2);
77
78         // then
79         verify(con).send(eq(
80                 "<Main_Zone><Volume><Zone_B><Lvl><Val>-20</Val><Exp>1</Exp><Unit>dB</Unit></Lvl></Zone_B></Volume></Main_Zone>"));
81     }
82
83     @Test
84     public void given_HTR_4069_when_update_then_readsStateProperly() throws Exception {
85         given(HTR_4069);
86
87         // when
88         subject.update();
89
90         // then
91         ArgumentCaptor<ZoneControlState> stateArg = ArgumentCaptor.forClass(ZoneControlState.class);
92         verify(zoneControlStateListener).zoneStateChanged(stateArg.capture());
93
94         ZoneControlState state = stateArg.getValue();
95         assertNotNull(state);
96
97         assertEquals(false, state.power);
98         assertEquals(false, state.mute);
99         assertEquals(-34.5, state.volumeDB, 0);
100         assertEquals("TUNER", state.inputID);
101         assertEquals("5ch Stereo", state.surroundProgram);
102         assertEquals(1, state.dialogueLevel);
103     }
104 }