]> git.basschouten.com Git - openhab-addons.git/blob
3e5d3d14be03122fcf4005ad4a42f38d0a3a43c1
[openhab-addons.git] /
1 /*
2  * Copyright 2017 Gregory Moyer
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 package org.openhab.binding.sleepiq.api.model;
17
18 import static org.junit.jupiter.api.Assertions.assertEquals;
19
20 import java.time.Duration;
21
22 import org.junit.jupiter.api.Test;
23
24 public class TimeSinceTest {
25     @Test
26     public void testWithDuration() {
27         assertEquals(new TimeSince().withDuration(0, 0, 0, 0).getDuration(),
28                 new TimeSince().withDuration(Duration.parse("PT00H00M00S")).getDuration());
29         assertEquals(new TimeSince().withDuration(0, 2, 3, 4).getDuration(),
30                 new TimeSince().withDuration(Duration.parse("PT02H03M04S")).getDuration());
31         assertEquals(new TimeSince().withDuration(0, 12, 34, 56).getDuration(),
32                 new TimeSince().withDuration(Duration.parse("PT12H34M56S")).getDuration());
33         assertEquals(new TimeSince().withDuration(1, 2, 3, 4).getDuration(),
34                 new TimeSince().withDuration(Duration.parse("P1DT02H03M04S")).getDuration());
35         assertEquals(new TimeSince().withDuration(12, 23, 34, 45).getDuration(),
36                 new TimeSince().withDuration(Duration.parse("P12DT23H34M45S")).getDuration());
37     }
38
39     @Test
40     public void testToString() {
41         assertEquals("00:00:00", new TimeSince().withDuration(Duration.parse("PT00H00M00S")).toString());
42         assertEquals("02:03:04", new TimeSince().withDuration(Duration.parse("PT02H03M04S")).toString());
43         assertEquals("12:34:56", new TimeSince().withDuration(Duration.parse("PT12H34M56S")).toString());
44         assertEquals("1 d 02:03:04", new TimeSince().withDuration(Duration.parse("P1DT02H03M04S")).toString());
45         assertEquals("12 d 23:34:45", new TimeSince().withDuration(Duration.parse("P12DT23H34M45S")).toString());
46     }
47
48     @Test
49     public void testParse() {
50         assertEquals(Duration.parse("PT00H00M00S"), TimeSince.parse("00:00:00").getDuration());
51         assertEquals(Duration.parse("PT2H3M4S"), TimeSince.parse("02:03:04").getDuration());
52         assertEquals(Duration.parse("PT12H34M56S"), TimeSince.parse("12:34:56").getDuration());
53         assertEquals(Duration.parse("P1DT2H3M4S"), TimeSince.parse("1 d 02:03:04").getDuration());
54         assertEquals(Duration.parse("P12DT23H34M45S"), TimeSince.parse("12 d 23:34:45").getDuration());
55     }
56 }