2 * Copyright (c) 2010-2020 Contributors to the openHAB project
4 * See the NOTICE file(s) distributed with this work for additional
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
11 * SPDX-License-Identifier: EPL-2.0
13 package org.openhab.binding.yamahareceiver.internal.protocol.xml;
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;
22 import org.junit.Test;
23 import org.mockito.ArgumentCaptor;
24 import org.openhab.binding.yamahareceiver.internal.state.ZoneControlState;
27 * Unit test for {@link ZoneBControlXML}.
29 * @author Tomasz Maruszak - Initial contribution
31 public class ZoneBControlXMLTest extends AbstractZoneControlXMLTest {
33 private ZoneBControlXML subject;
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>");
39 DeviceInformationXML deviceInformation = new DeviceInformationXML(con, deviceInformationState);
40 deviceInformation.update();
42 subject = new ZoneBControlXML(con, zoneConfig, zoneControlStateListener, deviceInformationState,
43 () -> inputConverter);
47 public void given_HTR_4069_when_power_then_sendsProperCommand() throws Exception {
51 subject.setPower(true);
52 subject.setPower(false);
55 verify(con).send(eq("<Main_Zone><Power_Control><Zone_B_Power>On</Zone_B_Power></Power_Control></Main_Zone>"));
57 .send(eq("<Main_Zone><Power_Control><Zone_B_Power>Standby</Zone_B_Power></Power_Control></Main_Zone>"));
61 public void given_HTR_4069_when_mute_then_sendsProperCommand() throws Exception {
65 subject.setMute(true);
66 subject.setMute(false);
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>"));
74 public void given_HTR_4069_when_volume_then_sendsProperCommand() throws Exception {
78 subject.setVolumeDB(-2);
82 "<Main_Zone><Volume><Zone_B><Lvl><Val>-20</Val><Exp>1</Exp><Unit>dB</Unit></Lvl></Zone_B></Volume></Main_Zone>"));
86 public void given_HTR_4069_when_update_then_readsStateProperly() throws Exception {
93 ArgumentCaptor<ZoneControlState> stateArg = ArgumentCaptor.forClass(ZoneControlState.class);
94 verify(zoneControlStateListener).zoneStateChanged(stateArg.capture());
96 ZoneControlState state = stateArg.getValue();
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);