ErrorTag should be Serializable
[yangtools.git] / common / yang-common / src / test / java / org / opendaylight / yangtools / yang / common / ErrorTagTest.java
diff --git a/common/yang-common/src/test/java/org/opendaylight/yangtools/yang/common/ErrorTagTest.java b/common/yang-common/src/test/java/org/opendaylight/yangtools/yang/common/ErrorTagTest.java
new file mode 100644 (file)
index 0000000..96dddba
--- /dev/null
@@ -0,0 +1,35 @@
+/*
+ * Copyright (c) 2021 PANTHEON.tech, s.r.o. and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.yangtools.yang.common;
+
+import static org.junit.Assert.assertEquals;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import org.junit.Test;
+
+public class ErrorTagTest {
+    @Test
+    public void testSerialization() throws Exception {
+        final ErrorTag expected = new ErrorTag("test");
+
+        final byte[] bytes;
+        try (ByteArrayOutputStream bos = new ByteArrayOutputStream()) {
+            try (ObjectOutputStream oos = new ObjectOutputStream(bos)) {
+                oos.writeObject(expected);
+            }
+            bytes = bos.toByteArray();
+        }
+
+        try (ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(bytes))) {
+            assertEquals(expected, ois.readObject());
+        }
+    }
+}