]> git.basschouten.com Git - openhab-addons.git/blob
13581dcad8acafa511f5691c84b3f992c211ac91
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2022 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.bmwconnecteddrive.internal.util;
14
15 import static org.junit.jupiter.api.Assertions.*;
16
17 import java.util.Locale;
18
19 import org.eclipse.jdt.annotation.NonNullByDefault;
20 import org.junit.jupiter.api.Test;
21 import org.openhab.binding.bmwconnecteddrive.internal.ConnectedDriveConstants;
22 import org.openhab.binding.bmwconnecteddrive.internal.dto.status.VehicleStatus;
23 import org.openhab.binding.bmwconnecteddrive.internal.dto.status.VehicleStatusContainer;
24 import org.openhab.binding.bmwconnecteddrive.internal.utils.Converter;
25 import org.openhab.core.library.types.DateTimeType;
26
27 import com.google.gson.Gson;
28
29 /**
30  * The {@link LocaleTest} is testing locale settings
31  *
32  * @author Bernd Weymann - Initial contribution
33  */
34 @NonNullByDefault
35 @SuppressWarnings("null")
36 public class LocaleTest {
37     private static final Gson GSON = new Gson();
38
39     @Test
40     public void languageTest() {
41         assertTrue(ConnectedDriveConstants.IMPERIAL_COUNTRIES.contains(Locale.UK.getCountry()), "United Kingdom");
42         assertTrue(ConnectedDriveConstants.IMPERIAL_COUNTRIES.contains(Locale.US.getCountry()), "United States");
43         assertFalse(ConnectedDriveConstants.IMPERIAL_COUNTRIES.contains(Locale.FRANCE.getCountry()), "France");
44         assertFalse(ConnectedDriveConstants.IMPERIAL_COUNTRIES.contains(Locale.GERMAN.getCountry()), "Germany");
45     }
46
47     public void testTimeUTCToLocaleTime() {
48         String resource1 = FileReader.readFileInString("src/test/resources/webapi/vehicle-status.json");
49         VehicleStatusContainer status = GSON.fromJson(resource1, VehicleStatusContainer.class);
50         VehicleStatus vStatus = status.vehicleStatus;
51
52         String inputTime = vStatus.internalDataTimeUTC;
53         String localeTime = Converter.getLocalDateTime(inputTime);
54         String dateTimeType = DateTimeType.valueOf(localeTime).toString();
55         assertEquals("2020-08-24T15:55:32", inputTime, "Input DateTime");
56         assertEquals("2020-08-24T17:55:32", localeTime, "Output DateTime");
57         assertEquals("2020-08-24T17:55:32.000+0200", dateTimeType, "DateTimeType Value");
58
59         inputTime = vStatus.updateTime;
60         localeTime = Converter.getLocalDateTime(inputTime);
61         dateTimeType = DateTimeType.valueOf(localeTime).toString();
62         assertEquals("2020-08-24T15:55:32+0000", inputTime, "Input DateTime");
63         assertEquals("2020-08-24T17:55:32", localeTime, "Output DateTime");
64         assertEquals("2020-08-24T17:55:32.000+0200", dateTimeType, "DateTimeType Value");
65
66         inputTime = vStatus.updateTime;
67         localeTime = Converter.getLocalDateTimeWithoutOffest(inputTime);
68         dateTimeType = DateTimeType.valueOf(localeTime).toString();
69         assertEquals("2020-08-24T15:55:32+0000", inputTime, "Input DateTime");
70         assertEquals("2020-08-24T15:55:32", localeTime, "Output DateTime");
71         assertEquals("2020-08-24T15:55:32.000+0200", dateTimeType, "DateTimeType Value");
72     }
73
74     @Test
75     public void testDistance() {
76         double lat = 45.678;
77         double lon = 8.765;
78         double distance = 0.005;
79         double dist = Converter.measureDistance(lat, lon, lat + distance, lon + distance);
80         assertTrue(dist < 1, "Distance below 1 km");
81     }
82 }