alshabib | e1248b6 | 2015-08-20 17:21:55 -0700 | [diff] [blame] | 1 | /* |
Brian O'Connor | 5ab426f | 2016-04-09 01:19:45 -0700 | [diff] [blame] | 2 | * Copyright 2015-present Open Networking Laboratory |
alshabib | e1248b6 | 2015-08-20 17:21:55 -0700 | [diff] [blame] | 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.meter; |
| 17 | |
| 18 | import com.google.common.testing.EqualsTester; |
| 19 | import org.junit.Test; |
| 20 | import org.onosproject.core.ApplicationId; |
| 21 | import org.onosproject.net.DeviceId; |
| 22 | |
| 23 | import java.util.Collection; |
| 24 | |
| 25 | import static org.hamcrest.MatcherAssert.assertThat; |
| 26 | import static org.hamcrest.Matchers.is; |
| 27 | import static org.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutableBaseClass; |
| 28 | |
| 29 | /** |
| 30 | * Unit tests for the MeterOperationTest object. |
| 31 | */ |
| 32 | public class MeterOperationTest { |
| 33 | |
| 34 | |
| 35 | |
| 36 | /** |
| 37 | * Checks that the MeterOperation class is immutable. |
| 38 | */ |
| 39 | @Test |
| 40 | public void testImmutability() { |
| 41 | assertThatClassIsImmutableBaseClass(MeterOperation.class); |
| 42 | } |
| 43 | |
| 44 | @Test |
| 45 | public void testEquality() { |
| 46 | final Meter m1 = new TestMeter(); |
| 47 | final Meter m2 = new TestMeter(); |
| 48 | final MeterOperation op1 = new MeterOperation(m1, |
| 49 | MeterOperation.Type.ADD); |
| 50 | final MeterOperation sameAsOp1 = new MeterOperation(m1, |
| 51 | MeterOperation.Type.ADD); |
| 52 | final MeterOperation op2 = new MeterOperation(m2, |
| 53 | MeterOperation.Type.ADD); |
| 54 | |
| 55 | new EqualsTester() |
| 56 | .addEqualityGroup(op1, sameAsOp1) |
| 57 | .addEqualityGroup(op2) |
| 58 | .testEquals(); |
| 59 | } |
| 60 | |
| 61 | @Test |
| 62 | public void testConstruction() { |
| 63 | final Meter m1 = new TestMeter(); |
| 64 | |
| 65 | final MeterOperation op = new MeterOperation(m1, MeterOperation.Type.ADD); |
| 66 | |
| 67 | assertThat(op.meter(), is(m1)); |
| 68 | } |
| 69 | |
| 70 | private static final class TestMeter implements Meter { |
| 71 | |
| 72 | @Override |
| 73 | public DeviceId deviceId() { |
| 74 | return null; |
| 75 | } |
| 76 | |
| 77 | @Override |
| 78 | public MeterId id() { |
| 79 | return null; |
| 80 | } |
| 81 | |
| 82 | @Override |
| 83 | public ApplicationId appId() { |
| 84 | return null; |
| 85 | } |
| 86 | |
| 87 | @Override |
| 88 | public Unit unit() { |
| 89 | return null; |
| 90 | } |
| 91 | |
| 92 | @Override |
| 93 | public boolean isBurst() { |
| 94 | return false; |
| 95 | } |
| 96 | |
| 97 | @Override |
| 98 | public Collection<Band> bands() { |
| 99 | return null; |
| 100 | } |
| 101 | |
| 102 | @Override |
| 103 | public MeterState state() { |
| 104 | return null; |
| 105 | } |
| 106 | |
| 107 | @Override |
| 108 | public long life() { |
| 109 | return 0; |
| 110 | } |
| 111 | |
| 112 | @Override |
| 113 | public long referenceCount() { |
| 114 | return 0; |
| 115 | } |
| 116 | |
| 117 | @Override |
| 118 | public long packetsSeen() { |
| 119 | return 0; |
| 120 | } |
| 121 | |
| 122 | @Override |
| 123 | public long bytesSeen() { |
| 124 | return 0; |
| 125 | } |
| 126 | } |
| 127 | |
| 128 | } |