Ray Milkey

Improve coverage to cover private serialization constructor

Change-Id: Ifedca248416ea28b9ea2716939a1ad7b3fbabe74
...@@ -15,6 +15,10 @@ ...@@ -15,6 +15,10 @@
15 */ 15 */
16 package org.onosproject.net.device; 16 package org.onosproject.net.device;
17 17
18 +import java.lang.reflect.Constructor;
19 +import java.util.Arrays;
20 +
21 +import org.junit.Assert;
18 import org.junit.Test; 22 import org.junit.Test;
19 import org.onosproject.net.NetTestTools; 23 import org.onosproject.net.NetTestTools;
20 24
...@@ -22,6 +26,7 @@ import com.google.common.testing.EqualsTester; ...@@ -22,6 +26,7 @@ import com.google.common.testing.EqualsTester;
22 26
23 import static org.hamcrest.MatcherAssert.assertThat; 27 import static org.hamcrest.MatcherAssert.assertThat;
24 import static org.hamcrest.Matchers.is; 28 import static org.hamcrest.Matchers.is;
29 +import static org.hamcrest.Matchers.notNullValue;
25 import static org.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutable; 30 import static org.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutable;
26 31
27 /** 32 /**
...@@ -92,4 +97,30 @@ public class DefaultPortStatisticsTest { ...@@ -92,4 +97,30 @@ public class DefaultPortStatisticsTest {
92 .addEqualityGroup(stats2) 97 .addEqualityGroup(stats2)
93 .testEquals(); 98 .testEquals();
94 } 99 }
100 +
101 + /**
102 + * Tests that the empty argument list constructor for serialization
103 + * is present and creates a proper object.
104 + */
105 + @Test
106 + public void testSerializerConstructor() {
107 + try {
108 + Constructor[] constructors = DefaultPortStatistics.class.getDeclaredConstructors();
109 + assertThat(constructors, notNullValue());
110 + Arrays.stream(constructors).filter(ctor ->
111 + ctor.getParameterTypes().length == 0)
112 + .forEach(noParamsCtor -> {
113 + try {
114 + noParamsCtor.setAccessible(true);
115 + DefaultPortStatistics stats =
116 + (DefaultPortStatistics) noParamsCtor.newInstance();
117 + assertThat(stats, notNullValue());
118 + } catch (Exception e) {
119 + Assert.fail("Exception instantiating no parameters constructor");
120 + }
121 + });
122 + } catch (Exception e) {
123 + Assert.fail("Exception looking up constructors");
124 + }
125 + }
95 } 126 }
......