Skip to content

Commit 3a903a2

Browse files
committed
Add test coverage for OkHttpConnector
1 parent 613e5b0 commit 3a903a2

File tree

2 files changed

+17
-5
lines changed

2 files changed

+17
-5
lines changed

pom.xml

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -153,10 +153,6 @@
153153
</limit>
154154
</limits>
155155
<excludes>
156-
<!-- Code implemented externally -->
157-
<exclude>org.kohsuke.github.extras.okhttp3.ObsoleteUrlFactory.**</exclude>
158-
<exclude>org.kohsuke.github.extras.okhttp3.ObsoleteUrlFactory</exclude>
159-
160156
<!-- Sample only -->
161157
<exclude>org.kohsuke.github.example.*</exclude>
162158

@@ -575,6 +571,17 @@
575571
<plugin>
576572
<artifactId>maven-surefire-plugin</artifactId>
577573
<executions>
574+
<execution>
575+
<id>okhttp-test</id>
576+
<phase>test</phase>
577+
<goals>
578+
<goal>test</goal>
579+
</goals>
580+
<configuration>
581+
<excludesFile>src/test/resources/slow-or-flaky-tests.txt</excludesFile>
582+
<argLine>@{jacoco.surefire.argLine} ${surefire.argLine} -Dtest.github.useOkHttp</argLine>
583+
</configuration>
584+
</execution>
578585
<execution>
579586
<id>slow-or-flaky-test</id>
580587
<phase>test</phase>

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
package org.kohsuke.github;
22

3+
import okhttp3.OkHttpClient;
4+
import org.kohsuke.github.extras.okhttp3.OkHttpConnector;
5+
36
import java.io.IOException;
47
import java.net.HttpURLConnection;
58
import java.net.URL;
@@ -33,7 +36,9 @@ default HttpURLConnection connect(URL url) throws IOException {
3336
/**
3437
* Default implementation that uses {@link URL#openConnection()}.
3538
*/
36-
GitHubConnector DEFAULT = new GitHubConnectorHttpConnectorAdapter(HttpConnector.DEFAULT);
39+
GitHubConnector DEFAULT = (System.getProperty("test.github.useOkHttp", "false") != "false")
40+
? new OkHttpConnector(new OkHttpClient.Builder().build())
41+
: new GitHubConnectorHttpConnectorAdapter(HttpConnector.DEFAULT);
3742

3843
GitHubConnector OFFLINE = new GitHubConnectorHttpConnectorAdapter(HttpConnector.OFFLINE);
3944
}

0 commit comments

Comments
 (0)