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.solarmax.internal.connector;
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;
19 import java.time.ZonedDateTime;
20 import java.util.HashMap;
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;
29 * The {@link SolarMaxDataTest} class is used to test the {@link SolaMaxData} class.
31 * @author Jamie Townsend - Initial contribution
34 public class SolarMaxDataTest {
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);
42 SolarMaxData solarMaxData = new SolarMaxData();
44 solarMaxData.setDataDateTime(dateTimeOriginal);
45 assertEquals(new DateTimeType(dateTimeOriginal), solarMaxData.getDataDateTime());
47 solarMaxData.setDataDateTime(dateTimeUpdated);
48 assertEquals(new DateTimeType(dateTimeUpdated), solarMaxData.getDataDateTime());
52 public void valueGetterSetterTest() throws Exception {
53 String startupsOriginal = "3B8B"; // 15243 in hex
54 String startupsUpdated = "3B8C"; // 15244 in hex
56 SolarMaxData solarMaxData = new SolarMaxData();
58 Map<SolarMaxCommandKey, @Nullable String> dataOrig = new HashMap<>();
59 dataOrig.put(SolarMaxCommandKey.startups, startupsOriginal);
60 solarMaxData.setData(dataOrig);
63 Number origVersion = solarMaxData.get(SolarMaxCommandKey.startups);
65 assertNotNull(origVersion);
66 assertEquals(Integer.parseInt(startupsOriginal, 16), origVersion.intValue());
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);