Fix ResourceId equality logic
- was failing exceptionally when compared against other Object
Change-Id: I299d29dee5ba136f64f230e2e8311da298c03bf6
diff --git a/model/pom.xml b/model/pom.xml
index 9929a7d..75edfbb 100644
--- a/model/pom.xml
+++ b/model/pom.xml
@@ -45,5 +45,12 @@
<version>4.12</version>
<scope>test</scope>
</dependency>
+ <dependency>
+ <groupId>com.google.guava</groupId>
+ <artifactId>guava-testlib</artifactId>
+ <version>${guava.version}</version>
+ <scope>test</scope>
+ </dependency>
+
</dependencies>
</project>
diff --git a/model/src/main/java/org/onosproject/yang/model/ResourceId.java b/model/src/main/java/org/onosproject/yang/model/ResourceId.java
index 2ccd09a..4222f55 100644
--- a/model/src/main/java/org/onosproject/yang/model/ResourceId.java
+++ b/model/src/main/java/org/onosproject/yang/model/ResourceId.java
@@ -86,7 +86,10 @@
@Override
public boolean equals(Object obj) {
- if (obj == null) {
+ if (obj == this) {
+ return true;
+ }
+ if (!(obj instanceof ResourceId)) {
return false;
}
ResourceId that = (ResourceId) obj;
diff --git a/model/src/test/java/org/onosproject/yang/model/ResourceIdTest.java b/model/src/test/java/org/onosproject/yang/model/ResourceIdTest.java
index 6a5075d..f9a3474 100644
--- a/model/src/test/java/org/onosproject/yang/model/ResourceIdTest.java
+++ b/model/src/test/java/org/onosproject/yang/model/ResourceIdTest.java
@@ -8,7 +8,9 @@
package org.onosproject.yang.model;
+import org.junit.Before;
import org.junit.Test;
+import com.google.common.testing.EqualsTester;
import java.util.List;
@@ -20,6 +22,27 @@
public class ResourceIdTest {
+ ResourceId ridA;
+ ResourceId ridAcopy;
+
+ @Before
+ public void setUp() throws Exception {
+ ridA = ResourceId.builder()
+ .addBranchPointSchema("/", "")
+ .addBranchPointSchema("devices", "onos")
+ .addBranchPointSchema("device", "onos")
+ .addKeyLeaf("device-id", "onos", "test:A")
+ .build();
+ ridAcopy = ridA.copyBuilder().build();
+ }
+
+ @Test
+ public void random() {
+ new EqualsTester()
+ .addEqualityGroup(ridA, ridAcopy)
+ .testEquals();
+ }
+
@Test
public void resourceIdConstruction() {
String sampleResId = "/card=8/port=5,eth/stats";