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.nobohub.internal.model;
15 import org.eclipse.jdt.annotation.NonNullByDefault;
16 import org.junit.jupiter.api.Assertions;
17 import org.junit.jupiter.api.Test;
20 * Unit tests for ComponentRegister model object.
22 * @author Jørgen Austvik - Initial contribution
25 public class ComponentRegisterTest {
28 public void testPutGet() throws NoboDataException {
29 Component c = Component.fromH02("H02 186170024143 0 Kontor 0 1 -1 -1");
30 ComponentRegister sut = new ComponentRegister();
32 Assertions.assertEquals(c, sut.get(c.getSerialNumber()));
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();
42 Assertions.assertEquals(c2, sut.get(c2.getSerialNumber()));
46 public void testRemove() throws NoboDataException {
47 Component c = Component.fromH02("H02 186170024143 0 Kontor 0 1 -1 -1");
48 ComponentRegister sut = new ComponentRegister();
50 Component res = sut.remove(c.getSerialNumber());
51 Assertions.assertEquals(c, res);
55 public void testRemoveUnknown() {
56 ComponentRegister sut = new ComponentRegister();
57 Component res = sut.remove(new SerialNumber("123123123123"));
58 Assertions.assertEquals(null, res);
62 public void testGetUnknown() {
63 ComponentRegister sut = new ComponentRegister();
64 Component z = sut.get(new SerialNumber("123123123123"));
65 Assertions.assertEquals(null, z);
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();
75 Assertions.assertEquals(2, sut.values().size());
76 Assertions.assertEquals(true, sut.values().contains(c1));
77 Assertions.assertEquals(true, sut.values().contains(c2));