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