Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sonar: rename non-static field #333

Merged
merged 1 commit into from
Jul 8, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,21 @@ public Response verifyHeadersWereSent(@Context HttpHeaders httpHeaders) {

private String baseUri;

private final DropwizardClientExtension CLIENT_EXTENSION = new DropwizardClientExtension(new TestResource());
//
// This field cannot be static; making it static results in an java.lang.IllegalArgumentException in the tests
// which call buildManagedJerseyClient. It works the first time it is called, but all tests that call it
// afterwards fail with the message:
//
// "A metric named org.apache.hc.client5.http.io.HttpClientConnectionManager.jersey-client.available-connections already exists"
//
// This is because, if the field is static, the MetricRegistry has already been created. Therefore, we need
// a fresh instance for each test, even though this slows the test down.
//
private final DropwizardClientExtension clientExtension = new DropwizardClientExtension(new TestResource());

@BeforeEach
void setUp() {
baseUri = CLIENT_EXTENSION.baseUri().toString() + "/test";
baseUri = clientExtension.baseUri().toString() + "/test";
}

@Nested
Expand Down Expand Up @@ -114,7 +124,7 @@ void shouldUseGivenJerseyClientConfiguration() {

client = new DropwizardManagedClientBuilder()
.clientName(CLIENT_NAME)
.environment(CLIENT_EXTENSION.getEnvironment())
.environment(clientExtension.getEnvironment())
.jerseyClientConfiguration(config)
.buildManagedJerseyClient();

Expand All @@ -126,7 +136,7 @@ void shouldUseGivenJerseyClientConfiguration() {
void shouldSetupDefaultJerseyClientConfigurationIfNotGiven_IgnoringTLSIfOptedOut() {
client = new DropwizardManagedClientBuilder()
.clientName(CLIENT_NAME)
.environment(CLIENT_EXTENSION.getEnvironment())
.environment(clientExtension.getEnvironment())
.withoutTls()
.buildManagedJerseyClient();

Expand All @@ -137,7 +147,7 @@ void shouldSetupDefaultJerseyClientConfigurationIfNotGiven_IgnoringTLSIfOptedOut
void shouldSetupDefaultJerseyClientConfigurationIfNotGiven_IgnoringTLSIfConfigProviderNotGiven() {
client = new DropwizardManagedClientBuilder()
.clientName(CLIENT_NAME)
.environment(CLIENT_EXTENSION.getEnvironment())
.environment(clientExtension.getEnvironment())
.buildManagedJerseyClient();

assertThat(client).isInstanceOf(Client.class);
Expand All @@ -147,7 +157,7 @@ void shouldSetupDefaultJerseyClientConfigurationIfNotGiven_IgnoringTLSIfConfigPr
void shouldSetupDefaultJerseyClientConfigurationIfNotGiven_IgnoringTLSIfConfigProviderCannotProvide() {
client = new DropwizardManagedClientBuilder()
.clientName(CLIENT_NAME)
.environment(CLIENT_EXTENSION.getEnvironment())
.environment(clientExtension.getEnvironment())
.tlsConfigProvider(TlsConfigProvider.builder().build())
.buildManagedJerseyClient();

Expand All @@ -168,7 +178,7 @@ void shouldSetupDefaultJerseyClientConfigurationWithTls() {

client = new DropwizardManagedClientBuilder()
.clientName(CLIENT_NAME)
.environment(CLIENT_EXTENSION.getEnvironment())
.environment(clientExtension.getEnvironment())
.tlsConfigProvider(tlsConfigProvider)
.buildManagedJerseyClient();

Expand All @@ -181,7 +191,7 @@ void shouldNotAllowNullTlsContextConfiguration() {
.isThrownBy(() ->
new DropwizardManagedClientBuilder()
.clientName(CLIENT_NAME)
.environment(CLIENT_EXTENSION.getEnvironment())
.environment(clientExtension.getEnvironment())
.tlsContextConfiguration(null)
.buildManagedJerseyClient())
.withMessage("tlsConfig must not be null");
Expand All @@ -197,7 +207,7 @@ void shouldSetupDefaultJerseyClientConfigurationWithTlsContextConfiguration() {

client = new DropwizardManagedClientBuilder()
.clientName(CLIENT_NAME)
.environment(CLIENT_EXTENSION.getEnvironment())
.environment(clientExtension.getEnvironment())
.tlsContextConfiguration(tlsConfig)
.buildManagedJerseyClient();

Expand All @@ -208,7 +218,7 @@ void shouldSetupDefaultJerseyClientConfigurationWithTlsContextConfiguration() {
void shouldUseGivenHeadersSupplier() {
client = new DropwizardManagedClientBuilder()
.clientName(CLIENT_NAME)
.environment(CLIENT_EXTENSION.getEnvironment())
.environment(clientExtension.getEnvironment())
.headersSupplier(() ->
Map.of(
"Header-1", "Value-1",
Expand Down Expand Up @@ -246,7 +256,7 @@ void tearDown() {
void shouldThrowIllegalStateExceptionIfRegistryClientNotSet() {
var builder = new DropwizardManagedClientBuilder()
.clientName(CLIENT_NAME)
.environment(CLIENT_EXTENSION.getEnvironment());
.environment(clientExtension.getEnvironment());

assertThatThrownBy(builder::buildManagedRegistryAwareClient)
.isInstanceOf(IllegalStateException.class)
Expand All @@ -257,7 +267,7 @@ void shouldThrowIllegalStateExceptionIfRegistryClientNotSet() {
void shouldBuildRegistryAwareClient() {
client = new DropwizardManagedClientBuilder()
.clientName(CLIENT_NAME)
.environment(CLIENT_EXTENSION.getEnvironment())
.environment(clientExtension.getEnvironment())
.registryClient(mock(RegistryClient.class))
.buildManagedRegistryAwareClient();

Expand All @@ -269,7 +279,7 @@ void shouldBuildRegistryAwareClient() {
void shouldUseGivenHeadersSupplier() {
client = new DropwizardManagedClientBuilder()
.clientName(CLIENT_NAME)
.environment(CLIENT_EXTENSION.getEnvironment())
.environment(clientExtension.getEnvironment())
.registryClient(mock(RegistryClient.class))
.headersSupplier(() -> Map.of(
"Header-A", "Value-A",
Expand Down