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 org.hamcrest.Description;
16 import org.hamcrest.TypeSafeMatcher;
17 import org.openhab.io.transport.modbus.ModbusWriteFunctionCode;
18 import org.openhab.io.transport.modbus.ModbusWriteRequestBlueprint;
21 * @author Sami Salonen - Initial contribution
23 abstract class AbstractRequestComparer<T extends ModbusWriteRequestBlueprint> extends TypeSafeMatcher<T> {
25 private int expectedUnitId;
26 private int expectedAddress;
27 private ModbusWriteFunctionCode expectedFunctionCode;
28 private int expectedMaxTries;
30 public AbstractRequestComparer(int expectedUnitId, int expectedAddress,
31 ModbusWriteFunctionCode expectedFunctionCode, int expectedMaxTries) {
32 this.expectedUnitId = expectedUnitId;
33 this.expectedAddress = expectedAddress;
34 this.expectedFunctionCode = expectedFunctionCode;
35 this.expectedMaxTries = expectedMaxTries;
39 public void describeTo(Description description) {
40 description.appendText("should return request with");
41 description.appendText(" unitID=");
42 description.appendValue(expectedUnitId);
43 description.appendText(" address=");
44 description.appendValue(expectedAddress);
45 description.appendText(" functionCode=");
46 description.appendValue(expectedFunctionCode);
47 description.appendText(" maxTries=");
48 description.appendValue(expectedMaxTries);
51 @SuppressWarnings("null")
53 protected boolean matchesSafely(T item) {
54 if (item.getUnitID() != expectedUnitId) {
57 if (item.getReference() != expectedAddress) {
60 if (item.getFunctionCode() != expectedFunctionCode) {
63 if (item.getMaxTries() != expectedMaxTries) {
66 return doMatchData(item);
69 protected abstract boolean doMatchData(T item);