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.rfxcom.internal.messages;
15 import static org.junit.jupiter.api.Assertions.assertEquals;
16 import static org.openhab.binding.rfxcom.internal.messages.RFXComTransmitterMessage.Response.ACK;
17 import static org.openhab.binding.rfxcom.internal.messages.RFXComTransmitterMessage.SubType.RESPONSE;
19 import org.eclipse.jdt.annotation.NonNullByDefault;
20 import org.junit.jupiter.api.Test;
21 import org.openhab.binding.rfxcom.internal.exceptions.RFXComException;
22 import org.openhab.binding.rfxcom.internal.messages.RFXComTransmitterMessage.Response;
23 import org.openhab.binding.rfxcom.internal.messages.RFXComTransmitterMessage.SubType;
24 import org.openhab.core.util.HexUtils;
27 * Test for RFXCom-binding
29 * @author Martin van Wingerden - Initial contribution
32 public class RFXComTransmitterMessageTest {
33 private void testMessage(String hexMsg, Response response, SubType subType, int seqNbr) throws RFXComException {
34 final RFXComTransmitterMessage msg = (RFXComTransmitterMessage) RFXComMessageFactoryImpl.INSTANCE
35 .createMessage(HexUtils.hexToBytes(hexMsg));
36 assertEquals(subType, msg.subType, "SubType");
37 assertEquals(response, msg.response, "Response");
38 assertEquals(seqNbr, (short) (msg.seqNbr & 0xFF), "Seq Number");
40 byte[] decoded = msg.decodeMessage();
42 assertEquals(hexMsg, HexUtils.bytesToHex(decoded), "Message converted back");
46 public void testSomeMessages() throws RFXComException {
47 testMessage("0402014300", ACK, RESPONSE, 67);