blob: 93a657953e3d1fe0c8bf355eadc4408fd6f68397 [file] [log] [blame]
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07001/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2014-present Open Networking Laboratory
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07003 *
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'Connorabafb502014-12-02 22:26:20 -080016package org.onosproject.net.intent;
Brian O'Connorf3d06162014-10-02 15:54:12 -070017
18import org.junit.Test;
19
Ray Milkeyc8f481f2014-11-18 15:37:12 -080020import com.google.common.testing.EqualsTester;
21
Brian O'Connorf3d06162014-10-02 15:54:12 -070022import static org.hamcrest.Matchers.is;
23import static org.hamcrest.Matchers.not;
24import static org.junit.Assert.assertEquals;
25import static org.junit.Assert.assertThat;
Pavlin Radoslavovd26f57a2014-10-23 17:19:45 -070026import static org.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutable;
Brian O'Connorf3d06162014-10-02 15:54:12 -070027
28/**
29 * This class tests the immutability, equality, and non-equality of
30 * {@link IntentId}.
31 */
32public class IntentIdTest {
33 /**
34 * Tests the immutability of {@link IntentId}.
35 */
36 @Test
37 public void intentIdFollowsGuidelineForImmutableObject() {
Pavlin Radoslavovd26f57a2014-10-23 17:19:45 -070038 assertThatClassIsImmutable(IntentId.class);
Brian O'Connorf3d06162014-10-02 15:54:12 -070039 }
40
41 /**
42 * Tests equality of {@link IntentId}.
43 */
44 @Test
45 public void testEquality() {
46 IntentId id1 = new IntentId(1L);
47 IntentId id2 = new IntentId(1L);
48
49 assertThat(id1, is(id2));
50 }
51
52 /**
53 * Tests non-equality of {@link IntentId}.
54 */
55 @Test
56 public void testNonEquality() {
57 IntentId id1 = new IntentId(1L);
58 IntentId id2 = new IntentId(2L);
59
60 assertThat(id1, is(not(id2)));
61 }
62
63 @Test
64 public void valueOf() {
Brian O'Connorf3d06162014-10-02 15:54:12 -070065 IntentId id = new IntentId(0xdeadbeefL);
Thomas Vachuskac96058a2014-10-20 23:00:16 -070066 assertEquals("incorrect valueOf", id, IntentId.valueOf(0xdeadbeefL));
Brian O'Connorf3d06162014-10-02 15:54:12 -070067 }
68
Ray Milkeyc8f481f2014-11-18 15:37:12 -080069 /**
70 * Tests the equals(), hashCode() and toString() methods.
71 */
72 @Test
73 public void testEquals() {
74 final IntentId id1 = new IntentId(11111L);
75 final IntentId sameAsId1 = new IntentId(11111L);
76 final IntentId id2 = new IntentId(22222L);
77
78 new EqualsTester()
79 .addEqualityGroup(id1, sameAsId1)
80 .addEqualityGroup(id2)
81 .testEquals();
82 }
83
84 /**
85 * Tests construction of an IntentId object.
86 */
87 @Test
88 public void testConstruction() {
89 final IntentId id1 = new IntentId(987654321L);
90 assertEquals(id1.fingerprint(), 987654321L);
91
92 final IntentId emptyId = new IntentId();
93 assertEquals(emptyId.fingerprint(), 0L);
94 }
Brian O'Connorf3d06162014-10-02 15:54:12 -070095}