2 * Copyright (c) 2010-2020 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.io.transport.modbus.test;
15 import java.util.Arrays;
16 import java.util.Objects;
17 import java.util.stream.StreamSupport;
19 import org.hamcrest.Description;
20 import org.openhab.io.transport.modbus.ModbusWriteCoilRequestBlueprint;
21 import org.openhab.io.transport.modbus.ModbusWriteFunctionCode;
24 * @author Sami Salonen - Initial contribution
26 class CoilMatcher extends AbstractRequestComparer<ModbusWriteCoilRequestBlueprint> {
28 private Boolean[] expectedCoils;
30 public CoilMatcher(int expectedUnitId, int expectedAddress, int expectedMaxTries,
31 ModbusWriteFunctionCode expectedFunctionCode, Boolean... expectedCoils) {
32 super(expectedUnitId, expectedAddress, expectedFunctionCode, expectedMaxTries);
33 this.expectedCoils = expectedCoils;
37 public void describeTo(Description description) {
38 super.describeTo(description);
39 description.appendText(" coils=");
40 description.appendValue(Arrays.toString(expectedCoils));
44 protected boolean doMatchData(ModbusWriteCoilRequestBlueprint item) {
45 Object[] actual = StreamSupport.stream(item.getCoils().spliterator(), false).toArray();
46 return Objects.deepEquals(actual, expectedCoils);