Skip to content

Commit

Permalink
Sonar cleanup (#355)
Browse files Browse the repository at this point in the history
* "Stream.toList()" method should be used instead of "collectors"
  when unmodifiable list needed java:S6204
* Parentheses should be removed from a single lambda parameter
  when its type is inferred java:S1611
* Java features should be preferred to Guava java:S4738
  • Loading branch information
sleberknight authored Jun 3, 2024
1 parent 712626f commit edba784
Show file tree
Hide file tree
Showing 9 changed files with 17 additions and 19 deletions.
2 changes: 1 addition & 1 deletion src/itest/java/org/kiwiproject/consul/AclClientITest.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ class AclClientITest {
private static GenericContainer<?> consulContainerAcl;
private static AclClient aclClient;

@SuppressWarnings("resource")
@BeforeAll
static void beforeAll() {
// noinspection resource
consulContainerAcl = new GenericContainer<>(CONSUL_DOCKER_IMAGE_NAME)
.withCommand("agent", "-dev", "-client", "0.0.0.0", "--enable-script-checks=true")
.withExposedPorts(8500)
Expand Down
3 changes: 1 addition & 2 deletions src/itest/java/org/kiwiproject/consul/AgentClientITest.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package org.kiwiproject.consul;

import static java.util.Objects.nonNull;
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.AssertionsForClassTypes.assertThatExceptionOfType;
Expand Down Expand Up @@ -596,7 +595,7 @@ private List<String> getHealthCheckNames(String serviceName) {
.getNodeChecks(node, QueryOptions.BLANK).getResponse()
.stream()
.map(HealthCheck::getName)
.collect(toList());
.toList();
}

private void verifyState(String state, Consul client, String serviceId, String serviceName, String output) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;

@SuppressWarnings("resource")
public abstract class BaseIntegrationTest {

private static final Logger LOG = LoggerFactory.getLogger(BaseIntegrationTest.class);
Expand All @@ -39,7 +40,6 @@ public abstract class BaseIntegrationTest {
// https://github.com/junit-team/junit5/issues/456#issuecomment-416945159

static {
// noinspection resource
consulContainer = new GenericContainer<>(CONSUL_DOCKER_IMAGE_NAME)
.withCommand("agent", "-dev", "-client", "0.0.0.0", "--enable-script-checks=true")
.withExposedPorts(8500);
Expand Down
9 changes: 4 additions & 5 deletions src/itest/java/org/kiwiproject/consul/EventClientITest.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package org.kiwiproject.consul;

import static java.util.Objects.nonNull;
import static java.util.stream.Collectors.toList;
import static org.assertj.core.api.Assertions.assertThat;
import static org.awaitility.Durations.TWO_HUNDRED_MILLISECONDS;
import static org.kiwiproject.consul.Awaiting.awaitAtMost1s;
Expand Down Expand Up @@ -156,11 +155,11 @@ void shouldListEventsAsyncWithNameAndQueryOptionsAndCallback() {
}

private List<String> createRandomEventsGettingIds(int eventCount) {
return createRandomEventsAsStream(eventCount).map(Event::getId).collect(toList());
return createRandomEventsAsStream(eventCount).map(Event::getId).toList();
}

private List<Event> createRandomEvents(int eventCount) {
return createRandomEventsAsStream(eventCount).collect(toList());
return createRandomEventsAsStream(eventCount).toList();
}

private Stream<Event> createRandomEventsAsStream(int eventCount) {
Expand All @@ -169,15 +168,15 @@ private Stream<Event> createRandomEventsAsStream(int eventCount) {
}

List<String> getEventIds(EventResponse eventResponse) {
return eventResponse.getEvents().stream().map(Event::getId).collect(toList());
return eventResponse.getEvents().stream().map(Event::getId).toList();
}

List<String> getEventIds(TestEventResponseCallback callback) {
return getEventIds(getEvents(callback));
}

List<String> getEventIds(Collection<Event> events) {
return events.stream().map(Event::getId).collect(toList());
return events.stream().map(Event::getId).toList();
}

Collection<Event> getEvents(TestEventResponseCallback callback) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package org.kiwiproject.consul;

import static java.util.stream.Collectors.toMap;
import static java.util.stream.Collectors.toUnmodifiableMap;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.entry;
import static org.kiwiproject.consul.TestUtils.randomUUIDString;
Expand Down Expand Up @@ -212,7 +212,7 @@ void shouldGetNestedValues() {

var valuesMap = keyValueClient.getValues(topLevelKey)
.stream()
.collect(toMap(Value::getKey, value -> value.getValueAsString().orElseThrow()));
.collect(toUnmodifiableMap(Value::getKey, value -> value.getValueAsString().orElseThrow()));

assertThat(valuesMap).containsOnly(
entry(key1, value1),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package org.kiwiproject.consul;

import static java.util.stream.Collectors.toList;
import static org.assertj.core.api.Assertions.assertThat;
import static org.kiwiproject.consul.TestUtils.randomUUIDString;

Expand Down Expand Up @@ -135,10 +134,10 @@ void shouldListPreparedQueries() {

assertThat(storedQueries).hasSize(2);

List<String> queryIds = storedQueries.stream().map(StoredQuery::getId).collect(toList());
List<String> queryIds = storedQueries.stream().map(StoredQuery::getId).toList();
assertThat(queryIds).contains(id1, id2);

List<String> queryNames = storedQueries.stream().map(StoredQuery::getName).collect(toList());
List<String> queryNames = storedQueries.stream().map(StoredQuery::getName).toList();
assertThat(queryNames).contains(query1, query2);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,8 @@ static TestCache createCache(CacheConfig config, Supplier<List<Integer>> respons
final CallbackConsumer<Integer> callbackConsumer = (index, callback) ->
callback.onComplete(new ConsulResponse<>(responseSupplier.get(), 0, true, BigInteger.ZERO, null, null));

return new TestCache((i) -> i,
return new TestCache(
i -> i,
callbackConsumer,
config,
clientEventHandler,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

import static org.assertj.core.api.Assertions.assertThat;

import com.google.common.io.BaseEncoding;
import org.apache.commons.lang3.RandomStringUtils;
import org.junit.jupiter.api.Test;
import org.kiwiproject.consul.model.event.Event;
import org.kiwiproject.consul.model.event.ImmutableEvent;

import java.io.IOException;
import java.util.Base64;

class Base64EncodingDeserializerTest {

Expand All @@ -20,7 +20,7 @@ void shouldDeserialize() throws IOException {
.lTime(1L)
.name("name")
.version(1)
.payload(BaseEncoding.base64().encode(value.getBytes()))
.payload(Base64.getEncoder().encodeToString(value.getBytes()))
.build();

String serializedEvent = Jackson.MAPPER.writeValueAsString(event);
Expand Down
4 changes: 2 additions & 2 deletions src/test/java/org/kiwiproject/consul/util/HttpTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ void setUp() {
}

private <T> Function<Call<T>, T> createExtractWrapper() {
return (call) -> http.extract(call);
return call -> http.extract(call);
}

private Function<Call<Void>, Void> createHandleWrapper() {
Expand All @@ -54,7 +54,7 @@ private Function<Call<Void>, Void> createHandleWrapper() {
}

private <T> Function<Call<T>, ConsulResponse<T>> createExtractConsulResponseWrapper() {
return (call) -> http.extractConsulResponse(call);
return call -> http.extractConsulResponse(call);
}

@Test
Expand Down

0 comments on commit edba784

Please sign in to comment.