Committed by
Brian O'Connor
Unit tests for DefaultPortStatistics class
Change-Id: I778bc0a10381a304d35aaf2628c254d8f1c1e5db
Showing
1 changed file
with
95 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.device; | ||
| 17 | + | ||
| 18 | +import org.junit.Test; | ||
| 19 | +import org.onosproject.net.NetTestTools; | ||
| 20 | + | ||
| 21 | +import com.google.common.testing.EqualsTester; | ||
| 22 | + | ||
| 23 | +import static org.hamcrest.MatcherAssert.assertThat; | ||
| 24 | +import static org.hamcrest.Matchers.is; | ||
| 25 | +import static org.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutable; | ||
| 26 | + | ||
| 27 | +/** | ||
| 28 | + * DefaultPortStatistics unit tests. | ||
| 29 | + */ | ||
| 30 | +public class DefaultPortStatisticsTest { | ||
| 31 | + | ||
| 32 | + private final PortStatistics stats1 = DefaultPortStatistics.builder() | ||
| 33 | + .setBytesReceived(1) | ||
| 34 | + .setBytesSent(2) | ||
| 35 | + .setDurationNano(3) | ||
| 36 | + .setDurationSec(4) | ||
| 37 | + .setPacketsReceived(5) | ||
| 38 | + .setPacketsSent(6) | ||
| 39 | + .setPacketsRxDropped(7) | ||
| 40 | + .setPacketsRxErrors(8) | ||
| 41 | + .setPacketsTxDropped(9) | ||
| 42 | + .setPacketsTxErrors(10) | ||
| 43 | + .setPort(80) | ||
| 44 | + .setDeviceId(NetTestTools.did("1")) | ||
| 45 | + .build(); | ||
| 46 | + | ||
| 47 | + private final PortStatistics stats2 = DefaultPortStatistics.builder() | ||
| 48 | + .setBytesReceived(1) | ||
| 49 | + .setBytesSent(2) | ||
| 50 | + .setDurationNano(3) | ||
| 51 | + .setDurationSec(4) | ||
| 52 | + .setPacketsReceived(5) | ||
| 53 | + .setPacketsSent(6) | ||
| 54 | + .setPacketsRxDropped(7) | ||
| 55 | + .setPacketsRxErrors(8) | ||
| 56 | + .setPacketsTxDropped(9) | ||
| 57 | + .setPacketsTxErrors(11) | ||
| 58 | + .setPort(80) | ||
| 59 | + .setDeviceId(NetTestTools.did("1")) | ||
| 60 | + .build(); | ||
| 61 | + | ||
| 62 | + /** | ||
| 63 | + * Checks that the GroupOperation class is immutable. | ||
| 64 | + */ | ||
| 65 | + @Test | ||
| 66 | + public void testImmutability() { | ||
| 67 | + assertThatClassIsImmutable(DefaultPortStatistics.class); | ||
| 68 | + } | ||
| 69 | + | ||
| 70 | + @Test | ||
| 71 | + public void testConstruction() { | ||
| 72 | + assertThat(stats1.bytesReceived(), is(1L)); | ||
| 73 | + assertThat(stats1.bytesSent(), is(2L)); | ||
| 74 | + assertThat(stats1.durationNano(), is(3L)); | ||
| 75 | + assertThat(stats1.durationSec(), is(4L)); | ||
| 76 | + assertThat(stats1.packetsReceived(), is(5L)); | ||
| 77 | + assertThat(stats1.packetsSent(), is(6L)); | ||
| 78 | + assertThat(stats1.packetsRxDropped(), is(7L)); | ||
| 79 | + assertThat(stats1.packetsRxErrors(), is(8L)); | ||
| 80 | + assertThat(stats1.packetsTxDropped(), is(9L)); | ||
| 81 | + assertThat(stats1.packetsTxErrors(), is(10L)); | ||
| 82 | + assertThat(stats1.port(), is(80)); | ||
| 83 | + } | ||
| 84 | + | ||
| 85 | + /** | ||
| 86 | + * Tests the equals, hashCode and toString methods using Guava EqualsTester. | ||
| 87 | + */ | ||
| 88 | + @Test | ||
| 89 | + public void testEquals() { | ||
| 90 | + new EqualsTester() | ||
| 91 | + .addEqualityGroup(stats1, stats1) | ||
| 92 | + .addEqualityGroup(stats2) | ||
| 93 | + .testEquals(); | ||
| 94 | + } | ||
| 95 | +} |
-
Please register or login to post a comment