2 * Copyright (c) 2010-2022 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.fmiweather;
15 import org.eclipse.jdt.annotation.NonNullByDefault;
16 import org.eclipse.jdt.annotation.Nullable;
17 import org.hamcrest.Description;
18 import org.hamcrest.TypeSafeMatcher;
21 * Hamcrest matcher for timestamps
23 * @author Sami Salonen - Initial contribution
26 public class TimestampMatcher extends TypeSafeMatcher<long[]> {
29 private int intervalMinutes;
32 public TimestampMatcher(long start, int intervalMinutes, long steps) {
34 this.intervalMinutes = intervalMinutes;
39 public void describeTo(@Nullable Description description) {
40 if (description == null) {
43 description.appendText(new StringBuilder("start=").append(start).append(", length=").append(steps)
44 .append(", interval=").append(intervalMinutes).toString());
48 protected boolean matchesSafely(long[] timestamps) {
49 return verifyLength(timestamps) && verifyStart(timestamps) && verifyStep(timestamps);
52 private boolean verifyLength(long[] timestamps) {
53 return timestamps.length == steps;
56 private boolean verifyStart(long[] timestamps) {
57 return timestamps[0] == start;
60 private boolean verifyStep(long[] timestamps) {
61 for (int i = 1; i < timestamps.length; i++) {
62 if (timestamps[i] - timestamps[i - 1] != intervalMinutes * 60) {