View Javadoc
1   /**
2    * Logback: the reliable, generic, fast and flexible logging framework.
3    * Copyright (C) 1999-2015, QOS.ch. All rights reserved.
4    *
5    * This program and the accompanying materials are dual-licensed under
6    * either the terms of the Eclipse Public License v1.0 as published by
7    * the Eclipse Foundation
8    *
9    *   or (per the licensee's choosing)
10   *
11   * under the terms of the GNU Lesser General Public License version 2.1
12   * as published by the Free Software Foundation.
13   */
14  package ch.qos.logback.core.util;
15  
16  import org.junit.jupiter.api.Assertions;
17  import org.junit.jupiter.api.Test;
18  
19  import static org.junit.jupiter.api.Assertions.assertEquals;
20  
21  public class DurationTest {
22  
23      static long HOURS_CO = 60 * 60;
24      static long DAYS_CO = 24 * 60 * 60;
25  
26      @Test
27      public void test() {
28          {
29              Duration d = Duration.valueOf("12");
30              assertEquals(12, d.getMilliseconds());
31          }
32  
33          {
34              Duration d = Duration.valueOf("159 milli");
35              assertEquals(159, d.getMilliseconds());
36          }
37  
38          {
39              Duration d = Duration.valueOf("15 millis");
40              assertEquals(15, d.getMilliseconds());
41          }
42  
43          {
44              Duration d = Duration.valueOf("8 milliseconds");
45              assertEquals(8, d.getMilliseconds());
46          }
47  
48          {
49              Duration d = Duration.valueOf("10.7 millisecond");
50              assertEquals(10, d.getMilliseconds());
51          }
52  
53          {
54              Duration d = Duration.valueOf("10 SECOnds");
55              assertEquals(10 * 1000, d.getMilliseconds());
56          }
57  
58          {
59              Duration d = Duration.valueOf("12seconde");
60              assertEquals(12 * 1000, d.getMilliseconds());
61          }
62  
63          {
64              Duration d = Duration.valueOf("14 SECONDES");
65              assertEquals(14 * 1000, d.getMilliseconds());
66          }
67  
68          {
69              Duration d = Duration.valueOf("12second");
70              assertEquals(12 * 1000, d.getMilliseconds());
71          }
72  
73          {
74              Duration d = Duration.valueOf("10.7 seconds");
75              assertEquals(10700, d.getMilliseconds());
76          }
77  
78          {
79              Duration d = Duration.valueOf("1 minute");
80              assertEquals(1000 * 60, d.getMilliseconds());
81          }
82  
83          {
84              Duration d = Duration.valueOf("2.2 minutes");
85              assertEquals(2200 * 60, d.getMilliseconds());
86          }
87  
88          {
89              Duration d = Duration.valueOf("1 hour");
90              assertEquals(1000 * HOURS_CO, d.getMilliseconds());
91          }
92  
93          {
94              Duration d = Duration.valueOf("4.2 hours");
95              assertEquals(4200 * HOURS_CO, d.getMilliseconds());
96          }
97  
98          {
99              Duration d = Duration.valueOf("5 days");
100             assertEquals(5000 * DAYS_CO, d.getMilliseconds());
101         }
102     }
103 }