View Javadoc

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