package de.tr7zw.nbtapi.plugin.tests;

import java.io.File;
import java.nio.file.Files;

import de.tr7zw.changeme.nbtapi.NBTCompound;
import de.tr7zw.changeme.nbtapi.NBTContainer;
import de.tr7zw.changeme.nbtapi.NBTFile;
import de.tr7zw.changeme.nbtapi.NbtApiException;
import de.tr7zw.nbtapi.plugin.NBTAPI;

public class NBTFileTest implements Test {

	@Override
	public void test() throws Exception {
		NBTAPI.getInstance().getDataFolder().mkdirs();
		NBTFile file = new NBTFile(new File(NBTAPI.getInstance().getDataFolder(), "test.nbt"));
		file.addCompound("testcomp").setString("test1", "ok");
		NBTCompound comp = file.getCompound("testcomp");
		comp.setString("test2", "ok");
		file.setLong("time", System.currentTimeMillis());
		file.setString("test", "test");
		NBTCompound chunks = file.addCompound("chunks");
		NBTCompound chunk = chunks.addCompound("somechunk");
		NBTCompound block = chunk.addCompound("someblock");
		block.setString("type", "wool");
		file.save();
		
		if(!"wool".equals(block.getString("type"))) {
			throw new NbtApiException("SubCompounds did not work!");
		}

		NBTFile fileLoaded = new NBTFile(new File(NBTAPI.getInstance().getDataFolder(), "test.nbt"));
		if (!fileLoaded.getString("test").equals("test")) {
			throw new NbtApiException("Wasn't able to load NBT File with the correct content!");
		}
		Files.deleteIfExists(fileLoaded.getFile().toPath());
		// String
		String str = fileLoaded.asNBTString();
		NBTContainer rebuild = new NBTContainer(str);
		if (!str.equals(rebuild.asNBTString())) {
			throw new NbtApiException("Wasn't able to parse NBT from a String!");
		}
	}

}

@@ -447,25 +447,26 @@
 rs();%0A%09%09
-NBT
 File 
-f
+testF
 ile = ne
@@ -463,36 +463,24 @@
 tFile = new 
-NBTFile(new 
 File(NBTAPI.
@@ -517,24 +517,106 @@
  %22test.nbt%22)
+;%0A%09%09Files.deleteIfExists(testFile.toPath());%0A%09%09NBTFile file = new NBTFile(testFile
 );%0A%09%09file.ad
@@ -1198,66 +1198,16 @@
 ile(
-new File(NBTAPI.getInstance().getDataFolder(), %22test.nbt%22)
+testFile
 );%0A%09

Delete the selftest file first, incase it's corrupted