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.paradoxalarm.internal;
15 import static org.junit.jupiter.api.Assertions.assertTrue;
17 import org.eclipse.jdt.annotation.NonNullByDefault;
18 import org.junit.jupiter.api.Test;
19 import org.openhab.binding.paradoxalarm.internal.communication.messages.partition.PartitionCommand;
20 import org.openhab.binding.paradoxalarm.internal.communication.messages.partition.PartitionCommandPayload;
21 import org.openhab.binding.paradoxalarm.internal.util.ParadoxUtil;
24 * The {@link TestCreateCommandPayload} This test tests the proper build of command payload object for partition entity
25 * with all types of commands.
27 * @author Konstantin Polihronov - Initial contribution
30 public class TestCreateCommandPayload {
33 public void testCreatePayload() {
34 for (PartitionCommand command : PartitionCommand.values()) {
35 for (int partitionNumber = 1; partitionNumber <= 8; partitionNumber++) {
36 PartitionCommandPayload payload = new PartitionCommandPayload(partitionNumber, command);
37 assertNibble(partitionNumber, command, payload);
42 private void assertNibble(int partitionNumber, PartitionCommand command, PartitionCommandPayload payload) {
43 byte[] bytes = payload.getBytes();
44 int payloadIndexOfByteToCheck = 6 + (partitionNumber - 1) / 2;
45 byte byteValue = bytes[payloadIndexOfByteToCheck];
46 if ((partitionNumber - 1) % 2 == 0) {
47 assertTrue(ParadoxUtil.getHighNibble(byteValue) == command.getCommand());
49 assertTrue(ParadoxUtil.getLowNibble(byteValue) == command.getCommand());