]> git.basschouten.com Git - openhab-addons.git/blob
298a3d35253bba7713ad047aa42a0ff06aad76f4
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2023 Contributors to the openHAB project
3  *
4  * See the NOTICE file(s) distributed with this work for additional
5  * information.
6  *
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
10  *
11  * SPDX-License-Identifier: EPL-2.0
12  */
13 package org.openhab.binding.rfxcom.internal.messages;
14
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;
18
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;
25
26 /**
27  * Test for RFXCom-binding
28  *
29  * @author Martin van Wingerden - Initial contribution
30  */
31 @NonNullByDefault
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");
39
40         byte[] decoded = msg.decodeMessage();
41
42         assertEquals(hexMsg, HexUtils.bytesToHex(decoded), "Message converted back");
43     }
44
45     @Test
46     public void testSomeMessages() throws RFXComException {
47         testMessage("0402014300", ACK, RESPONSE, 67);
48     }
49 }