View Javadoc

1   /**
2    * BSD-style license; for more info see http://pmd.sourceforge.net/license.html
3    */
4   package net.sourceforge.pmd;
5   
6   import static org.junit.Assert.assertEquals;
7   
8   import java.util.Arrays;
9   import java.util.Collection;
10  
11  import junit.framework.JUnit4TestAdapter;
12  
13  import org.junit.Test;
14  import org.junit.runner.RunWith;
15  import org.junit.runners.Parameterized;
16  import org.junit.runners.Parameterized.Parameters;
17  
18  @RunWith(Parameterized.class)
19  public class ReadableDurationTest {
20  
21      private Integer value;
22      private String expected;
23  
24      public ReadableDurationTest(String expected, Integer value) {
25          this.value = value;
26          this.expected = expected;
27      }
28  
29      @Parameters
30      public static Collection<Object[]> data() {
31          return Arrays.asList(new Object[][]{
32                  {"0s", 35},
33                  {"25s", (25 * 1000)},
34                  {"5m 0s", (60 * 1000 * 5)},
35                  {"2h 0m 0s", (60 * 1000 * 120)}
36          });
37      }
38  
39      @Test
40      public void test() {
41          assertEquals(expected, new Report.ReadableDuration(value).getTime());
42      }
43  
44      public static junit.framework.Test suite() {
45          return new JUnit4TestAdapter(ReadableDurationTest.class);
46      }
47  }