Committed by
Gerrit Code Review
Unit tests for DefaultLoad class
Change-Id: I9f661bbb20199c190076bcf71537c6c881cebc3a
Showing
1 changed file
with
92 additions
and
0 deletions
1 | +/* | ||
2 | + * Copyright 2015 Open Networking Laboratory | ||
3 | + * | ||
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 | + */ | ||
16 | +package org.onosproject.net.statistic; | ||
17 | + | ||
18 | +import org.junit.Before; | ||
19 | +import org.junit.Test; | ||
20 | + | ||
21 | +import static org.hamcrest.MatcherAssert.assertThat; | ||
22 | +import static org.hamcrest.Matchers.containsString; | ||
23 | +import static org.hamcrest.Matchers.is; | ||
24 | +import static org.hamcrest.core.IsNot.not; | ||
25 | + | ||
26 | +/** | ||
27 | + * Unit tests for DefaultLoad class. | ||
28 | + */ | ||
29 | +public class DefaultLoadTest { | ||
30 | + | ||
31 | + @Before | ||
32 | + public void reset() { | ||
33 | + DefaultLoad.setPollInterval(10); | ||
34 | + } | ||
35 | + | ||
36 | + /** | ||
37 | + * Tests the default constructor. | ||
38 | + */ | ||
39 | + @Test | ||
40 | + public void testDefaultConstructor() { | ||
41 | + DefaultLoad load = new DefaultLoad(); | ||
42 | + assertThat(load.isValid(), is(false)); | ||
43 | + assertThat(load.latest(), is(-1L)); | ||
44 | + assertThat(load.rate(), is(0L)); | ||
45 | + assertThat(load.time(), is(not(0))); | ||
46 | + } | ||
47 | + | ||
48 | + /** | ||
49 | + * Tests the current-previous constructor. | ||
50 | + */ | ||
51 | + @Test | ||
52 | + public void testCurrentPreviousConstructor() { | ||
53 | + DefaultLoad load = new DefaultLoad(20, 10); | ||
54 | + assertThat(load.isValid(), is(true)); | ||
55 | + assertThat(load.latest(), is(20L)); | ||
56 | + assertThat(load.rate(), is(1L)); | ||
57 | + assertThat(load.time(), is(not(0))); | ||
58 | + } | ||
59 | + | ||
60 | + /** | ||
61 | + * Tests the current-previous-interval constructor. | ||
62 | + */ | ||
63 | + @Test | ||
64 | + public void testCurrentPreviousIntervalConstructor() { | ||
65 | + DefaultLoad load = new DefaultLoad(20, 10, 1); | ||
66 | + assertThat(load.isValid(), is(true)); | ||
67 | + assertThat(load.latest(), is(20L)); | ||
68 | + assertThat(load.rate(), is(10L)); | ||
69 | + assertThat(load.time(), is(not(0))); | ||
70 | + } | ||
71 | + | ||
72 | + /** | ||
73 | + * Tests the toString operation. | ||
74 | + */ | ||
75 | + @Test | ||
76 | + public void testToString() { | ||
77 | + DefaultLoad load = new DefaultLoad(20, 10); | ||
78 | + | ||
79 | + String s = load.toString(); | ||
80 | + assertThat(s, containsString("Load{rate=1, latest=20}")); | ||
81 | + } | ||
82 | + | ||
83 | + /** | ||
84 | + * Tests setting the poll interval. | ||
85 | + */ | ||
86 | + @Test | ||
87 | + public void testSettingPollInterval() { | ||
88 | + DefaultLoad.setPollInterval(1); | ||
89 | + DefaultLoad load = new DefaultLoad(40, 10); | ||
90 | + assertThat(load.rate(), is(30L)); | ||
91 | + } | ||
92 | +} |
-
Please register or login to post a comment