001/**
002 * Logback: the reliable, generic, fast and flexible logging framework.
003 * Copyright (C) 1999-2015, QOS.ch. All rights reserved.
004 *
005 * This program and the accompanying materials are dual-licensed under
006 * either the terms of the Eclipse Public License v1.0 as published by
007 * the Eclipse Foundation
008 *
009 *   or (per the licensee's choosing)
010 *
011 * under the terms of the GNU Lesser General Public License version 2.1
012 * as published by the Free Software Foundation.
013 */
014package ch.qos.logback.core.util;
015
016import static org.junit.Assert.assertEquals;
017
018import org.junit.Test;
019
020public class DurationTest {
021
022    static long HOURS_CO = 60 * 60;
023    static long DAYS_CO = 24 * 60 * 60;
024
025    @Test
026    public void test() {
027        {
028            Duration d = Duration.valueOf("12");
029            assertEquals(12, d.getMilliseconds());
030        }
031
032        {
033            Duration d = Duration.valueOf("159 milli");
034            assertEquals(159, d.getMilliseconds());
035        }
036
037        {
038            Duration d = Duration.valueOf("15 millis");
039            assertEquals(15, d.getMilliseconds());
040        }
041
042        {
043            Duration d = Duration.valueOf("8 milliseconds");
044            assertEquals(8, d.getMilliseconds());
045        }
046
047        {
048            Duration d = Duration.valueOf("10.7 millisecond");
049            assertEquals(10, d.getMilliseconds());
050        }
051
052        {
053            Duration d = Duration.valueOf("10 SECOnds");
054            assertEquals(10 * 1000, d.getMilliseconds());
055        }
056
057        {
058            Duration d = Duration.valueOf("12seconde");
059            assertEquals(12 * 1000, d.getMilliseconds());
060        }
061
062        {
063            Duration d = Duration.valueOf("14 SECONDES");
064            assertEquals(14 * 1000, d.getMilliseconds());
065        }
066
067        {
068            Duration d = Duration.valueOf("12second");
069            assertEquals(12 * 1000, d.getMilliseconds());
070        }
071
072        {
073            Duration d = Duration.valueOf("10.7 seconds");
074            assertEquals(10700, d.getMilliseconds());
075        }
076
077        {
078            Duration d = Duration.valueOf("1 minute");
079            assertEquals(1000 * 60, d.getMilliseconds());
080        }
081
082        {
083            Duration d = Duration.valueOf("2.2 minutes");
084            assertEquals(2200 * 60, d.getMilliseconds());
085        }
086
087        {
088            Duration d = Duration.valueOf("1 hour");
089            assertEquals(1000 * HOURS_CO, d.getMilliseconds());
090        }
091
092        {
093            Duration d = Duration.valueOf("4.2 hours");
094            assertEquals(4200 * HOURS_CO, d.getMilliseconds());
095        }
096
097        {
098            Duration d = Duration.valueOf("5 days");
099            assertEquals(5000 * DAYS_CO, d.getMilliseconds());
100        }
101    }
102}