]> git.basschouten.com Git - openhab-addons.git/blob
067af55b19a96615847b09f998f4f13a916d909f
[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.nobohub.internal.model;
14
15 import org.eclipse.jdt.annotation.NonNullByDefault;
16 import org.junit.jupiter.api.Assertions;
17 import org.junit.jupiter.api.Test;
18
19 /**
20  * Unit tests for ComponentRegister model object.
21  *
22  * @author Jørgen Austvik - Initial contribution
23  */
24 @NonNullByDefault
25 public class ComponentRegisterTest {
26
27     @Test
28     public void testPutGet() throws NoboDataException {
29         Component c = Component.fromH02("H02 186170024143 0 Kontor 0 1 -1 -1");
30         ComponentRegister sut = new ComponentRegister();
31         sut.put(c);
32         Assertions.assertEquals(c, sut.get(c.getSerialNumber()));
33     }
34
35     @Test
36     public void testPutOverwrite() throws NoboDataException {
37         Component c1 = Component.fromH02("H02 186170024143 0 Kontor 0 1 -1 -1");
38         Component c2 = Component.fromH02("H02 186170024143 0 Bad 0 1 -1 -1");
39         ComponentRegister sut = new ComponentRegister();
40         sut.put(c1);
41         sut.put(c2);
42         Assertions.assertEquals(c2, sut.get(c2.getSerialNumber()));
43     }
44
45     @Test
46     public void testRemove() throws NoboDataException {
47         Component c = Component.fromH02("H02 186170024143 0 Kontor 0 1 -1 -1");
48         ComponentRegister sut = new ComponentRegister();
49         sut.put(c);
50         Component res = sut.remove(c.getSerialNumber());
51         Assertions.assertEquals(c, res);
52     }
53
54     @Test
55     public void testRemoveUnknown() {
56         ComponentRegister sut = new ComponentRegister();
57         Component res = sut.remove(new SerialNumber("123123123123"));
58         Assertions.assertEquals(null, res);
59     }
60
61     @Test
62     public void testGetUnknown() {
63         ComponentRegister sut = new ComponentRegister();
64         Component z = sut.get(new SerialNumber("123123123123"));
65         Assertions.assertEquals(null, z);
66     }
67
68     @Test
69     public void testValues() throws NoboDataException {
70         Component c1 = Component.fromH02("H02 186170024141 0 Kontor 0 1 -1 -1");
71         Component c2 = Component.fromH02("H02 186170024142 0 Soverom 0 1 -1 -1");
72         ComponentRegister sut = new ComponentRegister();
73         sut.put(c1);
74         sut.put(c2);
75         Assertions.assertEquals(2, sut.values().size());
76         Assertions.assertEquals(true, sut.values().contains(c1));
77         Assertions.assertEquals(true, sut.values().contains(c2));
78     }
79 }