Turn RemoteDeviceId into a simple record
[netconf.git] / netconf / sal-netconf-connector / src / test / java / org / opendaylight / netconf / sal / connect / netconf / util / RemoteDeviceIdTest.java
1 /*
2  * Copyright (c) 2016 Cisco Systems, Inc. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8
9 package org.opendaylight.netconf.sal.connect.netconf.util;
10
11 import static org.junit.Assert.assertEquals;
12 import static org.junit.Assert.assertNotEquals;
13
14 import java.net.InetSocketAddress;
15 import org.junit.Test;
16 import org.opendaylight.netconf.sal.connect.util.RemoteDeviceId;
17
18 public class RemoteDeviceIdTest {
19
20     @Test
21     public void testEquals() {
22         final InetSocketAddress address = new InetSocketAddress("127.0.0.1", 8000);
23
24         final RemoteDeviceId remoteDeviceId = new RemoteDeviceId("test", address);
25         final RemoteDeviceId remoteDeviceIdEqualName = new RemoteDeviceId("test", address);
26         final RemoteDeviceId remoteDeviceIdDiffName = new RemoteDeviceId("test-diff", address);
27
28         assertEquals(true, remoteDeviceId.equals(remoteDeviceId));
29         assertEquals(false, remoteDeviceId.equals(this));
30         assertEquals(false, remoteDeviceId.equals(remoteDeviceIdDiffName));
31         assertEquals(true, remoteDeviceId.equals(remoteDeviceIdEqualName));
32     }
33
34     @Test
35     public void testHashCode() {
36         final String name = "name";
37         final InetSocketAddress address = new InetSocketAddress("127.0.0.1", 8000);
38         final RemoteDeviceId remoteDeviceId = new RemoteDeviceId(name, address);
39         final RemoteDeviceId remoteDeviceIdEqualName = new RemoteDeviceId(name, address);
40         final RemoteDeviceId remoteDeviceIdDiffName = new RemoteDeviceId("test-diff", address);
41
42         assertEquals(remoteDeviceIdEqualName.hashCode(), remoteDeviceId.hashCode());
43         assertNotEquals(remoteDeviceIdDiffName.hashCode(), remoteDeviceId.hashCode());
44     }
45 }