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.*;
16 import static org.mockito.ArgumentMatchers.*;
17 import static org.mockito.Mockito.*;
19 import org.junit.Test;
20 import org.mockito.ArgumentCaptor;
21 import org.mockito.Mock;
22 import org.openhab.binding.yamahareceiver.internal.TestModels;
23 import org.openhab.binding.yamahareceiver.internal.state.DeviceInformationState;
24 import org.openhab.binding.yamahareceiver.internal.state.SystemControlState;
25 import org.openhab.binding.yamahareceiver.internal.state.SystemControlStateListener;
28 * Unit test for {@link SystemControlXML}.
30 * @author Tomasz Maruszak - Initial contribution
32 public class SystemControlXMLTest extends AbstractXMLProtocolTest {
34 private SystemControlXML subject;
36 private DeviceInformationState deviceInformationState;
39 private SystemControlStateListener systemControlStateListener;
41 protected void setupFor(String model) throws Exception {
42 ctx.prepareForModel(model);
43 ctx.respondWith("<System><Power_Control><Power>GetParam</Power></Power_Control></System>",
44 "System_Power_Control_Power.xml");
45 ctx.respondWith("<System><Party_Mode><Mode>GetParam</Mode></Party_Mode></System>",
46 "System_Party_Mode_Mode.xml");
48 deviceInformationState = new DeviceInformationState();
49 DeviceInformationXML deviceInformation = new DeviceInformationXML(con, deviceInformationState);
50 deviceInformation.update();
52 subject = new SystemControlXML(con, systemControlStateListener, deviceInformationState);
56 public void given_RX_S601D_when_update_then_parsesState() throws Exception {
58 setupFor(TestModels.RX_S601D);
64 ArgumentCaptor<SystemControlState> stateArg = ArgumentCaptor.forClass(SystemControlState.class);
65 verify(systemControlStateListener, only()).systemControlStateChanged(stateArg.capture());
67 SystemControlState state = stateArg.getValue();
68 assertTrue(state.power);
69 assertTrue(state.partyMode);
73 public void given_RX_S601D_when_power_then_sendsProperCommand() throws Exception {
75 setupFor(TestModels.RX_S601D);
78 subject.setPower(true);
79 subject.setPower(false);
80 subject.setPartyMode(true);
81 subject.setPartyModeMute(true);
84 verify(con).send(eq("<System><Power_Control><Power>On</Power></Power_Control></System>"));
85 verify(con).send(eq("<System><Power_Control><Power>Standby</Power></Power_Control></System>"));
86 verify(con).send(eq("<System><Party_Mode><Mode>On</Mode></Party_Mode></System>"));
87 verify(con).send(eq("<System><Party_Mode><Volume><Mute>On</Mute></Volume></Party_Mode></System>"));
91 public void given_RX_V3900_when_partyMode_then_noCommandSend() throws Exception {
93 setupFor(TestModels.RX_V3900);
96 subject.setPartyMode(true);
97 subject.setPartyModeMute(true);
98 subject.setPartyModeVolume(true);
101 verify(con, never()).send(anyString());
105 public void given_RX_V3900_when_update_then_parsesStateAndDoesNotUpdateStateForPartyMode() throws Exception {
107 setupFor(TestModels.RX_V3900);
113 ArgumentCaptor<SystemControlState> stateArg = ArgumentCaptor.forClass(SystemControlState.class);
114 verify(systemControlStateListener, only()).systemControlStateChanged(stateArg.capture());
115 verify(con, never()).sendReceive(eq("<System><Party_Mode><Mode>GetParam</Mode></Party_Mode></System>"));
117 SystemControlState state = stateArg.getValue();
118 assertTrue(state.power);
119 assertFalse(state.partyMode);