2 * Copyright (c) 2010-2021 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.bmwconnecteddrive.internal.util;
15 import static org.junit.jupiter.api.Assertions.*;
17 import java.util.Locale;
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;
27 import com.google.gson.Gson;
30 * The {@link LocaleTest} is testing locale settings
32 * @author Bernd Weymann - Initial contribution
35 @SuppressWarnings("null")
36 public class LocaleTest {
37 private static final Gson GSON = new Gson();
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");
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;
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");
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");
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");
75 public void testDistance() {
78 double distance = 0.005;
79 double dist = Converter.measureDistance(lat, lon, lat + distance, lon + distance);
80 assertTrue(dist < 1, "Distance below 1 km");