Jian Li | c565ebf | 2017-02-04 14:49:52 +0900 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2017-present Open Networking Foundation |
Jian Li | c565ebf | 2017-02-04 14:49:52 +0900 | [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.mapping; |
| 17 | |
| 18 | import com.google.common.testing.EqualsTester; |
| 19 | import org.junit.Test; |
| 20 | |
| 21 | import static org.hamcrest.MatcherAssert.assertThat; |
| 22 | import static org.hamcrest.Matchers.is; |
| 23 | import static org.hamcrest.Matchers.notNullValue; |
| 24 | import static org.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutable; |
| 25 | |
| 26 | /** |
| 27 | * Unit tests for mapping id class. |
| 28 | */ |
| 29 | public class MappingIdTest { |
| 30 | |
| 31 | final MappingId mappingId1 = MappingId.valueOf(1); |
| 32 | final MappingId sameAsMappingId1 = MappingId.valueOf(1); |
| 33 | final MappingId mappingId2 = MappingId.valueOf(2); |
| 34 | |
| 35 | /** |
| 36 | * Checks that the MappingId class is immutable. |
| 37 | */ |
| 38 | @Test |
| 39 | public void testImmutability() { |
| 40 | assertThatClassIsImmutable(MappingId.class); |
| 41 | } |
| 42 | |
| 43 | /** |
| 44 | * Checks the operation of equals(), hashCode() and toString() methods. |
| 45 | */ |
| 46 | @Test |
| 47 | public void testEquals() { |
| 48 | new EqualsTester() |
| 49 | .addEqualityGroup(mappingId1, sameAsMappingId1) |
| 50 | .addEqualityGroup(mappingId2) |
| 51 | .testEquals(); |
| 52 | } |
| 53 | |
| 54 | /** |
| 55 | * Checks the construction of a MappingId object. |
| 56 | */ |
| 57 | @Test |
| 58 | public void testConstruction() { |
| 59 | final long mappingIdValue = 8888L; |
| 60 | final MappingId mappingId = MappingId.valueOf(mappingIdValue); |
| 61 | assertThat(mappingId, is(notNullValue())); |
| 62 | assertThat(mappingId.value(), is(mappingIdValue)); |
| 63 | } |
| 64 | } |