blob: da1365d94f493137884798368b72cce360d7e00a [file] [log] [blame]
Jian Lib6859e12016-03-01 09:29:24 -08001/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2016-present Open Networking Laboratory
Jian Lib6859e12016-03-01 09:29:24 -08003 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16package org.onosproject.ui.chart;
17
18import org.junit.Test;
19
20import static org.hamcrest.Matchers.is;
21import static org.junit.Assert.assertArrayEquals;
22import static org.junit.Assert.assertEquals;
23import static org.junit.Assert.assertThat;
24
25/**
26 * Unit tests for {@link ChartModel}.
27 */
28public class ChartModelTest {
29
30 private static final String FOO = "foo";
31 private static final String BAR = "bar";
32 private static final String ZOO = "zoo";
33
34 private static final Double[] VALUES1 = {0D, 1D, 2D};
35 private static final Double[] VALUES2 = {3D, 4D, 5D};
36 private static final Double[] VALUES3 = {6D, 7D, 8D};
37
38 private static final String[] SERIES = {FOO, BAR, ZOO};
39
40 private ChartModel cm;
41
42 @Test(expected = NullPointerException.class)
43 public void guardAgainstNullSeries() {
44 cm = new ChartModel(1, null);
45 }
46
47 @Test(expected = IllegalArgumentException.class)
48 public void guardAgainstWrongDpNumber() {
49 cm = new ChartModel(0, FOO);
50 }
51
52 @Test
53 public void testSeriesCount() {
54 cm = new ChartModel(1, FOO, BAR, ZOO);
55 assertEquals("Wrong series count", 3, cm.seriesCount());
56 }
57
58 @Test
59 public void testAddDataPoint() {
60 cm = new ChartModel(2, FOO, BAR, ZOO);
61
62 cm.addDataPoint("1", VALUES1);
63 cm.addDataPoint("2", VALUES2);
64
65 assertEquals("Wrong result", "1", cm.getDataPoints()[0].getLabel());
66 assertEquals("Wrong result", "2", cm.getDataPoints()[1].getLabel());
67
68 cm.addDataPoint("3", VALUES3);
69
70 assertEquals("Wrong result", "2", cm.getDataPoints()[0].getLabel());
71 assertEquals("Wrong result", "3", cm.getDataPoints()[1].getLabel());
72 }
73
74 @Test
75 public void testGetData() {
76 cm = new ChartModel(2, FOO, BAR, ZOO);
77
78 cm.addDataPoint("1", VALUES1);
79 assertThat(cm.getLastDataPoint().getValue(ZOO), is(2D));
80
81 cm.addDataPoint("2", VALUES2);
82 assertThat(cm.getLastDataPoint().getValue(BAR), is(4D));
83 }
84
85 @Test
86 public void testGetSeries() {
87 cm = new ChartModel(1, FOO, BAR, ZOO);
88
89 assertArrayEquals("series", SERIES, cm.getSeries());
90 }
91}