View Javadoc

1   // Copyright (C) 2008 Philip Aston
2   // All rights reserved.
3   //
4   // This file is part of The Grinder software distribution. Refer to
5   // the file LICENSE which is part of The Grinder distribution for
6   // licensing details. The Grinder distribution is available on the
7   // Internet at http://grinder.sourceforge.net/
8   //
9   // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
10  // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
11  // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
12  // FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
13  // COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
14  // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
15  // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
16  // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
17  // HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
18  // STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
19  // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
20  // OF THE POSSIBILITY OF SUCH DAMAGE.
21  
22  package net.grinder.console.model;
23  
24  import net.grinder.common.StubTest;
25  import net.grinder.common.Test;
26  import net.grinder.statistics.StatisticsServices;
27  import net.grinder.statistics.StatisticsServicesImplementation;
28  import net.grinder.statistics.StatisticsSet;
29  import junit.framework.TestCase;
30  
31  
32  /**
33   * Unit tests for {@link ModelTestIndex}.
34   *
35   * @author Philip Aston
36   */
37  public class TestModelTestIndex extends TestCase {
38  
39    public void testConstruction() throws Exception {
40      final ModelTestIndex nullModelTestIndex = new ModelTestIndex();
41      assertEquals(0, nullModelTestIndex.getNumberOfTests());
42      assertEquals(0, nullModelTestIndex.getAccumulatorArray().length);
43  
44      final StatisticsServices statisticsServices =
45        StatisticsServicesImplementation.getInstance();
46  
47      final Test[] tests =
48        new Test[] {
49          new StubTest(100, "first test"),
50          new StubTest(101, "second test"),
51        };
52  
53      final SampleAccumulator[] accumulators =
54        new SampleAccumulator[] {
55          new SampleAccumulator(
56            null, null, statisticsServices.getStatisticsSetFactory()),
57          new SampleAccumulator(
58            null, null, statisticsServices.getStatisticsSetFactory()),
59        };
60  
61      final ModelTestIndex modelTestIndex =
62        new ModelTestIndex(tests, accumulators);
63  
64      assertEquals(tests.length, modelTestIndex.getNumberOfTests());
65      assertSame(tests[0], modelTestIndex.getTest(0));
66      assertSame(tests[1], modelTestIndex.getTest(1));
67  
68      final StatisticsSet cumulativeStatistics0 =
69        modelTestIndex.getCumulativeStatistics(0);
70  
71      assertNotNull(cumulativeStatistics0);
72      assertSame(cumulativeStatistics0, cumulativeStatistics0);
73      assertNotSame(cumulativeStatistics0,
74                    modelTestIndex.getCumulativeStatistics(1));
75  
76      final StatisticsSet lastSampleStatistics0 =
77        modelTestIndex.getLastSampleStatistics(0);
78  
79      assertNotNull(lastSampleStatistics0);
80      assertSame(lastSampleStatistics0, lastSampleStatistics0);
81      assertNotSame(lastSampleStatistics0,
82                    modelTestIndex.getLastSampleStatistics(1));
83  
84      assertNotSame(cumulativeStatistics0, lastSampleStatistics0);
85    }
86  }