Skip to content

Commit 3479e4f

Browse files
committed
Clean up and formatting
1 parent 54f4152 commit 3479e4f

3 files changed

Lines changed: 10 additions & 41 deletions

File tree

src/main/java/org/kohsuke/github/Requester.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -890,10 +890,8 @@ private <T> T parse(Class<T> type, T instance, int timeouts) throws IOException
890890
// If we see a 404 with an ETag we treat it as corrupt and make new request with
891891
// caching headers overridden to force refresh.
892892
// If we tried this once already, don't try again.
893-
if (Objects.equals(uc.getRequestMethod(), "GET")
894-
&& uc.getHeaderField("ETag") != null
895-
&& !Objects.equals(uc.getRequestProperty("Cache-Control"), "no-cache")
896-
&& timeouts > 0) {
893+
if (Objects.equals(uc.getRequestMethod(), "GET") && uc.getHeaderField("ETag") != null
894+
&& !Objects.equals(uc.getRequestProperty("Cache-Control"), "no-cache") && timeouts > 0) {
897895
setupConnection(uc.getURL());
898896
// Setting "Cache-Control" to "no-cache" stops the cache from supplying
899897
// "If-Modified-Since" or "If-None-Match" values.

src/test/java/org/kohsuke/github/extras/GitHubCachingTest.java

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,8 @@
77
import com.squareup.okhttp.OkUrlFactory;
88
import org.apache.commons.io.FileUtils;
99
import org.junit.Before;
10-
import org.junit.Ignore;
1110
import org.junit.Test;
1211
import org.kohsuke.github.AbstractGitHubWireMockTest;
13-
import org.kohsuke.github.GHContent;
14-
import org.kohsuke.github.GHException;
1512
import org.kohsuke.github.GHFileNotFoundException;
1613
import org.kohsuke.github.GHIssueState;
1714
import org.kohsuke.github.GHPullRequest;
@@ -21,9 +18,6 @@
2118

2219
import java.io.File;
2320
import java.io.IOException;
24-
import java.util.List;
25-
26-
import static org.hamcrest.core.Is.is;
2721

2822
/**
2923
* Test showing the behavior of OkHttpConnector cache with GitHub 404 responses.
@@ -58,18 +52,10 @@ public void setupRepo() throws Exception {
5852
}
5953
}
6054

61-
@Test
62-
public void OkHttpConnector_Cache_MaxAgeDefault_Zero_GitHubRef_Error_runnable() throws Exception {
63-
64-
requireProxy("This test method can be run locally for debugging and analyzing.");
65-
OkHttpConnector_Cache_MaxAgeDefault_Zero_GitHubRef_Error();
66-
}
67-
6855
@Test
6956
public void OkHttpConnector_Cache_MaxAgeDefault_Zero_GitHubRef_Error() throws Exception {
7057
// ISSUE #669
71-
// requireProxy("For clarity. Will switch to snapshot shortly.");
72-
// snapshotNotAllowed();
58+
snapshotNotAllowed();
7359

7460
OkHttpClient client = createClient(true);
7561
OkHttpConnector connector = new OkHttpConnector(new OkUrlFactory(client));
@@ -176,8 +162,8 @@ private OkHttpClient createClient(boolean useCache) throws IOException {
176162
OkHttpClient client = new OkHttpClient();
177163

178164
if (useCache) {
179-
File cacheDir = new File("target/cache/" + baseFilesClassPath + "/" + mockGitHub.getMethodName()
180-
+ clientCount++);
165+
File cacheDir = new File(
166+
"target/cache/" + baseFilesClassPath + "/" + mockGitHub.getMethodName() + clientCount++);
181167
cacheDir.mkdirs();
182168
FileUtils.cleanDirectory(cacheDir);
183169
Cache cache = new Cache(cacheDir, 100 * 1024L * 1024L);

src/test/java/org/kohsuke/github/extras/okhttp3/GitHubCachingTest.java

Lines changed: 5 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,8 @@
66
import okhttp3.OkHttpClient;
77
import org.apache.commons.io.FileUtils;
88
import org.junit.Before;
9-
import org.junit.Ignore;
109
import org.junit.Test;
1110
import org.kohsuke.github.AbstractGitHubWireMockTest;
12-
import org.kohsuke.github.GHContent;
13-
import org.kohsuke.github.GHException;
1411
import org.kohsuke.github.GHFileNotFoundException;
1512
import org.kohsuke.github.GHIssueState;
1613
import org.kohsuke.github.GHPullRequest;
@@ -20,9 +17,6 @@
2017

2118
import java.io.File;
2219
import java.io.IOException;
23-
import java.util.List;
24-
25-
import static org.hamcrest.core.Is.is;
2620

2721
/**
2822
* Test showing the behavior of OkHttpConnector cache with GitHub 404 responses.
@@ -40,8 +34,8 @@ public GitHubCachingTest() {
4034
@Override
4135
protected WireMockConfiguration getWireMockOptions() {
4236
return super.getWireMockOptions()
43-
// Use the same data files as the 2.x test
44-
.usingFilesUnderDirectory(baseRecordPath.replace("/okhttp3/", "/"))
37+
// Use the same data files as the 2.x test
38+
.usingFilesUnderDirectory(baseRecordPath.replace("/okhttp3/", "/"))
4539
.extensions(ResponseTemplateTransformer.builder().global(true).maxCacheEntries(0L).build());
4640
}
4741

@@ -59,19 +53,10 @@ public void setupRepo() throws Exception {
5953
}
6054
}
6155

62-
@Test
63-
public void OkHttpConnector_Cache_MaxAgeDefault_Zero_GitHubRef_Error_runnable() throws Exception {
64-
65-
requireProxy("This test method can be run locally for debugging and analyzing.");
66-
OkHttpConnector_Cache_MaxAgeDefault_Zero_GitHubRef_Error();
67-
}
68-
69-
// @Ignore("The wiremock snapshot files attached to this test method show what was sent to and from the server during a run, but they aren't re-runnable - not templated.")
7056
@Test
7157
public void OkHttpConnector_Cache_MaxAgeDefault_Zero_GitHubRef_Error() throws Exception {
7258
// ISSUE #669
73-
// requireProxy("For clarity. Will switch to snapshot shortly.");
74-
// snapshotNotAllowed();
59+
snapshotNotAllowed();
7560

7661
OkHttpClient client = createClient(true);
7762
OkHttpConnector connector = new OkHttpConnector(client);
@@ -178,8 +163,8 @@ private OkHttpClient createClient(boolean useCache) throws IOException {
178163
OkHttpClient.Builder builder = new OkHttpClient().newBuilder();
179164

180165
if (useCache) {
181-
File cacheDir = new File("target/cache/" + baseFilesClassPath + "/" + mockGitHub.getMethodName()
182-
+ clientCount++);
166+
File cacheDir = new File(
167+
"target/cache/" + baseFilesClassPath + "/" + mockGitHub.getMethodName() + clientCount++);
183168
cacheDir.mkdirs();
184169
FileUtils.cleanDirectory(cacheDir);
185170
Cache cache = new Cache(cacheDir, 100 * 1024L * 1024L);

0 commit comments

Comments
 (0)