]> git.basschouten.com Git - openhab-addons.git/blob
5bb52b743e4a56aee316c5ac000f124cbfb5c3c9
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2021 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.miele.internal;
14
15 import static org.junit.jupiter.api.Assertions.*;
16
17 import org.junit.jupiter.api.Test;
18 import org.openhab.core.test.java.JavaTest;
19
20 /**
21  * This class provides test cases for {@link
22  * org.openhab.binding.miele.internal.ExtendedDeviceStateUtil}
23  *
24  * @author Jacob Laursen - Added power/water consumption channels
25  */
26
27 public class ExtendedDeviceStateUtilTest extends JavaTest {
28
29     @Test
30     public void bytesToHexWhenTopBitIsUsedReturnsCorrectString() {
31         String actual = ExtendedDeviceStateUtil
32                 .bytesToHex(new byte[] { (byte) 0xde, (byte) 0xad, (byte) 0xbe, (byte) 0xef });
33         assertEquals("DEADBEEF", actual);
34     }
35
36     /**
37      * This test guards that the UTF-16 returned by the RPC-JSON API will be
38      * considered as a sequence of 8-bit characters and converted into bytes
39      * accordingly. Default behaviour of String.getBytes() assumes UTF-8
40      * and adds a 0xc2 byte before any character out of ASCII range.
41      */
42     @Test
43     public void stringToBytesWhenTopBitIsUsedReturnsSingleByte() {
44         byte[] expected = new byte[] { (byte) 0x00, (byte) 0x80, (byte) 0x00 };
45         byte[] actual = ExtendedDeviceStateUtil.stringToBytes("\u0000\u0080\u0000");
46         assertArrayEquals(expected, actual);
47     }
48 }