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 static org.junit.Assert.assertEquals;
17  
18  import org.junit.Test;
19  
20  public class DurationTest {
21  
22      static long HOURS_CO = 60 * 60;
23      static long DAYS_CO = 24 * 60 * 60;
24  
25      @Test
26      public void test() {
27          {
28              Duration d = Duration.valueOf("12");
29              assertEquals(12, d.getMilliseconds());
30          }
31  
32          {
33              Duration d = Duration.valueOf("159 milli");
34              assertEquals(159, d.getMilliseconds());
35          }
36  
37          {
38              Duration d = Duration.valueOf("15 millis");
39              assertEquals(15, d.getMilliseconds());
40          }
41  
42          {
43              Duration d = Duration.valueOf("8 milliseconds");
44              assertEquals(8, d.getMilliseconds());
45          }
46  
47          {
48              Duration d = Duration.valueOf("10.7 millisecond");
49              assertEquals(10, d.getMilliseconds());
50          }
51  
52          {
53              Duration d = Duration.valueOf("10 SECOnds");
54              assertEquals(10 * 1000, d.getMilliseconds());
55          }
56  
57          {
58              Duration d = Duration.valueOf("12seconde");
59              assertEquals(12 * 1000, d.getMilliseconds());
60          }
61  
62          {
63              Duration d = Duration.valueOf("14 SECONDES");
64              assertEquals(14 * 1000, d.getMilliseconds());
65          }
66  
67          {
68              Duration d = Duration.valueOf("12second");
69              assertEquals(12 * 1000, d.getMilliseconds());
70          }
71  
72          {
73              Duration d = Duration.valueOf("10.7 seconds");
74              assertEquals(10700, d.getMilliseconds());
75          }
76  
77          {
78              Duration d = Duration.valueOf("1 minute");
79              assertEquals(1000 * 60, d.getMilliseconds());
80          }
81  
82          {
83              Duration d = Duration.valueOf("2.2 minutes");
84              assertEquals(2200 * 60, d.getMilliseconds());
85          }
86  
87          {
88              Duration d = Duration.valueOf("1 hour");
89              assertEquals(1000 * HOURS_CO, d.getMilliseconds());
90          }
91  
92          {
93              Duration d = Duration.valueOf("4.2 hours");
94              assertEquals(4200 * HOURS_CO, d.getMilliseconds());
95          }
96  
97          {
98              Duration d = Duration.valueOf("5 days");
99              assertEquals(5000 * DAYS_CO, d.getMilliseconds());
100         }
101     }
102 }