blob: 62419ee5b7b7d27d89203e5e0b976c064a65de46 [file] [log] [blame]
Ray Milkey96495ca2015-07-07 11:02:10 -07001/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2015-present Open Networking Laboratory
Ray Milkey96495ca2015-07-07 11:02:10 -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 */
16package org.onosproject.store.cluster.messaging;
17
18
19import org.junit.Test;
20import org.onlab.packet.IpAddress;
21
22import com.google.common.testing.EqualsTester;
23
24import static org.hamcrest.MatcherAssert.assertThat;
25import static org.hamcrest.Matchers.is;
26import static org.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutable;
27
28/**
29 * Unit tests for the Endpoint class.
30 */
31public class EndpointTest {
32 IpAddress host1 = IpAddress.valueOf("1.2.3.4");
33 IpAddress host2 = IpAddress.valueOf("1.2.3.5");
34
35 private final Endpoint endpoint1 = new Endpoint(host1, 1);
36 private final Endpoint sameAsEndpoint1 = new Endpoint(host1, 1);
37 private final Endpoint endpoint2 = new Endpoint(host2, 1);
38 private final Endpoint endpoint3 = new Endpoint(host1, 2);
39
40 /**
41 * Checks that the MessageSubject class is immutable.
42 */
43 @Test
44 public void testImmutability() {
45 assertThatClassIsImmutable(Endpoint.class);
46 }
47
48 /**
49 * Checks the operation of equals(), hashCode() and toString() methods.
50 */
51 @Test
52 public void testEquals() {
53 new EqualsTester()
54 .addEqualityGroup(endpoint1, sameAsEndpoint1)
55 .addEqualityGroup(endpoint2)
56 .addEqualityGroup(endpoint3)
57 .testEquals();
58 }
59
60 /**
61 * Checks the construction of a MessageSubject object.
62 */
63 @Test
64 public void testConstruction() {
65 assertThat(endpoint2.host(), is(host2));
66 assertThat(endpoint2.port(), is(1));
67 }
68}