]> git.basschouten.com Git - openhab-addons.git/blob
22f4b21a7536461c41a697c11d9b2ea6f7ddbd53
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2023 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.energidataservice.internal.retry.strategy;
14
15 import static org.hamcrest.CoreMatchers.*;
16 import static org.hamcrest.MatcherAssert.assertThat;
17 import static org.hamcrest.Matchers.is;
18
19 import java.time.Clock;
20 import java.time.Duration;
21 import java.time.Instant;
22 import java.time.LocalTime;
23 import java.time.ZoneId;
24
25 import org.eclipse.jdt.annotation.NonNullByDefault;
26 import org.junit.jupiter.api.Test;
27 import org.openhab.binding.energidataservice.internal.retry.RetryStrategy;
28
29 /**
30  * Tests for {@link FixedTime}.
31  * 
32  * @author Jacob Laursen - Initial contribution
33  */
34 @NonNullByDefault
35 public class FixedTimeTest {
36
37     @Test
38     void beforeNoon() {
39         RetryStrategy retryPolicy = new FixedTime(LocalTime.of(12, 0),
40                 Clock.fixed(Instant.parse("2023-01-24T10:00:00Z"), ZoneId.of("UTC")));
41         assertThat(retryPolicy.getDuration(), is(Duration.ofHours(2)));
42     }
43
44     @Test
45     void atNoon() {
46         RetryStrategy retryPolicy = new FixedTime(LocalTime.of(12, 0),
47                 Clock.fixed(Instant.parse("2023-01-24T12:00:00Z"), ZoneId.of("UTC")));
48         assertThat(retryPolicy.getDuration(), is(Duration.ZERO));
49     }
50
51     @Test
52     void afterNoon() {
53         RetryStrategy retryPolicy = new FixedTime(LocalTime.of(12, 0),
54                 Clock.fixed(Instant.parse("2023-01-24T13:00:00Z"), ZoneId.of("UTC")));
55         assertThat(retryPolicy.getDuration(), is(Duration.ofHours(23)));
56     }
57 }