Skip to content

Commit a09a479

Browse files
committed
Fix quality flaws
1 parent a0d27a6 commit a09a479

4 files changed

Lines changed: 13 additions & 17 deletions

File tree

lib/src/main/java/org/sonarsource/scanner/lib/internal/http/OkHttpClientFactory.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@
3737
import okhttp3.OkHttpClient;
3838
import org.sonarsource.scanner.lib.ScannerProperties;
3939
import org.sonarsource.scanner.lib.internal.SonarUserHome;
40-
import org.sonarsource.scanner.lib.internal.cache.Logger;
4140
import org.sonarsource.scanner.lib.internal.http.ssl.CertificateStore;
4241
import org.sonarsource.scanner.lib.internal.http.ssl.SslConfig;
4342

@@ -74,7 +73,7 @@ private OkHttpClientFactory() {
7473
COOKIE_JAR = new JavaNetCookieJar(COOKIE_MANAGER);
7574
}
7675

77-
static OkHttpClient create(Logger logger, Map<String, String> bootstrapProperties, SonarUserHome sonarUserHome) {
76+
static OkHttpClient create(Map<String, String> bootstrapProperties, SonarUserHome sonarUserHome) {
7877

7978
String oldSocketTimeout = defaultIfBlank(bootstrapProperties.get(READ_TIMEOUT_SEC_PROPERTY), valueOf(DEFAULT_READ_TIMEOUT_SEC));
8079
String socketTimeout = defaultIfBlank(bootstrapProperties.get(SONAR_SCANNER_SOCKET_TIMEOUT), oldSocketTimeout);

lib/src/main/java/org/sonarsource/scanner/lib/internal/http/ServerConnection.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public class ServerConnection {
5555
this.logger = logger;
5656
this.baseUrlWithoutTrailingSlash = removeTrailingSlash(baseUrl);
5757
this.userAgent = userAgent;
58-
this.httpClient = OkHttpClientFactory.create(logger, bootstrapProperties, sonarUserHome);
58+
this.httpClient = OkHttpClientFactory.create(bootstrapProperties, sonarUserHome);
5959
}
6060

6161
private static String removeTrailingSlash(String url) {

lib/src/test/java/org/sonarsource/scanner/lib/internal/http/OkHttpClientFactoryTest.java

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@
4343
import org.junit.jupiter.api.io.TempDir;
4444
import org.junitpioneer.jupiter.RestoreSystemProperties;
4545
import org.sonarsource.scanner.lib.internal.SonarUserHome;
46-
import org.sonarsource.scanner.lib.internal.cache.Logger;
4746

4847
import static com.github.tomakehurst.wiremock.client.WireMock.aResponse;
4948
import static com.github.tomakehurst.wiremock.client.WireMock.anyUrl;
@@ -60,14 +59,12 @@
6059
import static org.assertj.core.api.Assertions.assertThat;
6160
import static org.assertj.core.api.Assertions.assertThatThrownBy;
6261
import static org.junit.Assert.assertThrows;
63-
import static org.mockito.Mockito.mock;
6462

6563
class OkHttpClientFactoryTest {
6664

6765
private static final String SONAR_WS_TIMEOUT = "sonar.ws.timeout";
6866
private static final String COOKIE = "BIGipServerpool_sonarqube.example.com_8443=123456789.12345.0000";
6967

70-
private final Logger logger = mock(Logger.class);
7168
private final Map<String, String> bootstrapProperties = new HashMap<>();
7269

7370
@TempDir
@@ -84,15 +81,15 @@ void prepareMocks() {
8481
void support_custom_timeouts() {
8582
int readTimeoutSec = 2000;
8683

87-
OkHttpClient underTest = OkHttpClientFactory.create(logger, Map.of(SONAR_WS_TIMEOUT, String.valueOf(readTimeoutSec)), sonarUserHome);
84+
OkHttpClient underTest = OkHttpClientFactory.create(Map.of(SONAR_WS_TIMEOUT, String.valueOf(readTimeoutSec)), sonarUserHome);
8885

8986
assertThat(underTest.readTimeoutMillis()).isEqualTo(readTimeoutSec * 1000);
9087
}
9188

9289
@Test
9390
void support_custom_timeouts_throws_exception_on_non_number() {
9491
var props = Map.of(SONAR_WS_TIMEOUT, "fail");
95-
assertThatThrownBy(() -> OkHttpClientFactory.create(logger, props, sonarUserHome))
92+
assertThatThrownBy(() -> OkHttpClientFactory.create(props, sonarUserHome))
9693
.isInstanceOf(IllegalArgumentException.class)
9794
.hasMessage("sonar.scanner.socketTimeout is not a valid integer: fail");
9895
}
@@ -185,7 +182,7 @@ void it_should_throw_if_invalid_proxy_port() {
185182
bootstrapProperties.put("sonar.scanner.proxyHost", "localhost");
186183
bootstrapProperties.put("sonar.scanner.proxyPort", "not_a_number");
187184

188-
assertThrows(IllegalArgumentException.class, () -> OkHttpClientFactory.create(logger, bootstrapProperties, sonarUserHome));
185+
assertThrows(IllegalArgumentException.class, () -> OkHttpClientFactory.create(bootstrapProperties, sonarUserHome));
189186
}
190187

191188
@Nested
@@ -398,7 +395,7 @@ void it_should_support_jvm_system_properties() throws IOException {
398395
}
399396

400397
private Response call(String url) throws IOException {
401-
return OkHttpClientFactory.create(logger, bootstrapProperties, sonarUserHome).newCall(
398+
return OkHttpClientFactory.create(bootstrapProperties, sonarUserHome).newCall(
402399
new Request.Builder()
403400
.url(url)
404401
.get()

lib/src/test/java/org/sonarsource/scanner/lib/internal/http/ServerConnectionTest.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ class ServerConnectionTest {
5757

5858
@Test
5959
void download_success() throws Exception {
60-
ServerConnection connection = create(false, false);
60+
ServerConnection connection = create();
6161
answer(HELLO_WORLD);
6262

6363
String response = connection.downloadString("/batch/index.txt");
@@ -67,7 +67,7 @@ void download_success() throws Exception {
6767

6868
@Test
6969
void downloadString_fails_on_url_validation() {
70-
ServerConnection connection = create(false, false);
70+
ServerConnection connection = create();
7171
answer(HELLO_WORLD);
7272

7373
assertThatThrownBy(() -> connection.downloadString("should_fail"))
@@ -80,15 +80,15 @@ void test_downloadFile(@TempDir Path tmpFolder) throws Exception {
8080
var toFile = tmpFolder.resolve("index.txt");
8181
answer(HELLO_WORLD);
8282

83-
ServerConnection underTest = create(false, false);
83+
ServerConnection underTest = create();
8484
underTest.downloadFile("/batch/index.txt", toFile);
8585

8686
assertThat(new String(Files.readAllBytes(toFile), StandardCharsets.UTF_8)).isEqualTo(HELLO_WORLD);
8787
}
8888

8989
@Test
9090
void downloadFile_fails_on_url_validation() {
91-
ServerConnection connection = create(false, false);
91+
ServerConnection connection = create();
9292
answer(HELLO_WORLD);
9393

9494
assertThatThrownBy(() -> connection.downloadFile("should_fail", Paths.get("test-path")))
@@ -97,11 +97,11 @@ void downloadFile_fails_on_url_validation() {
9797
}
9898

9999
@Test
100-
void should_throw_ISE_if_response_not_successful(@TempDir Path tmpFolder) throws Exception {
100+
void should_throw_ISE_if_response_not_successful(@TempDir Path tmpFolder) {
101101
var toFile = tmpFolder.resolve("index.txt");
102102
answer(HELLO_WORLD, 400);
103103

104-
ServerConnection underTest = create(false, false);
104+
ServerConnection underTest = create();
105105
assertThatThrownBy(() -> underTest.downloadFile("/batch/index.txt", toFile))
106106
.isInstanceOf(IllegalStateException.class)
107107
.hasMessage(format("Status returned by url [http://%s:%d/batch/index.txt] is not valid: [400]", "localhost", sonarqube.getPort()));
@@ -129,7 +129,7 @@ void should_support_server_url_with_trailing_slash() throws Exception {
129129
assertThat(content).isEqualTo(HELLO_WORLD);
130130
}
131131

132-
private ServerConnection create(boolean enableCache, boolean preferCache) {
132+
private ServerConnection create() {
133133
return new ServerConnection(sonarqube.baseUrl(), "user-agent", null, logger, Map.of(), new SonarUserHome(sonarUserHome));
134134
}
135135

0 commit comments

Comments
 (0)