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.energidataservice.internal.api.serialization;
15 import static org.hamcrest.MatcherAssert.assertThat;
16 import static org.hamcrest.Matchers.equalTo;
17 import static org.hamcrest.Matchers.is;
18 import static org.junit.jupiter.api.Assertions.assertThrows;
20 import java.time.LocalDateTime;
22 import org.eclipse.jdt.annotation.NonNullByDefault;
23 import org.eclipse.jdt.annotation.Nullable;
24 import org.junit.jupiter.api.Test;
25 import org.junit.jupiter.api.extension.ExtendWith;
26 import org.mockito.junit.jupiter.MockitoExtension;
28 import com.google.gson.Gson;
29 import com.google.gson.GsonBuilder;
30 import com.google.gson.JsonParseException;
33 * Tests for {@link LocalDateDeserializer}.
35 * @author Jacob Laursen - Initial contribution
38 @ExtendWith(MockitoExtension.class)
39 public class LocalDateDeserializerTest {
41 private final Gson gson = new GsonBuilder()
42 .registerTypeAdapter(LocalDateTime.class, new LocalDateTimeDeserializer()).create();
45 void localDateTimeWhenInvalidShouldThrowJsonParseException() {
46 assertThrows(JsonParseException.class, () -> {
47 gson.fromJson("\"invalid\"", LocalDateTime.class);
52 void instantWhenValidShouldParse() {
53 assertThat((@Nullable LocalDateTime) gson.fromJson("\"2023-04-17T20:38:01\"", LocalDateTime.class),
54 is(equalTo(LocalDateTime.of(2023, 4, 17, 20, 38, 1, 0))));