]> git.basschouten.com Git - openhab-addons.git/blob
7a5bb9e330aa69f176e749d1a64dd5236827e804
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2020 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.io.transport.modbus.test;
14
15 import java.util.Arrays;
16 import java.util.Objects;
17 import java.util.stream.StreamSupport;
18
19 import org.hamcrest.Description;
20 import org.openhab.io.transport.modbus.ModbusWriteCoilRequestBlueprint;
21 import org.openhab.io.transport.modbus.ModbusWriteFunctionCode;
22
23 /**
24  * @author Sami Salonen - Initial contribution
25  */
26 class CoilMatcher extends AbstractRequestComparer<ModbusWriteCoilRequestBlueprint> {
27
28     private Boolean[] expectedCoils;
29
30     public CoilMatcher(int expectedUnitId, int expectedAddress, int expectedMaxTries,
31             ModbusWriteFunctionCode expectedFunctionCode, Boolean... expectedCoils) {
32         super(expectedUnitId, expectedAddress, expectedFunctionCode, expectedMaxTries);
33         this.expectedCoils = expectedCoils;
34     }
35
36     @Override
37     public void describeTo(Description description) {
38         super.describeTo(description);
39         description.appendText(" coils=");
40         description.appendValue(Arrays.toString(expectedCoils));
41     }
42
43     @Override
44     protected boolean doMatchData(ModbusWriteCoilRequestBlueprint item) {
45         Object[] actual = StreamSupport.stream(item.getCoils().spliterator(), false).toArray();
46         return Objects.deepEquals(actual, expectedCoils);
47     }
48 }