Code Review
/
controller.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
review
|
tree
raw
|
inline
| side by side
Separate out RaftEntryMeta
[controller.git]
/
opendaylight
/
md-sal
/
cds-access-api
/
src
/
test
/
java
/
org
/
opendaylight
/
controller
/
cluster
/
access
/
concepts
/
AbstractIdentifierTest.java
diff --git
a/opendaylight/md-sal/cds-access-api/src/test/java/org/opendaylight/controller/cluster/access/concepts/AbstractIdentifierTest.java
b/opendaylight/md-sal/cds-access-api/src/test/java/org/opendaylight/controller/cluster/access/concepts/AbstractIdentifierTest.java
index 080e1e46b4854a74615e1ac8d9a08bd3066cb01c..74cd4cf3ba182d2b3ee3c805dba0b33991589f25 100644
(file)
--- a/
opendaylight/md-sal/cds-access-api/src/test/java/org/opendaylight/controller/cluster/access/concepts/AbstractIdentifierTest.java
+++ b/
opendaylight/md-sal/cds-access-api/src/test/java/org/opendaylight/controller/cluster/access/concepts/AbstractIdentifierTest.java
@@
-26,6
+26,8
@@
public abstract class AbstractIdentifierTest<T extends Identifier> {
abstract T equalObject();
abstract T equalObject();
+ abstract int expectedSize();
+
@Test
public final void testEquals() {
assertTrue(object().equals(object()));
@Test
public final void testEquals() {
assertTrue(object().equals(object()));
@@
-40,22
+42,25
@@
public abstract class AbstractIdentifierTest<T extends Identifier> {
assertEquals(object().hashCode(), equalObject().hashCode());
}
assertEquals(object().hashCode(), equalObject().hashCode());
}
+ @Test
+ public final void testSerialization() throws Exception {
+ assertTrue(object().equals(copy(object())));
+ assertTrue(object().equals(copy(equalObject())));
+ assertFalse(differentObject().equals(copy(object())));
+ }
+
@SuppressWarnings("unchecked")
@SuppressWarnings("unchecked")
- private
static <T> T copy(
T obj) throws IOException, ClassNotFoundException {
+ private
T copy(final
T obj) throws IOException, ClassNotFoundException {
final ByteArrayOutputStream bos = new ByteArrayOutputStream();
try (ObjectOutputStream oos = new ObjectOutputStream(bos)) {
oos.writeObject(obj);
}
final ByteArrayOutputStream bos = new ByteArrayOutputStream();
try (ObjectOutputStream oos = new ObjectOutputStream(bos)) {
oos.writeObject(obj);
}
- try (ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(bos.toByteArray()))) {
+ final byte[] bytes = bos.toByteArray();
+ assertEquals(expectedSize(), bytes.length);
+
+ try (ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(bytes))) {
return (T) ois.readObject();
}
}
return (T) ois.readObject();
}
}
-
- @Test
- public final void testSerialization() throws Exception {
- assertTrue(object().equals(copy(object())));
- assertTrue(object().equals(copy(equalObject())));
- assertFalse(differentObject().equals(copy(object())));
- }
}
}