]> git.basschouten.com Git - openhab-addons.git/blob
81262d0ce5638a291cc114eb31927a736471e55f
[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 static org.junit.jupiter.api.Assertions.assertEquals;
16 import static org.junit.jupiter.api.Assertions.assertNull;
17 import static org.junit.jupiter.api.Assertions.assertThrows;
18
19 import java.time.LocalDateTime;
20 import java.time.Month;
21
22 import org.eclipse.jdt.annotation.NonNullByDefault;
23 import org.junit.jupiter.api.Test;
24
25 /**
26  * Unit test for ModelHelper class.
27  *
28  * @author Jørgen Austvik - Initial contribution
29  */
30 @NonNullByDefault
31 public class ModelHelperTest {
32
33     @Test
34     public void testParseJavaStringNoSpace() {
35         assertEquals("NoSpace", ModelHelper.toJavaString("NoSpace"));
36     }
37
38     @Test
39     public void testParseJavaStringNormalSpace() {
40         assertEquals("Contains Space", ModelHelper.toJavaString("Contains Space"));
41     }
42
43     @Test
44     public void testParseJavaStringNoBreakSpace() {
45         assertEquals("Contains NoBreak Space", ModelHelper.toJavaString("Contains" + (char) 160 + "NoBreak Space"));
46     }
47
48     @Test
49     public void testGenerateNoboStringNoSpace() {
50         assertEquals("NoSpace", ModelHelper.toHubString("NoSpace"));
51     }
52
53     @Test
54     public void testGenerateNoboStringNormalSpace() {
55         assertEquals("Contains" + (char) 160 + "NoBreak", ModelHelper.toHubString("Contains" + (char) 160 + "NoBreak"));
56     }
57
58     @Test
59     public void testGenerateNoboStringNoBreakSpace() {
60         assertEquals("Contains" + (char) 160 + "NoBreak" + (char) 160 + "Space",
61                 ModelHelper.toHubString("Contains NoBreak Space"));
62     }
63
64     @Test
65     public void testParseNull() throws NoboDataException {
66         assertNull(ModelHelper.toJavaDate("-1"));
67     }
68
69     @Test
70     public void testParseDate() throws NoboDataException {
71         LocalDateTime date = LocalDateTime.of(2020, Month.JANUARY, 22, 19, 30);
72         assertEquals(date, ModelHelper.toJavaDate("202001221930"));
73     }
74
75     @Test()
76     public void testParseIllegalDate() {
77         assertThrows(NoboDataException.class, () -> ModelHelper.toJavaDate("20201322h1930"));
78     }
79
80     @Test
81     public void testGenerateNoboDate() {
82         LocalDateTime date = LocalDateTime.of(2020, Month.JANUARY, 22, 19, 30);
83         assertEquals("202001221930", ModelHelper.toHubDateMinutes(date));
84     }
85 }