Improve test coverage for DefaultDeviceDescription

Change-Id: If779ceb26f390fbe6e3ec4302a4c9cb054a21fe2
diff --git a/core/api/src/main/java/org/onosproject/net/device/DefaultDeviceDescription.java b/core/api/src/main/java/org/onosproject/net/device/DefaultDeviceDescription.java
index 91ce5af..0a4c705 100644
--- a/core/api/src/main/java/org/onosproject/net/device/DefaultDeviceDescription.java
+++ b/core/api/src/main/java/org/onosproject/net/device/DefaultDeviceDescription.java
@@ -206,7 +206,7 @@
     }
 
     // default constructor for serialization
-    private DefaultDeviceDescription() {
+    DefaultDeviceDescription() {
         this.uri = null;
         this.type = null;
         this.manufacturer = null;
diff --git a/core/api/src/test/java/org/onosproject/net/device/DefaultDeviceDescriptionTest.java b/core/api/src/test/java/org/onosproject/net/device/DefaultDeviceDescriptionTest.java
index 7f06e9c..97e4a59 100644
--- a/core/api/src/test/java/org/onosproject/net/device/DefaultDeviceDescriptionTest.java
+++ b/core/api/src/test/java/org/onosproject/net/device/DefaultDeviceDescriptionTest.java
@@ -18,11 +18,17 @@
 import org.junit.Test;
 import org.onlab.packet.ChassisId;
 import org.onosproject.net.DefaultAnnotations;
+import org.onosproject.net.Device;
 
 import java.net.URI;
 
+import com.google.common.testing.EqualsTester;
+
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertTrue;
+import static org.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutableBaseClass;
+import static org.onosproject.net.Device.Type.ROADM;
+import static org.onosproject.net.Device.Type.ROUTER;
 import static org.onosproject.net.Device.Type.SWITCH;
 
 /**
@@ -30,6 +36,7 @@
  */
 public class DefaultDeviceDescriptionTest {
 
+
     private static final URI DURI = URI.create("of:foo");
     private static final String MFR = "whitebox";
     private static final String HW = "1.1.x";
@@ -39,19 +46,150 @@
     private static final DefaultAnnotations DA =
             DefaultAnnotations.builder().set("Key", "Value").build();
 
+    private static final URI DURI2 = URI.create("of:foo2");
+    private static final String MFR2 = "whitebox2";
+    private static final String HW2 = "1.1.x2";
+    private static final String SW2 = "3.9.12";
+    private static final String SN2 = "43311-123452";
+    private static final ChassisId CID2 = new ChassisId(2);
+    private static final DefaultAnnotations DA2 =
+            DefaultAnnotations.builder().set("2ndKey", "2ndValue").build();
+
+    private void checkValues(DeviceDescription device,
+                             URI uri,
+                             Device.Type type,
+                             String manufacturer,
+                             String hw,
+                             String sw,
+                             String serial,
+                             String containsUri,
+                             long chassisId,
+                             String annotationsString,
+                             boolean defaultAvailable) {
+        assertEquals("incorrect uri", uri, device.deviceUri());
+        assertEquals("incorrect type", type, device.type());
+        assertEquals("incorrect manufacturer", device.manufacturer(), manufacturer);
+        assertEquals("incorrect hw", device.hwVersion(), hw);
+        assertEquals("incorrect sw", device.swVersion(), sw);
+        assertEquals("incorrect serial", device.serialNumber(), serial);
+        assertTrue("incorrect toString", device.toString().contains(containsUri));
+        assertTrue("Incorrect chassis",
+                   device.chassisId() == null ? chassisId == 0 :
+                                                chassisId == device.chassisId().value());
+        assertTrue("incorrect annotations", device.toString().contains(annotationsString));
+        assertEquals("incorrect default available", defaultAvailable, device.isDefaultAvailable());
+    }
+
     @Test
     public void basics() {
         DeviceDescription device =
                 new DefaultDeviceDescription(DURI, SWITCH, MFR, HW, SW, SN, CID, DA);
-        assertEquals("incorrect uri", DURI, device.deviceUri());
-        assertEquals("incorrect type", SWITCH, device.type());
-        assertEquals("incorrect manufacturer", MFR, device.manufacturer());
-        assertEquals("incorrect hw", HW, device.hwVersion());
-        assertEquals("incorrect sw", SW, device.swVersion());
-        assertEquals("incorrect serial", SN, device.serialNumber());
-        assertTrue("incorrect toString", device.toString().contains("uri=of:foo"));
-        assertTrue("Incorrect chassis", device.chassisId().value() == 0);
-        assertTrue("incorrect annotatios", device.toString().contains("Key=Value"));
+        checkValues(device, DURI, SWITCH, MFR, HW, SW, SN, "uri=of:foo",
+                    CID.value(), "Key=Value", true);
+    }
+
+    /**
+     * Tests equals, hashCode, and toString.
+     */
+    @Test
+    public void testEquals() {
+        DeviceDescription device1 =
+                new DefaultDeviceDescription(DURI, SWITCH, MFR, HW, SW, SN, CID, DA);
+        DeviceDescription sameAsDevice1 =
+                new DefaultDeviceDescription(DURI, SWITCH, MFR, HW, SW, SN, CID, DA);
+        DeviceDescription device2 =
+                new DefaultDeviceDescription(DURI2, SWITCH, MFR, HW, SW, SN, CID, DA);
+        DeviceDescription device3 =
+                new DefaultDeviceDescription(DURI, ROUTER, MFR2, HW, SW, SN, CID, DA);
+        DeviceDescription device4 =
+                new DefaultDeviceDescription(DURI, SWITCH, MFR, HW2, SW, SN, CID, DA);
+        DeviceDescription device5 =
+                new DefaultDeviceDescription(DURI, SWITCH, MFR, HW, SW2, SN, CID, DA);
+        DeviceDescription device6 =
+                new DefaultDeviceDescription(DURI, SWITCH, MFR, HW, SW, SN2, CID, DA);
+        DeviceDescription device7 =
+                new DefaultDeviceDescription(DURI, SWITCH, MFR, HW, SW, SN, CID2, DA);
+        DeviceDescription device8 =
+                new DefaultDeviceDescription(DURI, SWITCH, MFR, HW, SW, SN, CID, DA2);
+
+        new EqualsTester()
+                .addEqualityGroup(device1, sameAsDevice1)
+                .addEqualityGroup(device2)
+                .addEqualityGroup(device3)
+                .addEqualityGroup(device4)
+                .addEqualityGroup(device5)
+                .addEqualityGroup(device6)
+                .addEqualityGroup(device7)
+                .addEqualityGroup(device8)
+                .testEquals();
+    }
+
+    /**
+     * Tests base + annotations constructor.
+     */
+    @Test
+    public void testConstructorWithBaseAndAnnotations() {
+        DeviceDescription base =
+                new DefaultDeviceDescription(DURI, SWITCH, MFR, HW, SW, SN, CID, DA);
+        DeviceDescription device = new DefaultDeviceDescription(base, DA2);
+
+        checkValues(device, DURI, SWITCH, MFR, HW, SW, SN, "uri=of:foo",
+                    CID.value(), "2ndKey=2ndValue", true);
+    }
+
+    /**
+     * Tests base + type + annotations constructor.
+     */
+    @Test
+    public void testConstructorWithBaseAndType() {
+        DeviceDescription base =
+                new DefaultDeviceDescription(DURI, ROADM, MFR, HW, SW, SN, CID, DA);
+        DeviceDescription device = new DefaultDeviceDescription(base, ROADM, DA);
+
+        checkValues(device, DURI, ROADM, MFR, HW, SW, SN, "uri=of:foo",
+                    CID.value(), "Key=Value", true);
+    }
+
+    /**
+     * Tests base + annotations + isDefaultAvailable constructor.
+     */
+    @Test
+    public void testConstructorWithBaseAndIsDefault() {
+        DeviceDescription base =
+                new DefaultDeviceDescription(DURI, SWITCH, MFR, HW, SW, SN, CID, DA);
+        DeviceDescription device = new DefaultDeviceDescription(base, false, DA2);
+
+        checkValues(device, DURI, SWITCH, MFR, HW, SW, SN, "uri=of:foo",
+                    CID.value(), "2ndKey=2ndValue", false);
+    }
+
+    /**
+     * Tests empty constructor.
+     */
+    @Test
+    public void testBareConstructor() {
+        DeviceDescription device = new DefaultDeviceDescription();
+
+        checkValues(device, null, null, null, null, null, null, "uri=null",
+                    CID.value(), "", true);
+
+        assertEquals("incorrect uri", null, device.deviceUri());
+        assertEquals("incorrect type", null, device.type());
+        assertEquals("incorrect manufacturer", null, device.manufacturer());
+        assertEquals("incorrect hw", null, device.hwVersion());
+        assertEquals("incorrect sw", null, device.swVersion());
+        assertEquals("incorrect serial", null, device.serialNumber());
+        assertEquals("Incorrect chassis", null, device.chassisId());
+        assertEquals("incorrect annotations", null, device.annotations());
+        assertTrue("incorrect default available", device.isDefaultAvailable());
+    }
+
+    /**
+     * Tests immutability.
+     */
+    @Test
+    public void testImmutable() {
+        assertThatClassIsImmutableBaseClass(DefaultDeviceDescription.class);
     }
 
 }