diff --git a/src/test/java/org/kohsuke/github/extras/okhttp3/OkHttpConnectorTest.java b/src/test/java/org/kohsuke/github/extras/okhttp3/OkHttpConnectorTest.java index 1f6b3cafa0..792c199442 100644 --- a/src/test/java/org/kohsuke/github/extras/okhttp3/OkHttpConnectorTest.java +++ b/src/test/java/org/kohsuke/github/extras/okhttp3/OkHttpConnectorTest.java @@ -5,6 +5,7 @@ import okhttp3.Cache; import okhttp3.OkHttpClient; import org.apache.commons.io.FileUtils; +import org.junit.After; import org.junit.Before; import org.junit.Test; import org.kohsuke.github.AbstractGitHubWireMockTest; @@ -67,6 +68,7 @@ public OkHttpConnectorTest() { private static int maxAgeNoneHitCount = 11; private GHRateLimit rateLimitBefore; + private Cache cache = null; @Override protected WireMockConfiguration getWireMockOptions() { @@ -88,6 +90,13 @@ public void setupRepo() throws Exception { } } + @After + public void deleteCache() throws IOException { + if (cache != null) { + cache.delete(); + } + } + @Test public void DefaultConnector() throws Exception { @@ -120,7 +129,6 @@ public void OkHttpConnector_NoCache() throws Exception { checkRequestAndLimit(okhttpNetworkRequestCount, okhttpRateLimitUsed); - Cache cache = client.cache(); assertThat("Cache", cache, is(nullValue())); } @@ -147,8 +155,6 @@ public void OkHttpConnector_Cache_MaxAgeNone() throws Exception { checkRequestAndLimit(maxAgeNoneNetworkRequestCount, maxAgeNoneRateLimitUsed); - Cache cache = client.cache(); - // NOTE: this is actually bad. // This elevated hit count is the stale requests returning bad data took longer to detect a change. assertThat("getHitCount", cache.hitCount(), is(maxAgeNoneHitCount)); @@ -176,7 +182,6 @@ public void OkHttpConnector_Cache_MaxAge_Three() throws Exception { checkRequestAndLimit(maxAgeThreeNetworkRequestCount, maxAgeThreeRateLimitUsed); - Cache cache = client.cache(); assertThat("getHitCount", cache.hitCount(), is(maxAgeThreeHitCount)); } @@ -202,7 +207,6 @@ public void OkHttpConnector_Cache_MaxAgeDefault_Zero() throws Exception { checkRequestAndLimit(maxAgeZeroNetworkRequestCount, maxAgeZeroRateLimitUsed); - Cache cache = client.cache(); assertThat("getHitCount", cache.hitCount(), is(maxAgeZeroHitCount)); } @@ -228,7 +232,7 @@ private OkHttpClient createClient(boolean useCache) throws IOException { File cacheDir = new File("target/cache/" + baseFilesClassPath + "/" + mockGitHub.getMethodName()); cacheDir.mkdirs(); FileUtils.cleanDirectory(cacheDir); - Cache cache = new Cache(cacheDir, 100 * 1024L * 1024L); + cache = new Cache(cacheDir, 100 * 1024L * 1024L); builder.cache(cache); }