blob: bec3cd8ab4482996fc69d07bddb44427f2dbeef3 [file] [log] [blame]
Pavlin Radoslavov53b208a2014-07-28 13:16:11 -07001package net.onrc.onos.core.util;
2
3import org.junit.Test;
4
5import static net.onrc.onos.core.util.ImmutableClassChecker.assertThatClassIsImmutable;
6import static org.hamcrest.Matchers.is;
7import static org.hamcrest.Matchers.not;
8import static org.junit.Assert.assertEquals;
9import static org.junit.Assert.assertThat;
10
11/**
12 * Tests for class {@link OnosInstanceId}.
13 */
14public class OnosInstanceIdTest {
15 /**
16 * Tests the immutability of {@link OnosInstanceId}.
17 */
18 @Test
19 public void testImmutable() {
20 assertThatClassIsImmutable(OnosInstanceId.class);
21 }
22
23 /**
24 * Tests valid class constructor for a string.
25 */
26 @Test
27 public void testConstructorForString() {
28 OnosInstanceId id = new OnosInstanceId("ONOS-ID");
29 assertEquals(id.toString(), "ONOS-ID");
30 }
31
32 /**
33 * Tests invalid class constructor for a null string.
34 */
35 @Test(expected = NullPointerException.class)
36 public void testInvalidConstructorNullString() {
37 OnosInstanceId id = new OnosInstanceId(null);
38 }
39
40 /**
41 * Tests invalid class constructor for an empty string.
42 */
43 @Test(expected = IllegalArgumentException.class)
44 public void testInvalidConstructors() {
45 // Check constructor for invalid ID: empty string
46 OnosInstanceId id = new OnosInstanceId("");
47 }
48
49 /**
50 * Tests equality of {@link OnosInstanceId}.
51 */
52 @Test
53 public void testEquality() {
54 OnosInstanceId id1 = new OnosInstanceId("ONOS-ID");
55 OnosInstanceId id2 = new OnosInstanceId("ONOS-ID");
56
57 assertThat(id1, is(id2));
58 }
59
60 /**
61 * Tests non-equality of {@link OnosInstanceId}.
62 */
63 @Test
64 public void testNonEquality() {
65 OnosInstanceId id1 = new OnosInstanceId("ONOS-ID1");
66 OnosInstanceId id2 = new OnosInstanceId("ONOS-ID2");
67
68 assertThat(id1, is(not(id2)));
69 }
70
71 /**
72 * Tests object string representation.
73 */
74 @Test
75 public void testToString() {
76 OnosInstanceId id = new OnosInstanceId("ONOS-ID");
77 assertEquals("ONOS-ID", id.toString());
78 }
79}