]> git.basschouten.com Git - openhab-addons.git/blob
1591bc4acb116114524db3de3ee62dfdd7f6fbf2
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2023 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.binding.fmiweather;
14
15 import java.math.BigDecimal;
16 import java.util.Objects;
17
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;
23
24 /**
25  * Hamcrest matcher for Location objects
26  *
27  * @author Sami Salonen - Initial contribution
28  */
29 @NonNullByDefault
30 public class ResponseLocationMatcher extends TypeSafeMatcher<Location> {
31
32     public final String name;
33     public final String id;
34     @Nullable
35     public final BigDecimal latitude;
36     @Nullable
37     public final BigDecimal longitude;
38
39     public ResponseLocationMatcher(Location template) {
40         this(template.name, template.id, template.latitude, template.longitude);
41     }
42
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));
46     }
47
48     public ResponseLocationMatcher(String name, String id, @Nullable BigDecimal latitude,
49             @Nullable BigDecimal longitude) {
50         super();
51         this.name = name;
52         this.id = id;
53         this.latitude = latitude;
54         this.longitude = longitude;
55     }
56
57     @Override
58     public void describeTo(@Nullable Description description) {
59         if (description == null) {
60             return;
61         }
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(")");
65     }
66
67     @Override
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);
71     }
72 }