Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2014-present Open Networking Foundation |
Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -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 | */ |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 16 | package org.onosproject.net.intent; |
Brian O'Connor | f3d0616 | 2014-10-02 15:54:12 -0700 | [diff] [blame] | 17 | |
| 18 | import org.junit.Test; |
| 19 | |
Ray Milkey | c8f481f | 2014-11-18 15:37:12 -0800 | [diff] [blame] | 20 | import com.google.common.testing.EqualsTester; |
| 21 | |
Brian O'Connor | f3d0616 | 2014-10-02 15:54:12 -0700 | [diff] [blame] | 22 | import static org.hamcrest.Matchers.is; |
| 23 | import static org.hamcrest.Matchers.not; |
| 24 | import static org.junit.Assert.assertEquals; |
| 25 | import static org.junit.Assert.assertThat; |
Pavlin Radoslavov | d26f57a | 2014-10-23 17:19:45 -0700 | [diff] [blame] | 26 | import static org.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutable; |
Brian O'Connor | f3d0616 | 2014-10-02 15:54:12 -0700 | [diff] [blame] | 27 | |
| 28 | /** |
| 29 | * This class tests the immutability, equality, and non-equality of |
| 30 | * {@link IntentId}. |
| 31 | */ |
| 32 | public class IntentIdTest { |
| 33 | /** |
| 34 | * Tests the immutability of {@link IntentId}. |
| 35 | */ |
| 36 | @Test |
| 37 | public void intentIdFollowsGuidelineForImmutableObject() { |
Pavlin Radoslavov | d26f57a | 2014-10-23 17:19:45 -0700 | [diff] [blame] | 38 | assertThatClassIsImmutable(IntentId.class); |
Brian O'Connor | f3d0616 | 2014-10-02 15:54:12 -0700 | [diff] [blame] | 39 | } |
| 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'Connor | f3d0616 | 2014-10-02 15:54:12 -0700 | [diff] [blame] | 65 | IntentId id = new IntentId(0xdeadbeefL); |
Thomas Vachuska | c96058a | 2014-10-20 23:00:16 -0700 | [diff] [blame] | 66 | assertEquals("incorrect valueOf", id, IntentId.valueOf(0xdeadbeefL)); |
Brian O'Connor | f3d0616 | 2014-10-02 15:54:12 -0700 | [diff] [blame] | 67 | } |
| 68 | |
Ray Milkey | c8f481f | 2014-11-18 15:37:12 -0800 | [diff] [blame] | 69 | /** |
| 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'Connor | f3d0616 | 2014-10-02 15:54:12 -0700 | [diff] [blame] | 95 | } |