View Javadoc

1   package com.google.code.jetm.maven.data;
2   
3   import static org.fest.assertions.Assertions.assertThat;
4   import static org.mockito.Mockito.mock;
5   import static org.mockito.Mockito.when;
6   
7   import org.junit.Test;
8   
9   import etm.core.aggregation.Aggregate;
10  
11  /**
12   * Unit tests for {@link AggregateSummary}.
13   * 
14   * @author jrh3k5
15   * 
16   */
17  
18  public class AggregateSummaryTest {
19      /**
20       * Test the summary of two aggregates in a single {@link AggregateSummary}
21       * object.
22       */
23      @Test
24      public void testAdd() {
25          final Aggregate aggregateOne = mock(Aggregate.class);
26          when(aggregateOne.getMin()).thenReturn(Double.valueOf(1.0));
27          when(aggregateOne.getMax()).thenReturn(Double.valueOf(2.0));
28          when(aggregateOne.getTotal()).thenReturn(Double.valueOf(3.0));
29          when(aggregateOne.getMeasurements()).thenReturn(Long.valueOf(4));
30  
31          final Aggregate aggregateTwo = mock(Aggregate.class);
32          when(aggregateTwo.getMin()).thenReturn(Double.valueOf(5.0));
33          when(aggregateTwo.getMax()).thenReturn(Double.valueOf(6.0));
34          when(aggregateTwo.getTotal()).thenReturn(Double.valueOf(7.0));
35          when(aggregateTwo.getMeasurements()).thenReturn(Long.valueOf(8));
36  
37          final AggregateSummary summary = new AggregateSummary("a summary");
38          summary.add(aggregateOne);
39          summary.add(aggregateTwo);
40  
41          assertThat(summary.getMin()).isEqualTo(aggregateOne.getMin());
42          assertThat(summary.getMax()).isEqualTo(aggregateTwo.getMax());
43          assertThat(summary.getTotal()).isEqualTo(aggregateOne.getTotal() + aggregateTwo.getTotal());
44          assertThat(summary.getMeasurements()).isEqualTo(
45                  aggregateOne.getMeasurements() + aggregateTwo.getMeasurements());
46      }
47  
48      /**
49       * Test the comparison of two {@link AggregateSummary} objects. Two
50       * summaries by the same name should match; those with different names
51       * should not match.
52       */
53      @Test
54      public void testCompareTo() {
55          final AggregateSummary summaryA = new AggregateSummary("summaryA");
56          final AggregateSummary summaryACopy = new AggregateSummary(summaryA.getName());
57          
58          assertThat(summaryA.compareTo(summaryACopy)).isZero();
59          assertThat(summaryACopy.compareTo(summaryA)).isZero();
60          
61          final AggregateSummary summaryB = new AggregateSummary("summaryB");
62          assertThat(summaryA.compareTo(summaryB)).isLessThan(0);
63          assertThat(summaryB.compareTo(summaryA)).isGreaterThan(0);
64      }
65  
66  }