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.fmiweather;
15 import java.math.BigDecimal;
16 import java.util.Objects;
18 import org.eclipse.jdt.annotation.NonNullByDefault;
19 import org.eclipse.jdt.annotation.Nullable;
20 import org.hamcrest.Description;
21 import org.hamcrest.TypeSafeMatcher;
22 import org.openhab.binding.fmiweather.internal.client.Location;
25 * Hamcrest matcher for Location objects
27 * @author Sami Salonen - Initial contribution
30 public class ResponseLocationMatcher extends TypeSafeMatcher<Location> {
32 public final String name;
33 public final String id;
35 public final BigDecimal latitude;
37 public final BigDecimal longitude;
39 public ResponseLocationMatcher(Location template) {
40 this(template.name, template.id, template.latitude, template.longitude);
43 public ResponseLocationMatcher(String name, String id, @Nullable String latitude, @Nullable String longitude) {
44 this(name, id, latitude == null ? null : new BigDecimal(latitude),
45 longitude == null ? null : new BigDecimal(longitude));
48 public ResponseLocationMatcher(String name, String id, @Nullable BigDecimal latitude,
49 @Nullable BigDecimal longitude) {
53 this.latitude = latitude;
54 this.longitude = longitude;
58 public void describeTo(@Nullable Description description) {
59 if (description == null) {
62 description.appendText("Location(name=\"").appendText(name).appendText("\", id=\"").appendText(id)
63 .appendText("\", latitude=").appendText(Objects.toString(latitude)).appendText(", longitude=")
64 .appendText(Objects.toString(longitude)).appendText(")");
68 protected boolean matchesSafely(Location loc) {
69 return Objects.deepEquals(name, loc.name) && Objects.deepEquals(id, loc.id)
70 && Objects.deepEquals(latitude, loc.latitude) && Objects.deepEquals(longitude, loc.longitude);