Skip to content

Commit

Permalink
Sonar cleanup (2024-07-08) (#518)
Browse files Browse the repository at this point in the history
Fix five "new" issues that Sonar just flagged.

* Add comment to empty methods in test classes (MyDynamicPortsApp,
MyStartupLockApp)
* Remove no-args constructor from TestApp in ConfigResourceTest
* Rename non-static fields in nested test classes in StartupLockerTest
so they are idiomatic: camelCase, not UPPER_SNAKE_CASE.
  • Loading branch information
sleberknight authored Jul 8, 2024
1 parent 08e775e commit e2ffb99
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,6 @@ LocalPortChecker getLocalPortChecker() {

@Override
public void run(MyDynamicPortsConfig configuration, Environment environment) {
// intentionally empty
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -67,5 +67,6 @@ StartupLocker buildStartupLocker() {

@Override
public void run(MyStartupLockConfig configuration, Environment environment) {
// intentionally empty
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,6 @@ interface RefreshErrorLogConsumer {

public static class TestApp extends Application<TestConfig> {

public TestApp() {
}

@Override
public void run(TestConfig config, Environment environment) {
environment.jersey().register(new ConfigResource(config, List.of(".*Password")));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ void shouldDefaultCuratorLockHelper() {
class AcquireStartupLock {

// NOTE: This is not static because there isn't a way to reset the lifecycle listeners for each test
final DropwizardClientExtension CLIENT_EXTENSION = new DropwizardClientExtension();
final DropwizardClientExtension clientExtension = new DropwizardClientExtension();

private StartupLocker.StartupLockerBuilder startupLockerBuilder;

Expand Down Expand Up @@ -147,7 +147,7 @@ void shouldAttemptAndSucceedInAcquiringLock() {
var locker = startupLockerBuilder.build();
var curatorConfig = CuratorConfig.copyOfWithZkConnectString(new CuratorConfig(), ZK_TEST_SERVER.getConnectString());
var lockInfo = locker.acquireStartupLock(LOCK_PATH, Duration.milliseconds(100), DYNAMIC,
curatorConfig, CLIENT_EXTENSION.getEnvironment());
curatorConfig, clientExtension.getEnvironment());

assertThat(lockInfo.getLockState()).isEqualTo(StartupLockInfo.LockState.ACQUIRED);
assertThat(lockInfo.getInfoMessage()).isEqualTo("Lock acquired");
Expand All @@ -156,7 +156,7 @@ void shouldAttemptAndSucceedInAcquiringLock() {
assertThat(lockInfo.getException()).isNull();
assertThat(lockInfo.getClient()).isNotNull();

var listeners = DropwizardAppTests.lifeCycleListenersOf(CLIENT_EXTENSION.getEnvironment().lifecycle());
var listeners = DropwizardAppTests.lifeCycleListenersOf(clientExtension.getEnvironment().lifecycle());
assertThat(listeners).hasAtLeastOneElementOfType(StartupWithLockJettyLifeCycleListener.class);
}
}
Expand All @@ -165,7 +165,7 @@ void shouldAttemptAndSucceedInAcquiringLock() {
class AddFallbackJettyStartupLifeCycleListener {

// NOTE: This is not static because there isn't a way to reset the lifecycle listeners for each test
final DropwizardClientExtension CLIENT_EXTENSION = new DropwizardClientExtension();
final DropwizardClientExtension clientExtension = new DropwizardClientExtension();

@Test
void shouldNotAddListener_WhenLockInfoIsAcquired() {
Expand All @@ -181,9 +181,9 @@ void shouldNotAddListener_WhenLockInfoIsAcquired() {
.infoMessage("Lock acquired")
.build();

locker.addFallbackJettyStartupLifeCycleListener(lockInfo, CLIENT_EXTENSION.getEnvironment());
locker.addFallbackJettyStartupLifeCycleListener(lockInfo, clientExtension.getEnvironment());

var listeners = DropwizardAppTests.lifeCycleListenersOf(CLIENT_EXTENSION.getEnvironment().lifecycle());
var listeners = DropwizardAppTests.lifeCycleListenersOf(clientExtension.getEnvironment().lifecycle());
assertThat(listeners).doesNotHaveAnyElementsOfTypes(StartupJettyLifeCycleListener.class);
}

Expand All @@ -198,9 +198,9 @@ void shouldAddListener_WhenLockInfoNotAcquired(String state) {
.exception(new RuntimeException("Oops"))
.build();

locker.addFallbackJettyStartupLifeCycleListener(info, CLIENT_EXTENSION.getEnvironment());
locker.addFallbackJettyStartupLifeCycleListener(info, clientExtension.getEnvironment());

var listeners = DropwizardAppTests.lifeCycleListenersOf(CLIENT_EXTENSION.getEnvironment().lifecycle());
var listeners = DropwizardAppTests.lifeCycleListenersOf(clientExtension.getEnvironment().lifecycle());
assertThat(listeners).hasAtLeastOneElementOfType(StartupJettyLifeCycleListener.class);
}
}
Expand Down

0 comments on commit e2ffb99

Please sign in to comment.