2 * Copyright (c) 2010-2023 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.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;
20 import org.junit.jupiter.api.Test;
21 import org.mockito.ArgumentCaptor;
22 import org.openhab.binding.yamahareceiver.internal.state.ZoneControlState;
25 * Unit test for {@link ZoneBControlXML}.
27 * @author Tomasz Maruszak - Initial contribution
29 public class ZoneBControlXMLTest extends AbstractZoneControlXMLTest {
31 private ZoneBControlXML subject;
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>");
37 DeviceInformationXML deviceInformation = new DeviceInformationXML(con, deviceInformationState);
38 deviceInformation.update();
40 subject = new ZoneBControlXML(con, zoneConfig, zoneControlStateListener, deviceInformationState,
41 () -> inputConverter);
45 public void given_HTR_4069_when_power_then_sendsProperCommand() throws Exception {
49 subject.setPower(true);
50 subject.setPower(false);
53 verify(con).send(eq("<Main_Zone><Power_Control><Zone_B_Power>On</Zone_B_Power></Power_Control></Main_Zone>"));
55 .send(eq("<Main_Zone><Power_Control><Zone_B_Power>Standby</Zone_B_Power></Power_Control></Main_Zone>"));
59 public void given_HTR_4069_when_mute_then_sendsProperCommand() throws Exception {
63 subject.setMute(true);
64 subject.setMute(false);
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>"));
72 public void given_HTR_4069_when_volume_then_sendsProperCommand() throws Exception {
76 subject.setVolumeDB(-2);
80 "<Main_Zone><Volume><Zone_B><Lvl><Val>-20</Val><Exp>1</Exp><Unit>dB</Unit></Lvl></Zone_B></Volume></Main_Zone>"));
84 public void given_HTR_4069_when_update_then_readsStateProperly() throws Exception {
91 ArgumentCaptor<ZoneControlState> stateArg = ArgumentCaptor.forClass(ZoneControlState.class);
92 verify(zoneControlStateListener).zoneStateChanged(stateArg.capture());
94 ZoneControlState state = stateArg.getValue();
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);