]> git.basschouten.com Git - openhab-addons.git/blob
54c658cb5fbc75be447ebab5a78bc820a30150ed
[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.Assert.assertEquals;
19
20 import java.time.Duration;
21
22 import org.junit.Test;
23 import org.openhab.binding.sleepiq.api.model.TimeSince;
24
25 public class TimeSinceTest
26 {
27     @Test
28     public void testWithDuration()
29     {
30         assertEquals(new TimeSince().withDuration(0, 0, 0, 0).getDuration(),
31                      new TimeSince().withDuration(Duration.parse("PT00H00M00S")).getDuration());
32         assertEquals(new TimeSince().withDuration(0, 2, 3, 4).getDuration(),
33                      new TimeSince().withDuration(Duration.parse("PT02H03M04S")).getDuration());
34         assertEquals(new TimeSince().withDuration(0, 12, 34, 56).getDuration(),
35                      new TimeSince().withDuration(Duration.parse("PT12H34M56S")).getDuration());
36         assertEquals(new TimeSince().withDuration(1, 2, 3, 4).getDuration(),
37                      new TimeSince().withDuration(Duration.parse("P1DT02H03M04S")).getDuration());
38         assertEquals(new TimeSince().withDuration(12, 23, 34, 45).getDuration(),
39                      new TimeSince().withDuration(Duration.parse("P12DT23H34M45S")).getDuration());
40     }
41
42     @Test
43     public void testToString()
44     {
45         assertEquals("00:00:00",
46                      new TimeSince().withDuration(Duration.parse("PT00H00M00S")).toString());
47         assertEquals("02:03:04",
48                      new TimeSince().withDuration(Duration.parse("PT02H03M04S")).toString());
49         assertEquals("12:34:56",
50                      new TimeSince().withDuration(Duration.parse("PT12H34M56S")).toString());
51         assertEquals("1 d 02:03:04",
52                      new TimeSince().withDuration(Duration.parse("P1DT02H03M04S")).toString());
53         assertEquals("12 d 23:34:45",
54                      new TimeSince().withDuration(Duration.parse("P12DT23H34M45S")).toString());
55     }
56
57     @Test
58     public void testParse()
59     {
60         assertEquals(Duration.parse("PT00H00M00S"), TimeSince.parse("00:00:00").getDuration());
61         assertEquals(Duration.parse("PT2H3M4S"), TimeSince.parse("02:03:04").getDuration());
62         assertEquals(Duration.parse("PT12H34M56S"), TimeSince.parse("12:34:56").getDuration());
63         assertEquals(Duration.parse("P1DT2H3M4S"), TimeSince.parse("1 d 02:03:04").getDuration());
64         assertEquals(Duration.parse("P12DT23H34M45S"),
65                      TimeSince.parse("12 d 23:34:45").getDuration());
66     }
67 }