Skip to content

Commit

Permalink
Fix some Sonar or/and "IDEA inspect code" issues (partly) (#2686)
Browse files Browse the repository at this point in the history
* Fix some Sonar or/and "IDEA inspect code" issues

---------

Co-authored-by: Kirill Peshin <kirill.peshin@bscmsc.ru>
  • Loading branch information
pks-1981 and Kirill Peshin committed Apr 18, 2024
1 parent 5738804 commit 53384e8
Show file tree
Hide file tree
Showing 10 changed files with 48 additions and 49 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2016-2023 Thomas Akehurst
* Copyright (C) 2016-2024 Thomas Akehurst
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -27,7 +27,7 @@
import java.util.List;
import org.junit.jupiter.api.Test;

public class ConversionsTest {
class ConversionsTest {

@Test
void mapsValidFirstParameterValueAsDate() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2013-2023 Thomas Akehurst
* Copyright (C) 2013-2024 Thomas Akehurst
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -30,22 +30,22 @@
import org.junit.jupiter.api.Test;
import org.mockito.Mockito;

public class SaveMappingsTaskTest {
class SaveMappingsTaskTest {

private Admin mockAdmin = Mockito.mock(Admin.class);
private Request mockRequest = mockRequest();

private SaveMappingsTask saveMappingsTask = new SaveMappingsTask();

@Test
public void delegatesSavingMappingsToAdmin() {
void delegatesSavingMappingsToAdmin() {
saveMappingsTask.execute(mockAdmin, ServeEvent.of(mockRequest), PathParams.empty());

verify(mockAdmin).saveMappings();
}

@Test
public void returnsOkResponse() {
void returnsOkResponse() {
ResponseDefinition response =
saveMappingsTask.execute(mockAdmin, ServeEvent.of(mockRequest), PathParams.empty());

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2013-2023 Thomas Akehurst
* Copyright (C) 2013-2024 Thomas Akehurst
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -23,27 +23,27 @@
import com.github.tomakehurst.wiremock.common.url.QueryParams;
import org.junit.jupiter.api.Test;

public class QueryParamsTest {
class QueryParamsTest {

@Test
public void returnsEmptyStringWhenNoParametersPresent() {
void returnsEmptyStringWhenNoParametersPresent() {
assertThat(QueryParams.EMPTY.toString(), is(""));
}

@Test
public void correctlyRendersASingleQueryParamWithSingleValueAsString() {
void correctlyRendersASingleQueryParamWithSingleValueAsString() {
assertThat(QueryParams.single("param", "123").toString(), is("?param=123"));
}

@Test
public void correctlyRendersASingleQueryParamWithMultipleValuesAsString() {
void correctlyRendersASingleQueryParamWithMultipleValuesAsString() {
assertThat(
QueryParams.single("param", "123", "blah", "456").toString(),
is("?param=123&param=blah&param=456"));
}

@Test
public void correctlyRendersMultipleQueryParamsWithMixedSingleAndMultipleValuesAsString() {
void correctlyRendersMultipleQueryParamsWithMixedSingleAndMultipleValuesAsString() {
QueryParams queryParams = new QueryParams();
queryParams.put("one", singletonList("1"));
queryParams.put("two", asList("2", "three"));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2023 Thomas Akehurst
* Copyright (C) 2023-2024 Thomas Akehurst
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -36,7 +36,7 @@ class HealthCheckTaskTest {
private final HealthCheckTask healthCheckTask = new HealthCheckTask();

@Test
public void healthy() {
void healthy() {
ResponseDefinition response =
healthCheckTask.execute(mockAdmin, ServeEvent.of(mockRequest), PathParams.empty());

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2021 Thomas Akehurst
* Copyright (C) 2021-2024 Thomas Akehurst
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -64,7 +64,7 @@ class JUnit4DetectionTest {
describe(
"exclude WireMockJUnitRuleTest",
clazz ->
!excluded.stream().anyMatch(excl -> clazz.getName().contains(excl.getSimpleName())));
excluded.stream().noneMatch(excl -> clazz.getName().contains(excl.getSimpleName())));

private static final String REASON = "we want to migrate to JUnit Jupiter";

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2015-2021 Thomas Akehurst
* Copyright (C) 2015-2024 Thomas Akehurst
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -20,10 +20,10 @@

import org.junit.jupiter.api.Test;

public class CountMatchingStrategyTest {
class CountMatchingStrategyTest {

@Test
public void shouldMatchLessThanCorrectly() {
void shouldMatchLessThanCorrectly() {
CountMatchingStrategy countStrategy =
new CountMatchingStrategy(CountMatchingStrategy.LESS_THAN, 5);

Expand All @@ -33,7 +33,7 @@ public void shouldMatchLessThanCorrectly() {
}

@Test
public void shouldMatchLessThanOrEqualCorrectly() {
void shouldMatchLessThanOrEqualCorrectly() {
CountMatchingStrategy countStrategy =
new CountMatchingStrategy(CountMatchingStrategy.LESS_THAN_OR_EQUAL, 5);

Expand All @@ -43,7 +43,7 @@ public void shouldMatchLessThanOrEqualCorrectly() {
}

@Test
public void shouldMatchEqualToCorrectly() {
void shouldMatchEqualToCorrectly() {
CountMatchingStrategy countStrategy =
new CountMatchingStrategy(CountMatchingStrategy.EQUAL_TO, 5);

Expand All @@ -53,7 +53,7 @@ public void shouldMatchEqualToCorrectly() {
}

@Test
public void shouldMatchGreaterThanOrEqualCorrectly() {
void shouldMatchGreaterThanOrEqualCorrectly() {
CountMatchingStrategy countStrategy =
new CountMatchingStrategy(CountMatchingStrategy.GREATER_THAN_OR_EQUAL, 5);

Expand All @@ -63,7 +63,7 @@ public void shouldMatchGreaterThanOrEqualCorrectly() {
}

@Test
public void shouldMatchGreaterThanCorrectly() {
void shouldMatchGreaterThanCorrectly() {
CountMatchingStrategy countStrategy =
new CountMatchingStrategy(CountMatchingStrategy.GREATER_THAN, 5);

Expand All @@ -73,35 +73,35 @@ public void shouldMatchGreaterThanCorrectly() {
}

@Test
public void shouldCorrectlyObtainFriendlyNameForLessThanMode() throws Exception {
void shouldCorrectlyObtainFriendlyNameForLessThanMode() {
CountMatchingStrategy countStrategy =
new CountMatchingStrategy(CountMatchingStrategy.LESS_THAN, 5);
assertThat(countStrategy.toString(), is("Less than 5"));
}

@Test
public void shouldCorrectlyObtainFriendlyNameForLessThanOrEqualMode() throws Exception {
void shouldCorrectlyObtainFriendlyNameForLessThanOrEqualMode() {
CountMatchingStrategy countStrategy =
new CountMatchingStrategy(CountMatchingStrategy.LESS_THAN_OR_EQUAL, 5);
assertThat(countStrategy.toString(), is("Less than or exactly 5"));
}

@Test
public void shouldCorrectlyObtainFriendlyNameForEqualMode() throws Exception {
void shouldCorrectlyObtainFriendlyNameForEqualMode() {
CountMatchingStrategy countStrategy =
new CountMatchingStrategy(CountMatchingStrategy.EQUAL_TO, 5);
assertThat(countStrategy.toString(), is("Exactly 5"));
}

@Test
public void shouldCorrectlyObtainFriendlyNameForGreaterThanOrEqualMode() throws Exception {
void shouldCorrectlyObtainFriendlyNameForGreaterThanOrEqualMode() {
CountMatchingStrategy countStrategy =
new CountMatchingStrategy(CountMatchingStrategy.GREATER_THAN_OR_EQUAL, 5);
assertThat(countStrategy.toString(), is("More than or exactly 5"));
}

@Test
public void shouldCorrectlyObtainFriendlyNameForGreaterThanMode() throws Exception {
void shouldCorrectlyObtainFriendlyNameForGreaterThanMode() {
CountMatchingStrategy countStrategy =
new CountMatchingStrategy(CountMatchingStrategy.GREATER_THAN, 5);
assertThat(countStrategy.toString(), is("More than 5"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,18 @@
import org.apache.hc.core5.http.HttpStatus;
import org.junit.jupiter.api.Test;

public class HttpAdminClientTest {
class HttpAdminClientTest {
private static final String ADMIN_TEST_PREFIX = "/admin-test";

@Test
public void returnsOptionsWhenCallingGetOptions() {
void returnsOptionsWhenCallingGetOptions() {
var client = new HttpAdminClient("localhost", 8080);
assertThat(client.getOptions().portNumber()).isEqualTo(8080);
assertThat(client.getOptions().bindAddress()).isEqualTo("localhost");
}

@Test
public void shouldSendEmptyRequestForResetToDefaultMappings() {
void shouldSendEmptyRequestForResetToDefaultMappings() {
var server = new WireMockServer(options().dynamicPort());
server.start();
server.addStubMapping(
Expand All @@ -57,7 +57,7 @@ public void shouldSendEmptyRequestForResetToDefaultMappings() {
}

@Test
public void shouldSendEmptyRequestForResetAll() {
void shouldSendEmptyRequestForResetAll() {
var server = new WireMockServer(options().dynamicPort());
server.start();
server.addStubMapping(
Expand All @@ -71,7 +71,7 @@ public void shouldSendEmptyRequestForResetAll() {
}

@Test
public void shouldNotSendEntityForGetAllScenarios() {
void shouldNotSendEntityForGetAllScenarios() {
var server = new WireMockServer(options().dynamicPort());
server.start();
var expectedResponse = new GetScenariosResult(List.of(Scenario.inStartedState("scn1")));
Expand All @@ -86,7 +86,7 @@ public void shouldNotSendEntityForGetAllScenarios() {
}

@Test
public void reuseConnections() throws InterruptedException, IOException {
void reuseConnections() throws InterruptedException, IOException {
var server = new SingleConnectionServer();
server.start();
var client = new HttpAdminClient("localhost", server.getPort(), ADMIN_TEST_PREFIX);
Expand All @@ -97,8 +97,7 @@ public void reuseConnections() throws InterruptedException, IOException {
}

@Test
public void shouldThrowExceptionWithUrlForStubMappingFromNonWireMockServerPort()
throws IOException {
void shouldThrowExceptionWithUrlForStubMappingFromNonWireMockServerPort() throws IOException {
var nonWireMockServer = HttpServer.create(new InetSocketAddress(0), 0);
nonWireMockServer.start();
var serverPort = nonWireMockServer.getAddress().getPort();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

public class WireMockClientAcceptanceTest {
class WireMockClientAcceptanceTest {

private WireMockServer wireMockServer;
private WireMockTestClient testClient;
Expand All @@ -48,22 +48,22 @@ public void stopServer() {
}

@Test
public void buildsMappingWithUrlOnlyRequestAndStatusOnlyResponse() {
void buildsMappingWithUrlOnlyRequestAndStatusOnlyResponse() {
WireMock wireMock = WireMock.create().port(wireMockServer.port()).build();
wireMock.register(get(urlEqualTo("/my/new/resource")).willReturn(aResponse().withStatus(304)));

assertThat(testClient.get("/my/new/resource").statusCode(), is(304));
}

@Test
public void buildsMappingFromStaticSyntax() {
void buildsMappingFromStaticSyntax() {
givenThat(get(urlEqualTo("/my/new/resource")).willReturn(aResponse().withStatus(304)));

assertThat(testClient.get("/my/new/resource").statusCode(), is(304));
}

@Test
public void buildsMappingWithUrlOnyRequestAndResponseWithJsonBodyWithDiacriticSigns() {
void buildsMappingWithUrlOnyRequestAndResponseWithJsonBodyWithDiacriticSigns() {
WireMock wireMock = WireMock.create().port(wireMockServer.port()).build();
wireMock.register(
get(urlEqualTo("/my/new/resource"))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2018-2023 Thomas Akehurst
* Copyright (C) 2018-2024 Thomas Akehurst
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -22,10 +22,10 @@
import java.security.KeyStore;
import org.junit.jupiter.api.Test;

public class KeyStoreSettingsTest {
class KeyStoreSettingsTest {

@Test
public void loadsTrustStoreFromClasspath() {
void loadsTrustStoreFromClasspath() {
KeyStoreSettings trustStoreSettings =
new KeyStoreSettings(TRUST_STORE_NAME, TRUST_STORE_PASSWORD, "jks");

Expand All @@ -34,7 +34,7 @@ public void loadsTrustStoreFromClasspath() {
}

@Test
public void loadsTrustStoreOfTypeJCEKS() {
void loadsTrustStoreOfTypeJCEKS() {
KeyStoreSettings trustStoreSettings =
new KeyStoreSettings(JCEKS_TRUST_STORE_NAME, TRUST_STORE_PASSWORD, "jceks");

Expand All @@ -43,7 +43,7 @@ public void loadsTrustStoreOfTypeJCEKS() {
}

@Test
public void loadsTrustStoreFromFilesystem() {
void loadsTrustStoreFromFilesystem() {
KeyStoreSettings trustStoreSettings =
new KeyStoreSettings(TRUST_STORE_PATH, TRUST_STORE_PASSWORD, "jks");

Expand All @@ -52,7 +52,7 @@ public void loadsTrustStoreFromFilesystem() {
}

@Test
public void failsWhenTrustStoreNotFound() {
void failsWhenTrustStoreNotFound() {
assertThrows(
IllegalArgumentException.class,
() -> {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2020-2021 Thomas Akehurst
* Copyright (C) 2020-2024 Thomas Akehurst
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -22,10 +22,10 @@
import java.security.KeyStore;
import org.junit.jupiter.api.Test;

public class KeyStoreSourceTest {
class KeyStoreSourceTest {

@Test
public void loadsAPasswordProtectedJksKeyStore() throws Exception {
void loadsAPasswordProtectedJksKeyStore() throws Exception {
KeyStoreSource keyStoreSource =
new ReadOnlyFileOrClasspathKeyStoreSource(
"test-keystore-pwd", "jks", "nondefaultpass".toCharArray());
Expand Down

0 comments on commit 53384e8

Please sign in to comment.