]> git.basschouten.com Git - openhab-addons.git/blob
3239b8bac4aeccd9e03d44f699a4bb2ca002288e
[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.solarmax.internal.connector;
14
15 import static org.junit.jupiter.api.Assertions.assertEquals;
16 import static org.junit.jupiter.api.Assertions.assertNotEquals;
17 import static org.junit.jupiter.api.Assertions.assertNotNull;
18
19 import java.time.ZonedDateTime;
20 import java.util.HashMap;
21 import java.util.Map;
22
23 import org.eclipse.jdt.annotation.NonNullByDefault;
24 import org.eclipse.jdt.annotation.Nullable;
25 import org.junit.jupiter.api.Test;
26 import org.openhab.core.library.types.DateTimeType;
27
28 /**
29  * The {@link SolarMaxDataTest} class is used to test the {@link SolaMaxData} class.
30  *
31  * @author Jamie Townsend - Initial contribution
32  */
33 @NonNullByDefault
34 public class SolarMaxDataTest {
35
36     @Test
37     public void dataDateTimeGetterSetterTest() throws Exception {
38         // dataDateTime shouldn't be a problem, but check it anyway
39         ZonedDateTime dateTimeOriginal = ZonedDateTime.now();
40         ZonedDateTime dateTimeUpdated = dateTimeOriginal.plusDays(2);
41
42         SolarMaxData solarMaxData = new SolarMaxData();
43
44         solarMaxData.setDataDateTime(dateTimeOriginal);
45         assertEquals(new DateTimeType(dateTimeOriginal), solarMaxData.getDataDateTime());
46
47         solarMaxData.setDataDateTime(dateTimeUpdated);
48         assertEquals(new DateTimeType(dateTimeUpdated), solarMaxData.getDataDateTime());
49     }
50
51     @Test
52     public void valueGetterSetterTest() throws Exception {
53         String startupsOriginal = "3B8B"; // 15243 in hex
54         String startupsUpdated = "3B8C"; // 15244 in hex
55
56         SolarMaxData solarMaxData = new SolarMaxData();
57
58         Map<SolarMaxCommandKey, @Nullable String> dataOrig = new HashMap<>();
59         dataOrig.put(SolarMaxCommandKey.startups, startupsOriginal);
60         solarMaxData.setData(dataOrig);
61
62         @Nullable
63         Number origVersion = solarMaxData.get(SolarMaxCommandKey.startups);
64
65         assertNotNull(origVersion);
66         assertEquals(Integer.parseInt(startupsOriginal, 16), origVersion.intValue());
67
68         Map<SolarMaxCommandKey, @Nullable String> dataUpdated = new HashMap<>();
69         dataUpdated.put(SolarMaxCommandKey.startups, startupsUpdated);
70         solarMaxData.setData(dataUpdated);
71         Number updatedVersion = solarMaxData.get(SolarMaxCommandKey.startups);
72         assertNotEquals(origVersion, updatedVersion);
73     }
74 }