View Javadoc

1   // Copyright (C) 2000 Paco Gomez
2   // Copyright (C) 2000 - 2009 Philip Aston
3   // All rights reserved.
4   //
5   // This file is part of The Grinder software distribution. Refer to
6   // the file LICENSE which is part of The Grinder distribution for
7   // licensing details. The Grinder distribution is available on the
8   // Internet at http://grinder.sourceforge.net/
9   //
10  // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
11  // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
12  // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
13  // FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
14  // COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
15  // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
16  // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
17  // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
18  // HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
19  // STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
20  // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
21  // OF THE POSSIBILITY OF SUCH DAMAGE.
22  
23  package net.grinder.statistics;
24  
25  import net.grinder.statistics.StatisticExpressionFactoryImplementation.ParseContext.ParseException;
26  import net.grinder.testutility.RandomStubFactory;
27  import junit.framework.TestCase;
28  
29  
30  
31  /**
32   * Unit test case for <code>CommonStatisticsViews</code>.
33   *
34   * @author Philip Aston
35   * @see StatisticsSet
36   **/
37  public class TestCommonStatisticsViews extends TestCase {
38  
39    public TestCommonStatisticsViews(String name) {
40    super(name);
41    }
42  
43    public void testGetViews() throws Exception {
44  
45      final StatisticsIndexMap statisticsIndexMap = new StatisticsIndexMap();
46      final StatisticExpressionFactory statisticExpressionFactory =
47        new StatisticExpressionFactoryImplementation(statisticsIndexMap);
48  
49      final CommonStatisticsViews commonStatisticsViews =
50        new CommonStatisticsViews(statisticExpressionFactory);
51  
52      final StatisticsView detail =
53        commonStatisticsViews.getDetailStatisticsView();
54  
55      final ExpressionView[] detailExpressionViews = detail.getExpressionViews();
56  
57      assertTrue(detailExpressionViews.length > 0);
58  
59      final StatisticsView summary =
60        commonStatisticsViews.getSummaryStatisticsView();
61  
62      final ExpressionView[] summaryExpressionViews =
63        summary.getExpressionViews();
64  
65      assertTrue(summaryExpressionViews.length > 0);
66    }
67  
68    public void testGetViewsWithBrokenStatisticsExpressionFactory()
69      throws Exception {
70      final RandomStubFactory<StatisticExpressionFactory>
71        statisticExpressionFactoryStubFactory =
72          RandomStubFactory.create(StatisticExpressionFactory.class);
73  
74      statisticExpressionFactoryStubFactory.setThrows(
75        "createExpressionView", new ParseException("Broken", "foo", 0));
76  
77      try {
78        new CommonStatisticsViews(
79          statisticExpressionFactoryStubFactory.getStub());
80        fail("Expected AssertionError");
81      }
82      catch (AssertionError e) {
83      }
84    }
85  }