View Javadoc

1   package com.google.code.jetm.maven.data;
2   
3   import static org.fest.assertions.Assertions.assertThat;
4   
5   import org.junit.Rule;
6   import org.junit.Test;
7   import org.junit.rules.ExpectedException;
8   
9   import com.google.code.jetm.maven.TimingReportMojo;
10  /**
11   * Unit tests for {@link TimeUnit}.
12   * 
13   * @author jrh3k5
14   * 
15   */
16  
17  public class TimeUnitTest {
18      /**
19       * A {@link Rule} used to test for thrown exceptions.
20       */
21      @Rule
22      public ExpectedException expected = ExpectedException.none();
23  
24      /**
25       * Test the retrieval of a time unit by the {@link TimingReportMojo} abbreviations for time units.
26       */
27      @Test
28      public void testFromMojoAbbreviation() {
29          assertThat(TimeUnit.fromMojoAbbreviation("millis")).isEqualTo(TimeUnit.MILLISECONDS);
30          assertThat(TimeUnit.fromMojoAbbreviation("secs")).isEqualTo(TimeUnit.SECONDS);
31      }
32  
33      /**
34       * Looking up an unknown abbreviation should fail.
35       */
36      @Test
37      public void testFromMojoAbbreviationUnknownAbbreviation() {
38          final String abbreviation = "what is this i don't even";
39          expected.expect(IllegalArgumentException.class);
40          expected.expectMessage("Unrecognized time unit abbreviation: " + abbreviation);
41          TimeUnit.fromMojoAbbreviation(abbreviation);
42      }
43  
44      /**
45       * Test the retrieval of the display name.
46       */
47      @Test
48      public void testGetDisplayName() {
49          assertThat(TimeUnit.MILLISECONDS.getDisplayName()).isEqualTo("ms");
50          assertThat(TimeUnit.SECONDS.getDisplayName()).isEqualTo("sec");
51      }
52  
53      /**
54       * Test the conversion of microseconds to seconds.
55       */
56      @Test
57      public void testMillisecondsToSeconds() {
58          assertThat(TimeUnit.SECONDS.fromMilliseconds(1500)).isEqualTo(1.5);
59      }
60  
61      /**
62       * Test the conversion between two microsecond values.
63       */
64      @Test
65      public void testMillisecondsToMilliseconds() {
66          assertThat(TimeUnit.MILLISECONDS.fromMilliseconds(1200)).isEqualTo(1200);
67      }
68  }