Ray Milkey | 506455f | 2014-11-12 13:18:35 -0800 | [diff] [blame] | 1 | /* |
Brian O'Connor | 5ab426f | 2016-04-09 01:19:45 -0700 | [diff] [blame] | 2 | * Copyright 2014-present Open Networking Laboratory |
Ray Milkey | 506455f | 2014-11-12 13:18:35 -0800 | [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 | */ |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 16 | package org.onosproject.net.flow; |
Ray Milkey | 506455f | 2014-11-12 13:18:35 -0800 | [diff] [blame] | 17 | |
| 18 | import org.junit.Test; |
| 19 | |
| 20 | import com.google.common.testing.EqualsTester; |
| 21 | |
| 22 | import static org.hamcrest.MatcherAssert.assertThat; |
| 23 | import static org.hamcrest.Matchers.is; |
| 24 | import static org.hamcrest.Matchers.notNullValue; |
| 25 | import static org.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutable; |
| 26 | |
| 27 | /** |
| 28 | * Unit tests for flow id class. |
| 29 | */ |
| 30 | public class FlowIdTest { |
| 31 | |
| 32 | final FlowId flowId1 = FlowId.valueOf(1); |
| 33 | final FlowId sameAsFlowId1 = FlowId.valueOf(1); |
| 34 | final FlowId flowId2 = FlowId.valueOf(2); |
| 35 | |
| 36 | /** |
Ray Milkey | ff51773 | 2014-12-01 10:40:14 -0800 | [diff] [blame] | 37 | * Checks that the FlowId class is immutable. |
Ray Milkey | 506455f | 2014-11-12 13:18:35 -0800 | [diff] [blame] | 38 | */ |
| 39 | @Test |
| 40 | public void testImmutability() { |
| 41 | assertThatClassIsImmutable(FlowId.class); |
| 42 | } |
| 43 | |
| 44 | /** |
Ray Milkey | ff51773 | 2014-12-01 10:40:14 -0800 | [diff] [blame] | 45 | * Checks the operation of equals(), hashCode() and toString() methods. |
Ray Milkey | 506455f | 2014-11-12 13:18:35 -0800 | [diff] [blame] | 46 | */ |
| 47 | @Test |
| 48 | public void testEquals() { |
| 49 | new EqualsTester() |
| 50 | .addEqualityGroup(flowId1, sameAsFlowId1) |
| 51 | .addEqualityGroup(flowId2) |
| 52 | .testEquals(); |
| 53 | } |
| 54 | |
| 55 | /** |
| 56 | * Checks the construction of a FlowId object. |
| 57 | */ |
| 58 | @Test |
| 59 | public void testConstruction() { |
| 60 | final long flowIdValue = 7777L; |
| 61 | final FlowId flowId = FlowId.valueOf(flowIdValue); |
| 62 | assertThat(flowId, is(notNullValue())); |
| 63 | assertThat(flowId.value(), is(flowIdValue)); |
| 64 | } |
| 65 | } |