]> git.basschouten.com Git - openhab-addons.git/blob
52cf44f86b651c9d31d264120145b91af1615406
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2020 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.luftdateninfo.internal.util;
14
15 import static org.junit.Assert.*;
16
17 import java.time.LocalDateTime;
18 import java.time.format.DateTimeParseException;
19
20 import org.eclipse.jdt.annotation.NonNullByDefault;
21 import org.junit.Test;
22 import org.openhab.binding.luftdateninfo.internal.utils.DateTimeUtils;
23
24 /**
25  * The {@link DateTimeTest} Test DateTimeFormatter provided in utils package
26  *
27  * @author Bernd Weymann - Initial contribution
28  */
29 @NonNullByDefault
30 public class DateTimeTest {
31
32     @Test
33     public void testJSonTime() {
34         String jsonDateString = "2020-08-14 14:53:21";
35         try {
36             LocalDateTime dt = LocalDateTime.from(DateTimeUtils.DTF.parse(jsonDateString));
37             assertEquals("Day ", 14, dt.getDayOfMonth());
38             assertEquals("Month ", 8, dt.getMonthValue());
39             assertEquals("Year ", 2020, dt.getYear());
40
41             String s = dt.format(DateTimeUtils.DTF);
42             assertEquals("String ", jsonDateString, s);
43         } catch (DateTimeParseException e) {
44             assertFalse(true);
45         }
46     }
47 }