]> git.basschouten.com Git - openhab-addons.git/blob
3071b49d09d546e015ed2383f1d19445ac9d8aa5
[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.nanoleaf.internal.model;
14
15 import static org.hamcrest.CoreMatchers.*;
16 import static org.hamcrest.MatcherAssert.assertThat;
17
18 import java.util.Arrays;
19
20 import org.eclipse.jdt.annotation.NonNullByDefault;
21 import org.eclipse.jdt.annotation.Nullable;
22 import org.junit.jupiter.api.BeforeEach;
23 import org.junit.jupiter.api.Test;
24
25 /**
26  * Test for global orientation
27  *
28  * @author Jørgen Austvik - Initial contribution
29  */
30 @NonNullByDefault
31 public class PanelLayoutTest {
32
33     @Nullable
34     private PanelLayout pl1;
35
36     @Nullable
37     private PanelLayout pl2; // Different from pl1
38
39     @Nullable
40     private PanelLayout pl3; // Equal to pl1
41
42     @BeforeEach
43     public void setUp() {
44         PositionDatum pd1 = new PositionDatum(100, 200, 270, 123, 12);
45         PositionDatum pd2 = new PositionDatum(100, 220, 240, 123, 2);
46         PositionDatum pd3 = new PositionDatum(100, 200, 270, 123, 12);
47
48         Layout l1 = new Layout(Arrays.asList(pd1, pd3));
49         Layout l2 = new Layout(Arrays.asList(pd1, pd2));
50         Layout l3 = new Layout(Arrays.asList(pd1, pd3));
51
52         GlobalOrientation go1 = new GlobalOrientation(0, 360, 180);
53
54         pl1 = new PanelLayout(go1, l1);
55         pl2 = new PanelLayout(go1, l2);
56         pl3 = new PanelLayout(go1, l3);
57     }
58
59     @Test
60     public void testHashCode() {
61         PanelLayout p1 = pl1;
62         PanelLayout p2 = pl2;
63         PanelLayout p3 = pl3;
64         if (p1 != null && p2 != null && p3 != null) {
65             assertThat(p1.hashCode(), is(equalTo(p3.hashCode())));
66             assertThat(p2.hashCode(), is(not(equalTo(p3.hashCode()))));
67         } else {
68             assertThat("Should be initialized", false);
69         }
70     }
71
72     @Test
73     public void testEquals() {
74         assertThat(pl1, is(equalTo(pl3)));
75         assertThat(pl2, is(not(equalTo(pl3))));
76         assertThat(pl3, is(not(equalTo(null))));
77     }
78 }