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.*;
17 import static org.mockito.Mockito.*;
19 import org.junit.jupiter.api.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;
38 private @Mock SystemControlStateListener systemControlStateListener;
40 protected void setupFor(String model) throws Exception {
41 ctx.prepareForModel(model);
42 ctx.respondWith("<System><Power_Control><Power>GetParam</Power></Power_Control></System>",
43 "System_Power_Control_Power.xml");
44 ctx.respondWith("<System><Party_Mode><Mode>GetParam</Mode></Party_Mode></System>",
45 "System_Party_Mode_Mode.xml");
47 deviceInformationState = new DeviceInformationState();
48 DeviceInformationXML deviceInformation = new DeviceInformationXML(con, deviceInformationState);
49 deviceInformation.update();
51 subject = new SystemControlXML(con, systemControlStateListener, deviceInformationState);
55 public void given_RX_S601D_when_update_then_parsesState() throws Exception {
57 setupFor(TestModels.RX_S601D);
63 ArgumentCaptor<SystemControlState> stateArg = ArgumentCaptor.forClass(SystemControlState.class);
64 verify(systemControlStateListener, only()).systemControlStateChanged(stateArg.capture());
66 SystemControlState state = stateArg.getValue();
67 assertTrue(state.power);
68 assertTrue(state.partyMode);
72 public void given_RX_S601D_when_power_then_sendsProperCommand() throws Exception {
74 setupFor(TestModels.RX_S601D);
77 subject.setPower(true);
78 subject.setPower(false);
79 subject.setPartyMode(true);
80 subject.setPartyModeMute(true);
83 verify(con).send(eq("<System><Power_Control><Power>On</Power></Power_Control></System>"));
84 verify(con).send(eq("<System><Power_Control><Power>Standby</Power></Power_Control></System>"));
85 verify(con).send(eq("<System><Party_Mode><Mode>On</Mode></Party_Mode></System>"));
86 verify(con).send(eq("<System><Party_Mode><Volume><Mute>On</Mute></Volume></Party_Mode></System>"));
90 public void given_RX_V3900_when_partyMode_then_noCommandSend() throws Exception {
92 setupFor(TestModels.RX_V3900);
95 subject.setPartyMode(true);
96 subject.setPartyModeMute(true);
97 subject.setPartyModeVolume(true);
100 verify(con, never()).send(anyString());
104 public void given_RX_V3900_when_update_then_parsesStateAndDoesNotUpdateStateForPartyMode() throws Exception {
106 setupFor(TestModels.RX_V3900);
112 ArgumentCaptor<SystemControlState> stateArg = ArgumentCaptor.forClass(SystemControlState.class);
113 verify(systemControlStateListener, only()).systemControlStateChanged(stateArg.capture());
114 verify(con, never()).sendReceive(eq("<System><Party_Mode><Mode>GetParam</Mode></Party_Mode></System>"));
116 SystemControlState state = stateArg.getValue();
117 assertTrue(state.power);
118 assertFalse(state.partyMode);