unit tests

This commit is contained in:
sergiorussia
2019-05-05 18:06:52 +03:00
parent 4973da5e45
commit 7cf4ce0b2f
4 changed files with 76 additions and 33 deletions
@@ -7,23 +7,41 @@ package com.threerings.getdown.cache;
import java.io.File;
import java.io.IOException;
import java.util.Arrays;
import java.util.Collection;
import java.util.concurrent.TimeUnit;
import org.junit.*;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
import static org.junit.Assert.*;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.junit.Assume.assumeTrue;
/**
* Validates that cache garbage is collected and deleted correctly.
*/
@RunWith(Parameterized.class)
public class GarbageCollectorTest
{
@Parameterized.Parameters(name = "{0}")
public static Collection<Object[]> data() {
return Arrays.asList(new Object[][] {
{ ".jar" },
{ ".zip" }
});
}
@Parameterized.Parameter
public String extension;
@Before public void setupFiles () throws IOException
{
_cachedFile = _folder.newFile("abc123.jar");
_lastAccessedFile = _folder.newFile("abc123.jar" + ResourceCache.LAST_ACCESSED_FILE_SUFFIX);
_cachedFile = _folder.newFile("abc123" + extension);
_lastAccessedFile = _folder.newFile("abc123" + extension + ResourceCache.LAST_ACCESSED_FILE_SUFFIX);
}
@Test public void shouldDeleteCacheEntryIfRetentionPeriodIsReached ()
@@ -7,26 +7,44 @@ package com.threerings.getdown.cache;
import java.io.File;
import java.io.IOException;
import java.util.Arrays;
import java.util.Collection;
import java.util.concurrent.TimeUnit;
import org.junit.*;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
import static org.junit.Assert.*;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
/**
* Asserts the correct functionality of the {@link ResourceCache}.
*/
@RunWith(Parameterized.class)
public class ResourceCacheTest
{
@Parameterized.Parameters(name = "{0}")
public static Collection<Object[]> data() {
return Arrays.asList(new Object[][] {
{ ".jar" },
{ ".zip" }
});
}
@Parameterized.Parameter
public String extension;
@Before public void setupCache () throws IOException {
_fileToCache = _folder.newFile("filetocache.jar");
_fileToCache = _folder.newFile("filetocache" + extension);
_cache = new ResourceCache(_folder.newFolder(".cache"));
}
@Test public void shouldCacheFile () throws IOException
{
assertEquals("abc123.jar", cacheFile().getName());
assertEquals("abc123" + extension, cacheFile().getName());
}
private File cacheFile() throws IOException
@@ -36,7 +54,7 @@ public class ResourceCacheTest
@Test public void shouldTrackFileUsage () throws IOException
{
String name = "abc123.jar" + ResourceCache.LAST_ACCESSED_FILE_SUFFIX;
String name = "abc123" + extension + ResourceCache.LAST_ACCESSED_FILE_SUFFIX;
File lastAccessedFile = new File(cacheFile().getParentFile(), name);
assertTrue(lastAccessedFile.exists());
}