a32d54b1ad67c7dfc375828558b77d863750c7bb
[yangtools.git] / common / yang-common / src / test / java / org / opendaylight / yangtools / yang / common / EmptyTest.java
1 /*
2  * Copyright (c) 2017 Pantheon Technologies s.r.o. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8 package org.opendaylight.yangtools.yang.common;
9
10 import static org.junit.Assert.assertEquals;
11 import static org.junit.Assert.assertNotNull;
12 import static org.junit.Assert.assertSame;
13
14 import java.io.ByteArrayInputStream;
15 import java.io.ByteArrayOutputStream;
16 import java.io.IOException;
17 import java.io.ObjectInputStream;
18 import java.io.ObjectOutputStream;
19 import org.junit.Test;
20
21 public class EmptyTest {
22
23     @Test
24     public void testInstanceNotNull() {
25         assertNotNull(Empty.value());
26     }
27
28     @Test
29     public void testToString() {
30         assertEquals("empty", Empty.value().toString());
31     }
32
33     @Test
34     public void testSerialization() throws IOException, ClassNotFoundException {
35         final ByteArrayOutputStream bos = new ByteArrayOutputStream();
36         try (ObjectOutputStream oos = new ObjectOutputStream(bos)) {
37             oos.writeObject(Empty.value());
38         }
39
40         final Object read;
41         try (ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(bos.toByteArray()))) {
42             read = ois.readObject();
43         }
44
45         assertSame(Empty.value(), read);
46     }
47 }