blob: 0acdcaa140fb91b85b24bbb0a6d0dd28bfc7148d [file] [log] [blame]
Jian Lic565ebf2017-02-04 14:49:52 +09001/*
2 * Copyright 2017-present 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 */
16package org.onosproject.mapping;
17
18import com.google.common.testing.EqualsTester;
19import org.junit.Test;
20
21import static org.hamcrest.MatcherAssert.assertThat;
22import static org.hamcrest.Matchers.is;
23import static org.hamcrest.Matchers.notNullValue;
24import static org.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutable;
25
26/**
27 * Unit tests for mapping id class.
28 */
29public 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}