diff --git a/cache/src/test/java/net/runelite/cache/NpcDumperTest.java b/cache/src/test/java/net/runelite/cache/NpcDumperTest.java index 437630103d..2803bee0d8 100644 --- a/cache/src/test/java/net/runelite/cache/NpcDumperTest.java +++ b/cache/src/test/java/net/runelite/cache/NpcDumperTest.java @@ -46,17 +46,19 @@ public class NpcDumperTest File dumpDir = folder.newFolder(), javaDir = folder.newFolder(); - Store store = new Store(StoreLocation.LOCATION); - store.load(); + try (Store store = new Store(StoreLocation.LOCATION)) + { + store.load(); - NpcDumper dumper = new NpcDumper( - store, - dumpDir, - javaDir - ); - dumper.load(); - dumper.dump(); - dumper.java(); + NpcDumper dumper = new NpcDumper( + store, + dumpDir, + javaDir + ); + dumper.load(); + dumper.dump(); + dumper.java(); + } logger.info("Dumped to {}, java {}", dumpDir, javaDir); } diff --git a/cache/src/test/java/net/runelite/cache/ObjectDumperTest.java b/cache/src/test/java/net/runelite/cache/ObjectDumperTest.java index 7bc632bac4..b173d53dee 100644 --- a/cache/src/test/java/net/runelite/cache/ObjectDumperTest.java +++ b/cache/src/test/java/net/runelite/cache/ObjectDumperTest.java @@ -46,17 +46,19 @@ public class ObjectDumperTest File dumpDir = folder.newFolder(), javaDir = folder.newFolder(); - Store store = new Store(StoreLocation.LOCATION); - store.load(); + try (Store store = new Store(StoreLocation.LOCATION)) + { + store.load(); - ObjectDumper dumper = new ObjectDumper( - store, - dumpDir, - javaDir - ); - dumper.load(); - dumper.dump(); - dumper.java(); + ObjectDumper dumper = new ObjectDumper( + store, + dumpDir, + javaDir + ); + dumper.load(); + dumper.dump(); + dumper.java(); + } logger.info("Dumped to {}, java {}", dumpDir, javaDir); } diff --git a/cache/src/test/java/net/runelite/cache/downloader/CacheClientTest.java b/cache/src/test/java/net/runelite/cache/downloader/CacheClientTest.java index 699041367d..2fbb6ccada 100644 --- a/cache/src/test/java/net/runelite/cache/downloader/CacheClientTest.java +++ b/cache/src/test/java/net/runelite/cache/downloader/CacheClientTest.java @@ -49,45 +49,49 @@ public class CacheClientTest @Ignore public void test() throws Exception { - Store store = new Store(new File("d:/temp")); - store.load(); + try (Store store = new Store(new File("d:/temp"))) + { + store.load(); + + CacheClient c = new CacheClient(store); + c.connect(); + CompletableFuture handshake = c.handshake(); - CacheClient c = new CacheClient(store); - c.connect(); - CompletableFuture handshake = c.handshake(); + Integer result = handshake.get(); + logger.info("Handshake result: {}", result); - Integer result = handshake.get(); - logger.info("Handshake result: {}", result); + Assert.assertEquals(0, (int) result); + + c.download(); - Assert.assertEquals(0, (int) result); - - c.download(); - - c.close(); - - store.save(); + c.close(); + + store.save(); + } } @Test @Ignore public void testTree() throws Exception { - Store store = new Store(new File("C:\\rs\\temp")); - store.loadTree(new File("C:\\rs\\runescape-data\\cache")); + try (Store store = new Store(new File("C:\\rs\\temp"))) + { + store.loadTree(new File("C:\\rs\\runescape-data\\cache")); + + CacheClient c = new CacheClient(store); + c.connect(); + CompletableFuture handshake = c.handshake(); - CacheClient c = new CacheClient(store); - c.connect(); - CompletableFuture handshake = c.handshake(); + Integer result = handshake.get(); + logger.info("Handshake result: {}", result); - Integer result = handshake.get(); - logger.info("Handshake result: {}", result); + Assert.assertEquals(0, (int) result); + + c.download(); - Assert.assertEquals(0, (int) result); - - c.download(); - - c.close(); - - store.saveTree(new File("C:\\rs\\temp\\t")); + c.close(); + + store.saveTree(new File("C:\\rs\\temp\\t")); + } } } diff --git a/cache/src/test/java/net/runelite/cache/fs/IndexFileTest.java b/cache/src/test/java/net/runelite/cache/fs/IndexFileTest.java index 901be7421d..30c5479cb1 100644 --- a/cache/src/test/java/net/runelite/cache/fs/IndexFileTest.java +++ b/cache/src/test/java/net/runelite/cache/fs/IndexFileTest.java @@ -29,7 +29,6 @@ import java.io.File; import java.io.IOException; import net.runelite.cache.StoreLocation; import org.junit.Assert; -import org.junit.BeforeClass; import org.junit.Rule; import org.junit.Test; import org.junit.rules.TemporaryFolder; @@ -40,14 +39,16 @@ public class IndexFileTest public TemporaryFolder folder = StoreLocation.getTemporaryFolder(); @Test - public void test1() throws IOException + public void test() throws IOException { File file = folder.newFile(); - Store store = new Store(folder.getRoot()); - IndexFile index = new IndexFile(store, 5, file); - IndexEntry entry = new IndexEntry(index, 7, 8, 9); - index.write(entry); - IndexEntry entry2 = index.read(7); - Assert.assertEquals(entry, entry2); + try (Store store = new Store(folder.getRoot())) + { + IndexFile index = new IndexFile(store, 5, file); + IndexEntry entry = new IndexEntry(index, 7, 8, 9); + index.write(entry); + IndexEntry entry2 = index.read(7); + Assert.assertEquals(entry, entry2); + } } } diff --git a/cache/src/test/java/net/runelite/cache/fs/StoreLoadTest.java b/cache/src/test/java/net/runelite/cache/fs/StoreLoadTest.java index 37691b7908..0f15db9323 100644 --- a/cache/src/test/java/net/runelite/cache/fs/StoreLoadTest.java +++ b/cache/src/test/java/net/runelite/cache/fs/StoreLoadTest.java @@ -52,24 +52,28 @@ public class StoreLoadTest @Test public void testSave() throws IOException { - Store store = new Store(StoreLocation.LOCATION); - store.load(); - - java.io.File testStoreFile = folder.newFolder(); - for (java.io.File f : StoreLocation.LOCATION.listFiles()) + try (Store store = new Store(StoreLocation.LOCATION)) { - Files.copy(f, new java.io.File(testStoreFile, f.getName())); + store.load(); + + java.io.File testStoreFile = folder.newFolder(); + for (java.io.File f : StoreLocation.LOCATION.listFiles()) + { + Files.copy(f, new java.io.File(testStoreFile, f.getName())); + } + + try (Store testStore = new Store(testStoreFile)) + { + testStore.load(); + + Assert.assertTrue(store.equals(testStore)); + + testStore.save(); + testStore.load(); + + Assert.assertTrue(store.equals(testStore)); + } } - - Store testStore = new Store(testStoreFile); - testStore.load(); - - Assert.assertTrue(store.equals(testStore)); - - testStore.save(); - testStore.load(); - - Assert.assertTrue(store.equals(testStore)); } @Test