/hg/icedtea-web: Fix cache entry tests
omajid at icedtea.classpath.org
omajid at icedtea.classpath.org
Tue May 13 16:21:50 UTC 2014
changeset a784a0f1f821 in /hg/icedtea-web
details: http://icedtea.classpath.org/hg/icedtea-web?cmd=changeset;node=a784a0f1f821
author: Omair Majid <omajid at redhat.com>
date: Tue May 13 12:21:07 2014 -0400
Fix cache entry tests
CacheUtil.getCacheFile is still being called by the CacheEntry
constructor in unit tests. Bypass that.
verifyOriginalContentLengthIsSetCorrectly created a CacheEntry
instance, not a TestCacheEntry instance. Fix that too.
2014-05-13 Omair Majid <omajid at redhat.com>
* netx/net/sourceforge/jnlp/cache/CacheEntry.java
(readCacheEntryInfo): New method.
(CacheEntry): Call readCacheEntryInfo to get properties.
* tests/netx/unit/net/sourceforge/jnlp/cache/CacheEntryTest.java
(readCacheEntryInfo): New method.
(createCacheFile): Rename to ...
(createFile): New method. Adjust all callers.
(verifyOriginalContentLengthIsSetCorrectly): Create instances of
TestCacheEntry, not CacheEntry.
diffstat:
ChangeLog | 12 +++++
netx/net/sourceforge/jnlp/cache/CacheEntry.java | 9 +++-
tests/netx/unit/net/sourceforge/jnlp/cache/CacheEntryTest.java | 23 ++++++---
3 files changed, 36 insertions(+), 8 deletions(-)
diffs (130 lines):
diff -r d150e4453b0b -r a784a0f1f821 ChangeLog
--- a/ChangeLog Mon May 12 12:55:21 2014 -0400
+++ b/ChangeLog Tue May 13 12:21:07 2014 -0400
@@ -1,3 +1,15 @@
+2014-05-13 Omair Majid <omajid at redhat.com>
+
+ * netx/net/sourceforge/jnlp/cache/CacheEntry.java
+ (readCacheEntryInfo): New method.
+ (CacheEntry): Call readCacheEntryInfo to get properties.
+ * tests/netx/unit/net/sourceforge/jnlp/cache/CacheEntryTest.java
+ (readCacheEntryInfo): New method.
+ (createCacheFile): Rename to ...
+ (createFile): New method. Adjust all callers.
+ (verifyOriginalContentLengthIsSetCorrectly): Create instances of
+ TestCacheEntry, not CacheEntry.
+
2014-05-12 Omair Majid <omajid at redhat.com>
* netx/net/sourceforge/jnlp/cache/CacheEntry.java: Add
diff -r d150e4453b0b -r a784a0f1f821 netx/net/sourceforge/jnlp/cache/CacheEntry.java
--- a/netx/net/sourceforge/jnlp/cache/CacheEntry.java Mon May 12 12:55:21 2014 -0400
+++ b/netx/net/sourceforge/jnlp/cache/CacheEntry.java Tue May 13 12:21:07 2014 -0400
@@ -60,10 +60,17 @@
this.location = location;
this.version = version;
+ this.properties = readCacheEntryInfo();
+ }
+
+ /**
+ * Seam for testing
+ */
+ PropertiesFile readCacheEntryInfo() {
File infoFile = CacheUtil.getCacheFile(location, version);
infoFile = new File(infoFile.getPath() + ".info"); // replace with something that can't be clobbered
- properties = new PropertiesFile(infoFile, R("CAutoGen"));
+ return new PropertiesFile(infoFile, R("CAutoGen"));
}
/**
diff -r d150e4453b0b -r a784a0f1f821 tests/netx/unit/net/sourceforge/jnlp/cache/CacheEntryTest.java
--- a/tests/netx/unit/net/sourceforge/jnlp/cache/CacheEntryTest.java Mon May 12 12:55:21 2014 -0400
+++ b/tests/netx/unit/net/sourceforge/jnlp/cache/CacheEntryTest.java Tue May 13 12:21:07 2014 -0400
@@ -48,6 +48,7 @@
import java.nio.file.Files;
import net.sourceforge.jnlp.Version;
+import net.sourceforge.jnlp.util.PropertiesFile;
import org.junit.Before;
import org.junit.Test;
@@ -65,6 +66,14 @@
protected File getCacheFile() {
return cacheFile;
}
+ @Override
+ protected PropertiesFile readCacheEntryInfo() {
+ try {
+ return new PropertiesFile(createFile(""));
+ } catch (IOException e) {
+ throw new AssertionError(e);
+ }
+ }
}
private URL url;
@@ -116,7 +125,7 @@
public void verifyOriginalContentLengthIsSetCorrectly() {
long ORIGINAL_CONTENT_LENGTH = 1000;
- CacheEntry entry = new CacheEntry(url, version);
+ CacheEntry entry = new TestCacheEntry(url, version, null);
entry.setOriginalContentLength(ORIGINAL_CONTENT_LENGTH);
assertEquals(ORIGINAL_CONTENT_LENGTH, entry.getOriginalContentLength());
@@ -133,7 +142,7 @@
@Test
public void verifyNotCachedIfContentLengthsDiffer() throws IOException {
- File cachedFile = createCacheFile("Foo");
+ File cachedFile = createFile("Foo");
CacheEntry entry = new TestCacheEntry(url, version, cachedFile);
entry.setRemoteContentLength(10000);
@@ -144,7 +153,7 @@
@Test
public void verifyCachedIfContentLengthsAreSame() throws IOException {
String contents = "Foo";
- File cachedFile = createCacheFile(contents);
+ File cachedFile = createFile(contents);
CacheEntry entry = new TestCacheEntry(url, version, cachedFile);
entry.setRemoteContentLength(contents.length());
@@ -156,7 +165,7 @@
public void verifyCachedIfOriginalContentLengthsAreSame() throws IOException {
String contents = "FooDECOMPRESSED";
long compressedLength = 5;
- File cachedFile = createCacheFile(contents);
+ File cachedFile = createFile(contents);
CacheEntry entry = new TestCacheEntry(url, version, cachedFile);
entry.setRemoteContentLength(compressedLength);
@@ -169,7 +178,7 @@
public void verifyCurrentWhenCacheEntryHasSameTimeStamp() throws IOException {
long lastModified = 10;
String contents = "Foo";
- File cachedFile = createCacheFile(contents);
+ File cachedFile = createFile(contents);
CacheEntry entry = new TestCacheEntry(url, version, cachedFile);
entry.setRemoteContentLength(contents.length());
@@ -183,7 +192,7 @@
long oldTimeStamp = 10;
long newTimeStamp = 100;
String contents = "Foo";
- File cachedFile = createCacheFile(contents);
+ File cachedFile = createFile(contents);
CacheEntry entry = new TestCacheEntry(url, version, cachedFile);
entry.setRemoteContentLength(contents.length());
@@ -192,7 +201,7 @@
assertFalse(entry.isCurrent(newTimeStamp));
}
- protected File createCacheFile(String contents) throws IOException {
+ private static File createFile(String contents) throws IOException {
File cachedFile = File.createTempFile("CacheEntryTest", null);
Files.write(cachedFile.toPath(), contents.getBytes());
cachedFile.deleteOnExit();
More information about the distro-pkg-dev
mailing list