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;
15 import static org.junit.jupiter.api.Assertions.assertTrue;
16 import static org.mockito.ArgumentMatchers.eq;
17 import static org.mockito.Mockito.when;
18 import static org.openhab.binding.yamahareceiver.internal.YamahaReceiverBindingConstants.Zone.Zone_2;
20 import java.io.IOException;
22 import org.junit.jupiter.api.Test;
23 import org.mockito.Mock;
24 import org.openhab.binding.yamahareceiver.internal.config.YamahaZoneConfig;
25 import org.openhab.binding.yamahareceiver.internal.protocol.xml.AbstractXMLProtocolTest;
26 import org.openhab.binding.yamahareceiver.internal.protocol.xml.DeviceInformationXML;
27 import org.openhab.binding.yamahareceiver.internal.protocol.xml.XMLProtocolFactory;
28 import org.openhab.binding.yamahareceiver.internal.protocol.xml.ZoneBControlXML;
29 import org.openhab.binding.yamahareceiver.internal.protocol.xml.ZoneControlXML;
30 import org.openhab.binding.yamahareceiver.internal.state.DeviceInformationState;
31 import org.openhab.binding.yamahareceiver.internal.state.ZoneControlStateListener;
34 * Unit test for {@link ProtocolFactory}.
36 * @author Tomasz Maruszak - Initial contribution
38 public class XMLProtocolFactoryTest extends AbstractXMLProtocolTest {
40 private @Mock YamahaZoneConfig zoneConfig;
41 private @Mock ZoneControlStateListener zoneControlStateListener;
43 private DeviceInformationState state = new DeviceInformationState();
45 private XMLProtocolFactory subject;
48 protected void onSetUp() throws Exception {
51 when(zoneConfig.getZone()).thenReturn(Zone_2);
52 when(con.sendReceive(eq("<Zone_2><Basic_Status>GetParam</Basic_Status></Zone_2>"))).thenReturn("<xml></xml>");
54 subject = new XMLProtocolFactory();
58 public void given_HTR4069_with_ZONEB_then_Zone2_control_is_ZoneBControlXML()
59 throws IOException, ReceivedMessageParseException {
61 ctx.prepareForModel("HTR-4069");
63 DeviceInformationXML deviceInformation = new DeviceInformationXML(con, state);
64 deviceInformation.update();
67 ZoneControl zoneControl = subject.ZoneControl(con, zoneConfig, zoneControlStateListener, () -> null, state);
70 assertTrue(zoneControl instanceof ZoneBControlXML, "Created ZoneB control");
74 public void given_RXS601D_without_ZONEB_then_Zone2_control_is_ZoneControlXML()
75 throws IOException, ReceivedMessageParseException {
77 ctx.prepareForModel("RX-S601D");
79 DeviceInformationXML deviceInformation = new DeviceInformationXML(con, state);
80 deviceInformation.update();
83 ZoneControl zoneControl = subject.ZoneControl(con, zoneConfig, zoneControlStateListener, () -> null, state);
86 assertTrue(zoneControl instanceof ZoneControlXML, "Created Zone control");