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 cleanup #491

Merged
merged 1 commit into from
Jun 3, 2024
Merged
Show file tree
Hide file tree
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
@@ -1,6 +1,6 @@
package org.kiwiproject.test.dropwizard.app;

import static java.util.stream.Collectors.toSet;
import static java.util.stream.Collectors.toUnmodifiableSet;

import com.google.common.annotations.VisibleForTesting;
import com.google.common.collect.Sets;
Expand Down Expand Up @@ -101,7 +101,7 @@ public static Set<Object> registeredResourceObjectsOf(JerseyEnvironment jersey)
.filter(InstanceBinding.class::isInstance)
.map(InstanceBinding.class::cast)
.map(InstanceBinding::getService)
.collect(toSet());
.collect(toUnmodifiableSet());

return Sets.union(instances, wrappedResourceObjects);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package org.kiwiproject.test.validation;

import static java.util.stream.Collectors.toSet;
import static java.util.stream.Collectors.toUnmodifiableSet;

import jakarta.validation.ConstraintViolation;
import jakarta.validation.Validator;
Expand Down Expand Up @@ -105,7 +105,7 @@ public <T> Set<ConstraintViolation<T>> assertOnePropertyViolation(T object, Stri
public <T> Set<ConstraintViolation<T>> assertPropertiesEachHaveOneViolation(T object, String... propertyNames) {
return Arrays.stream(propertyNames)
.flatMap(propertyName -> assertOnePropertyViolation(object, propertyName).stream())
.collect(toSet());
.collect(toUnmodifiableSet());
}

/**
Expand Down Expand Up @@ -137,7 +137,7 @@ public <T> Set<ConstraintViolation<T>> assertNoPropertyViolations(T object, Stri
public <T> Set<ConstraintViolation<T>> assertPropertiesEachHaveNoViolations(T object, String... propertyNames) {
return Arrays.stream(propertyNames)
.flatMap(propertyName -> assertNoPropertyViolations(object, propertyName).stream())
.collect(toSet());
.collect(toUnmodifiableSet());
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -455,10 +455,10 @@ void shouldFail_WhenDetailsIsNullOrEmpty(Map<String, Object> details) {
@ValueSource(ints = { 1, 5, 10 })
void shouldFail_WhenDetailsDoesNotHaveExpectedSize(int size) {
var details = createDetailsOfSize(size);
var healthCheck = MockHealthCheck.builder().details(details).build();
var mockHealthCheck = MockHealthCheck.builder().details(details).build();

var expectedSize = size + 1;
assertThatThrownBy(() -> assertThat(healthCheck).hasDetailsWithSize(expectedSize))
assertThatThrownBy(() -> assertThat(mockHealthCheck).hasDetailsWithSize(expectedSize))
.hasMessageContaining("Expected %d details, but found %d", expectedSize, size);
}

Expand Down Expand Up @@ -515,10 +515,10 @@ void shouldFail_WhenDetailsDoesNotContainExpectedKey() {

@Test
void shouldFail_WhenDetailsIsNull() {
var healthCheck = newHealthCheckWithNullDetails();
var theHealthCheck = newHealthCheckWithNullDetails();

assertThatThrownBy(() ->
assertThat(healthCheck)
assertThat(theHealthCheck)
.isHealthy()
.hasDetailsContainingKey("foo"))
.hasMessageContaining("Expected key not found in details");
Expand Down Expand Up @@ -548,10 +548,10 @@ void shouldFail_WhenDetailsDoesNotContainKey() {

@Test
void shouldFail_WhenDetailsIsNull() {
var healthCheck = newHealthCheckWithNullDetails();
var theHealthCheck = newHealthCheckWithNullDetails();

assertThatThrownBy(() ->
assertThat(healthCheck)
assertThat(theHealthCheck)
.isHealthy()
.hasDetailsContainingKey("foo"))
.hasMessageContaining("Expected key not found in details");
Expand Down Expand Up @@ -587,10 +587,10 @@ void shouldFail_WhenDetailsDoesNotContainExpectedKeyAndValue() {

@Test
void shouldFail_WhenDetailsIsNull() {
var healthCheck = newHealthCheckWithNullDetails();
var theHealthCheck = newHealthCheckWithNullDetails();

assertThatThrownBy(() ->
assertThat(healthCheck)
assertThat(theHealthCheck)
.isHealthy()
.hasDetail("foo", "bar"))
.hasMessageContaining("Expected detail not found");
Expand Down Expand Up @@ -712,22 +712,22 @@ class HasEmptyDetails {

@Test
void shouldPass_WhenDetailsAreEmpty() {
var healthCheck = MockHealthCheck.builder().details(Map.of()).build();
var mockHealthCheck = MockHealthCheck.builder().details(Map.of()).build();

assertThatCode(() ->
assertThat(healthCheck)
assertThat(mockHealthCheck)
.isHealthy()
.hasEmptyDetails())
.doesNotThrowAnyException();
}

@Test
void shouldFail_WhenDetailsAreNotEmpty() {
var healthCheck = MockHealthCheck.builder().details(Map.of("answer", 42)).build();
var mockHealthCheck = MockHealthCheck.builder().details(Map.of("answer", 42)).build();


assertThatThrownBy(() ->
assertThat(healthCheck)
assertThat(mockHealthCheck)
.isHealthy()
.hasEmptyDetails())
.hasMessageContaining("Expected empty (non-null) details");
Expand All @@ -739,20 +739,20 @@ class HasNullDetails {

@Test
void shouldPass_WhenDetailsAreNull() {
var healthCheck = newHealthCheckWithNullDetails();
var theHealthCheck = newHealthCheckWithNullDetails();

assertThatCode(() ->
assertThat(healthCheck)
assertThat(theHealthCheck)
.hasNullDetails())
.doesNotThrowAnyException();
}

@Test
void shouldFail_WhenDetailsAreNotNull() {
var healthCheck = MockHealthCheck.builder().detail("answer", 42).build();
var mockHealthCheck = MockHealthCheck.builder().detail("answer", 42).build();

assertThatThrownBy(() ->
assertThat(healthCheck)
assertThat(mockHealthCheck)
.hasNullDetails())
.hasMessageContaining("Expected null details");
}
Expand All @@ -764,32 +764,32 @@ class HasNullOrEmptyDetails {

@Test
void shouldPass_WhenDetailsAreNull() {
var healthCheck = newHealthCheckWithNullDetails();
var theHealthCheck = newHealthCheckWithNullDetails();

assertThatCode(() ->
assertThat(healthCheck)
assertThat(theHealthCheck)
.isHealthy()
.hasNullOrEmptyDetails())
.doesNotThrowAnyException();
}

@Test
void shouldPass_WhenDetailsAreEmpty() {
var healthCheck = newMockHealthCheckWithEmptyDetails();
var mockHealthCheck = newMockHealthCheckWithEmptyDetails();

assertThatCode(() ->
assertThat(healthCheck)
assertThat(mockHealthCheck)
.isHealthy()
.hasNullOrEmptyDetails())
.doesNotThrowAnyException();
}

@Test
void shouldFail_WhenDetailsAreNotNullOrEmpty() {
var healthCheck = MockHealthCheck.builder().detail("answer", 42).build();
var mockHealthCheck = MockHealthCheck.builder().detail("answer", 42).build();

assertThatThrownBy(() ->
assertThat(healthCheck)
assertThat(mockHealthCheck)
.isHealthy()
.hasNullOrEmptyDetails())
.hasMessageContaining("Expected null or empty details");
Expand All @@ -801,19 +801,19 @@ class DoesNotHaveDetailsContainingKey {

@Test
void shouldPass_WhenDetailsAreNull() {
var healthCheck = newHealthCheckWithNullDetails();
var theHealthCheck = newHealthCheckWithNullDetails();
assertThatCode(() ->
assertThat(healthCheck)
assertThat(theHealthCheck)
.isHealthy()
.doesNotHaveDetailsContainingKey("someKey"))
.doesNotThrowAnyException();
}

@Test
void shouldPass_WhenDetailsAreEmpty() {
var healthCheck = newMockHealthCheckWithEmptyDetails();
var mockHealthCheck = newMockHealthCheckWithEmptyDetails();
assertThatCode(() ->
assertThat(healthCheck)
assertThat(mockHealthCheck)
.isHealthy()
.doesNotHaveDetailsContainingKey("someKey"))
.doesNotThrowAnyException();
Expand Down Expand Up @@ -844,19 +844,19 @@ class DoesNotHaveDetailsContainingKeys {

@Test
void shouldPass_WhenDetailsAreNull() {
var healthCheck = newHealthCheckWithNullDetails();
var theHealthCheck = newHealthCheckWithNullDetails();
assertThatCode(() ->
assertThat(healthCheck)
assertThat(theHealthCheck)
.isHealthy()
.doesNotHaveDetailsContainingKeys("someKey", "anotherKey", "yetAnotherKey"))
.doesNotThrowAnyException();
}

@Test
void shouldPass_WhenDetailsAreEmpty() {
var healthCheck = newMockHealthCheckWithEmptyDetails();
var mockHealthCheck = newMockHealthCheckWithEmptyDetails();
assertThatCode(() ->
assertThat(healthCheck)
assertThat(mockHealthCheck)
.isHealthy()
.doesNotHaveDetailsContainingKeys("someKey", "anotherKey", "yetAnotherKey"))
.doesNotThrowAnyException();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package org.kiwiproject.test.dropwizard.app;

import static java.util.stream.Collectors.toList;
import static java.util.stream.Collectors.toSet;
import static java.util.stream.Collectors.toUnmodifiableSet;
import static org.assertj.core.api.Assertions.assertThat;
import static org.kiwiproject.collect.KiwiLists.first;

Expand Down Expand Up @@ -206,7 +205,7 @@ void shouldReturnLifeCycleObjects() {

@Test
void shouldReturnStreamOfLifeCycleObjects() {
var lifeCycles = DropwizardAppTests.lifeCycleStreamOf(APP).collect(toList());
var lifeCycles = DropwizardAppTests.lifeCycleStreamOf(APP).toList();
assertLifeCycleObjects(lifeCycles);
}

Expand All @@ -219,7 +218,7 @@ private void assertLifeCycleObjects(List<LifeCycle> lifeCycles) {
.filter(managed -> NoOpManaged.class.isAssignableFrom(managed.getClass()))
.map(NoOpManaged.class::cast)
.map(NoOpManaged::mischiefManaged)
.collect(toSet());
.collect(toUnmodifiableSet());

assertThat(mischiefManaged).containsOnly(true);
}
Expand All @@ -242,7 +241,7 @@ void shouldReturnLifeCycleListenerObjects(SoftAssertions softly) {
var classNames = listeners.stream()
.map(Object::getClass)
.map(Class::getName)
.collect(toList());
.toList();

softly.assertThat(classNames).contains(DropwizardAppTests.DROPWIZARD_PRIVATE_SERVER_LISTENER_CLASS_NAME);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package org.kiwiproject.test.jaxrs;

import static java.util.stream.Collectors.toList;
import static org.assertj.core.api.Assertions.assertThat;
import static org.kiwiproject.collect.KiwiLists.first;
import static org.kiwiproject.collect.KiwiLists.second;
Expand Down Expand Up @@ -81,7 +80,7 @@ void shouldLogRequestsAndResponses() {
assertThat(records).hasSize(2);
assertThat(records).extracting(LogRecord::getLoggerName).containsOnly("MyLogger");

var messages = records.stream().map(LogRecord::getMessage).collect(toList());
var messages = records.stream().map(LogRecord::getMessage).toList();
assertThat(first(messages)).describedAs(CHECK_CLIENT_LOGGING_FILTER).contains(SENDING_CLIENT_REQUEST);
assertThat(second(messages)).describedAs(CHECK_CLIENT_LOGGING_FILTER).contains(CLIENT_RESPONSE_RECEIVED);

Expand All @@ -91,7 +90,7 @@ void shouldLogRequestsAndResponses() {
.hasSize(4);
var latestMessages = records.stream()
.skip(2)
.map(LogRecord::getMessage).collect(toList());
.map(LogRecord::getMessage).toList();
assertThat(first(latestMessages)).describedAs(CHECK_CLIENT_LOGGING_FILTER).contains(SENDING_CLIENT_REQUEST);
assertThat(second(latestMessages)).describedAs(CHECK_CLIENT_LOGGING_FILTER).contains(CLIENT_RESPONSE_RECEIVED);
}
Expand All @@ -109,8 +108,8 @@ private SimpleTestLogHandler() {
}

@Override
public void publish(final LogRecord record) {
records.add(record);
public void publish(final LogRecord logRecord) {
records.add(logRecord);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package org.kiwiproject.test.junit;

import static java.util.stream.Collectors.toList;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatCode;
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
Expand Down Expand Up @@ -141,7 +140,7 @@ private static List<String> getFirstLineOfEachFailureMessage(MultipleFailuresErr
.map(message -> message.split(lineSeparator))
.map(lines -> lines[0])
.map(String::trim)
.collect(toList());
.toList();
}

private static class Request {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,8 @@ static void afterAll() {
@Order(1)
@Tag("firstTest")
void shouldListCollections() {
var mongoDatabase = client.getDatabase(TEST_PROPERTIES.getDatabaseName());
assertThat(newArrayList(mongoDatabase.listCollectionNames().iterator())).isEmpty();
var theMongoDatabase = client.getDatabase(TEST_PROPERTIES.getDatabaseName());
assertThat(newArrayList(theMongoDatabase.listCollectionNames().iterator())).isEmpty();
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,10 +166,7 @@ void shouldBeTrue_WhenDatabaseName_ContainsTestDatabaseNameWithoutTimestamp(
"yet-another-service_unit_test_localhost_1605410638221"
})
void shouldBeFalse_WhenDatabaseName_DoesNotContainTestDatabaseNameWithoutTimestamp(String databaseName) {
verifyTestPropertiesDatabaseName();

assertThat(MongoDbExtension.isUnitTestDatabaseForThisService(databaseName, testProperties))
.isFalse();
assertNotUnitTestDatabaseForThisService(databaseName);
}

@ParameterizedTest
Expand All @@ -180,17 +177,17 @@ void shouldBeFalse_WhenDatabaseName_DoesNotContainTestDatabaseNameWithoutTimesta
"customer_database"
})
void shouldBeFalse_WhenDatabaseName_IsNotInOurExpectedFormat(String databaseName) {
verifyTestPropertiesDatabaseName();

assertThat(MongoDbExtension.isUnitTestDatabaseForThisService(databaseName, testProperties))
.isFalse();
assertNotUnitTestDatabaseForThisService(databaseName);
}

private void verifyTestPropertiesDatabaseName() {
private void assertNotUnitTestDatabaseForThisService(String databaseName) {
var testPropsDbName = testProperties.getDatabaseNameWithoutTimestamp();
verify(testPropsDbName.equals("test-service_unit_test_localhost"),
"Expected testProperties database name (w/o timestamp) to be: test-service_unit_test_localhost but was: %s",
testPropsDbName);

assertThat(MongoDbExtension.isUnitTestDatabaseForThisService(databaseName, testProperties))
.isFalse();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,16 @@ class AsciiOnlyBlankStringArgumentsProviderTest {
@ParameterizedTest
@ArgumentsSource(AsciiOnlyBlankStringArgumentsProvider.class)
void shouldProvideBlankArguments(String blankString) {
assertThat(blankString).isBlank();

if (nonNull(blankString)) {
assertOnlyAsciiCharactersIn(blankString);
}
assertProvidesBlankArguments(blankString);
}

@ParameterizedTest
@AsciiOnlyBlankStringSource
void shouldProvideBlankArgumentsUsingAnnotation(String blankString) {
assertProvidesBlankArguments(blankString);
}

private void assertProvidesBlankArguments(String blankString) {
assertThat(blankString).isBlank();

if (nonNull(blankString)) {
Expand Down
Loading