Cleanup resources allocated in @BeforeClass
[yangtools.git] / yang / yang-data-codec-gson / src / test / java / org / opendaylight / yangtools / yang / data / codec / gson / Bug5446Test.java
index 4d0600a258543888614274be88aa87bb389e8427..c18324d01882a8a9a7f3697151ee6ad828bb537c 100644 (file)
@@ -21,6 +21,7 @@ import java.io.StringWriter;
 import java.io.Writer;
 import java.net.URI;
 import java.net.URISyntaxException;
+import org.junit.AfterClass;
 import org.junit.BeforeClass;
 import org.junit.Test;
 import org.opendaylight.yangtools.yang.common.QName;
@@ -42,20 +43,21 @@ import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
 
 public class Bug5446Test {
 
-    private static QNameModule fooModuleQName;
-    private static QName rootQName;
-    private static QName ipAddressQName;
+    private static final QNameModule FOO_MODULE = QNameModule.create(URI.create("foo"), Revision.of("2015-11-05"));
+    private static final QName ROOT_QNAME = QName.create(FOO_MODULE, "root");
+    private static final QName IP_ADDRESS_QNAME = QName.create(FOO_MODULE, "ip-address");
     private static SchemaContext schemaContext;
 
     @BeforeClass
     public static void init() {
-        fooModuleQName = QNameModule.create(URI.create("foo"), Revision.of("2015-11-05"));
-        rootQName = QName.create(fooModuleQName, "root");
-        ipAddressQName = QName.create(fooModuleQName, "ip-address");
-
         schemaContext = YangParserTestUtils.parseYangResources(Bug5446Test.class, "/bug5446/yang/foo.yang");
     }
 
+    @AfterClass
+    public static void cleanup() {
+        schemaContext = null;
+    }
+
     @Test
     public void test() throws IOException, JsonIOException, JsonSyntaxException, URISyntaxException {
         final DataContainerChild<? extends PathArgument, ?> rootNode = createRootNode();
@@ -85,8 +87,9 @@ public class Bug5446Test {
     }
 
     private static ContainerNode createRootNode() {
-        LeafNode<byte[]> ipAddress = ImmutableNodes.leafNode(ipAddressQName, BaseEncoding.base64().decode("fwAAAQ=="));
-        return ImmutableContainerNodeBuilder.create().withNodeIdentifier(new NodeIdentifier(rootQName))
+        LeafNode<byte[]> ipAddress = ImmutableNodes.leafNode(IP_ADDRESS_QNAME,
+            BaseEncoding.base64().decode("fwAAAQ=="));
+        return ImmutableContainerNodeBuilder.create().withNodeIdentifier(new NodeIdentifier(ROOT_QNAME))
                 .withChild(ipAddress).build();
     }
 }