]> git.basschouten.com Git - openhab-addons.git/blob
d46598fcaaadb2caa8abe991bf6e9920102d5eab
[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 LayoutTest {
32
33     @Nullable
34     private Layout lo1;
35
36     @Nullable
37     private Layout lo2; // Different from l1
38
39     @Nullable
40     private Layout lo3; // Same as l1
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         lo1 = new Layout(Arrays.asList(pd1, pd3));
49         lo2 = new Layout(Arrays.asList(pd1, pd2));
50         lo3 = new Layout(Arrays.asList(pd1, pd3));
51     }
52
53     @Test
54     public void testHashCode() {
55         Layout l1 = lo1;
56         Layout l2 = lo2;
57         Layout l3 = lo3;
58         if (l1 != null && l2 != null && l3 != null) {
59             assertThat(l1.hashCode(), is(equalTo(l3.hashCode())));
60             assertThat(l2.hashCode(), is(not(equalTo(l3.hashCode()))));
61         } else {
62             assertThat("Should be initialized", false);
63         }
64     }
65
66     @Test
67     public void testEquals() {
68         assertThat(lo1, is(equalTo(lo3)));
69         assertThat(lo2, is(not(equalTo(lo3))));
70         assertThat(lo3, is(not(equalTo(null))));
71     }
72 }