Skip to content

Commit

Permalink
Fix some SonarCloud issues
Browse files Browse the repository at this point in the history
  • Loading branch information
CRoberto1926 committed Nov 14, 2024
1 parent fa304c1 commit 45fd917
Show file tree
Hide file tree
Showing 19 changed files with 85 additions and 84 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,10 @@ private DockerContainerCreator() {
public static Optional<JdbcDatabaseContainer<?>> createDockerContainer(DB db) {
return switch (db) {
case DB2 -> {
try (Db2Container db2Container = new Db2Container(
DockerImageName.parse("taskana/db2:11.5")
.asCompatibleSubstituteFor("ibmcom/db2"))) {
try (Db2Container db2Container =
new Db2Container(
DockerImageName.parse("taskana/db2:11.5")
.asCompatibleSubstituteFor("ibmcom/db2"))) {

yield Optional.of(
db2Container
Expand All @@ -56,8 +57,8 @@ public static Optional<JdbcDatabaseContainer<?>> createDockerContainer(DB db) {
}
}
case POSTGRES -> {
try (PostgreSQLContainer<?> selfPostgreSQLContainer = new PostgreSQLContainer<>(
DockerImageName.parse("postgres:14.7"))) {
try (PostgreSQLContainer<?> selfPostgreSQLContainer =
new PostgreSQLContainer<>(DockerImageName.parse("postgres:14.7"))) {

yield Optional.of(
selfPostgreSQLContainer
Expand All @@ -67,12 +68,15 @@ public static Optional<JdbcDatabaseContainer<?>> createDockerContainer(DB db) {
.withCommand(
"/bin/sh",
"-c",
"localedef -i de_DE -c -f UTF-8 -A /usr/share/locale/locale.alias de_DE.UTF-8 "
+ "&& export LANG=de_DE.UTF-8 "
+ "&& /usr/local/bin/docker-entrypoint.sh postgres -c fsync=off")
"""
localedef -i de_DE -c -f UTF-8 -A \
/usr/share/locale/locale.alias de_DE.UTF-8 \
&& export LANG=de_DE.UTF-8 \
&& /usr/local/bin/docker-entrypoint.sh postgres -c fsync=off""")
.waitingFor(
new LogMessageWaitStrategy()
.withRegEx(".*Datenbanksystem ist bereit, um Verbindungen anzunehmen.*\\s")
.withRegEx(
".*Datenbanksystem ist bereit, um Verbindungen anzunehmen.*\\s")
.withTimes(2)
.withStartupTimeout(Duration.of(60, SECONDS))));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,13 @@ void setup() {
@Test
void should_returnList_When_CallingListMethodOnTaskHistoryQuery() {
ClassificationHistoryEvent historyEvent = new ClassificationHistoryEvent();
historyEvent.setId(IdGenerator.generateWithPrefix(IdGenerator.ID_PREFIX_CLASSIFICATION_HISTORY_EVENT));
historyEvent.setId(
IdGenerator.generateWithPrefix(IdGenerator.ID_PREFIX_CLASSIFICATION_HISTORY_EVENT));
historyEvent.setUserId("admin");
historyEvent.setDetails("someDetails");
historyEvent.setEventType(ClassificationHistoryEventType.CREATED.getName());

List<ClassificationHistoryEvent> returnList = List.of(
historyEvent);
List<ClassificationHistoryEvent> returnList = List.of(historyEvent);

doNothing().when(internalKadaiEngineMock).openConnection();
doNothing().when(internalKadaiEngineMock).returnConnection();
Expand All @@ -77,5 +77,4 @@ void should_returnList_When_CallingListMethodOnTaskHistoryQuery() {
validateMockitoUsage();
assertThat(result).isEqualTo(returnList);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,15 @@ void setup() {
@Test
void should_ReturnList_When_CallingListMethodOnWorkbasketHistoryQuery() {
WorkbasketHistoryEvent historyEvent = new WorkbasketHistoryEvent();
historyEvent.setId(IdGenerator.generateWithPrefix(IdGenerator.ID_PREFIX_WORKBASKET_HISTORY_EVENT));
historyEvent.setId(
IdGenerator.generateWithPrefix(IdGenerator.ID_PREFIX_WORKBASKET_HISTORY_EVENT));
historyEvent.setUserId("someUserId");
historyEvent.setDetails("someDetails");
historyEvent.setKey("abcd");
historyEvent.setEventType(WorkbasketHistoryEventType.CREATED.getName());
historyEvent.setCreated(null);

List<WorkbasketHistoryEvent> returnList = List.of(
historyEvent);
List<WorkbasketHistoryEvent> returnList = List.of(historyEvent);
TimeInterval interval = new TimeInterval(Instant.now().minusNanos(1000), Instant.now());

doNothing().when(internalKadaiEngineMock).openConnection();
Expand Down
40 changes: 20 additions & 20 deletions lib/kadai-core-test/src/test/java/acceptance/PojoTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,26 +44,26 @@
/** check classes with a custom equals and hashcode implementation for correctness. */
class PojoTest {

private static final List<? extends Class<?>> POJO_CLASSES = getPojoClasses();

private static List<? extends Class<?>> getPojoClasses() {
// TODO how to identify pojos? Is overwritten equals method enough?
return new ClassFileImporter()
.importPackages("io.kadai").stream()
.filter(javaClass -> javaClass.tryGetMethod("equals", Object.class).isPresent())
.filter(
javaClass ->
!javaClass.getSimpleName().equals("TaskHistoryEvent")
&& !javaClass.getSimpleName().equals("WorkbasketHistoryEvent")
&& !javaClass.getSimpleName().equals("ClassificationHistoryEvent")
&& !javaClass.getSimpleName().equals("ComparableVersion")
&& !javaClass.getSimpleName().equals("StringItem")
&& !javaClass.getSimpleName().equals("BigIntegerItem")
&& !javaClass.getSimpleName().equals("IntItem")
&& !javaClass.getSimpleName().equals("LongItem"))
.map(JavaClass::reflect)
.toList();
}
private static final List<? extends Class<?>> POJO_CLASSES =
new ClassFileImporter()
.importPackages("io.kadai").stream()
.filter(javaClass -> javaClass.tryGetMethod("equals", Object.class).isPresent())
.filter(
javaClass ->
!javaClass.getSimpleName().equals("TaskHistoryEvent")
&& !javaClass.getSimpleName().equals("WorkbasketHistoryEvent")
&& !javaClass.getSimpleName().equals("ClassificationHistoryEvent")
&& !javaClass.getSimpleName().equals("ComparableVersion")
&& !javaClass.getSimpleName().equals("StringItem")
&& !javaClass.getSimpleName().equals("BigIntegerItem")
&& !javaClass.getSimpleName().equals("IntItem")
&& !javaClass.getSimpleName().equals("LongItem")
// This is a record, it has a getter per definition
&& !javaClass.getSimpleName().equals("DurationPrioHolder")
// This is a record, it has a getter per definition
&& !javaClass.getSimpleName().equals("CustomHoliday"))
.map(JavaClass::reflect)
.toList();

@Test
void testsThatPojoClassesAreFound() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,19 +178,19 @@ void setup() throws Exception {
.primaryObjRef(defaultObjectReference)
.buildAndStore(taskService);

TaskCommentBuilder.newTaskComment()
.taskId(task.getId())
.textField("Text1")
.created(Instant.now())
.modified(Instant.now())
.buildAndStore(taskService);

TaskCommentBuilder.newTaskComment()
.taskId(task.getId())
.textField("Text1")
.created(Instant.now())
.modified(Instant.now())
.buildAndStore(taskService);
TaskCommentBuilder.newTaskComment()
.taskId(task.getId())
.textField("Text1")
.created(Instant.now())
.modified(Instant.now())
.buildAndStore(taskService);

TaskCommentBuilder.newTaskComment()
.taskId(task.getId())
.textField("Text1")
.created(Instant.now())
.modified(Instant.now())
.buildAndStore(taskService);
}

@WithAccessId(user = "user-1-1")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@
import java.util.Map;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import javax.security.auth.Subject;
import org.assertj.core.api.ThrowableAssert.ThrowingCallable;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -411,11 +411,11 @@ void should_UpdateReadFlagOfTask_When_SetReadToFalse() throws Exception {
@WithAccessId(user = "user-1-2")
@Test
void should_ThrowException_When_UpdatingTaskWithInvalidId() throws Exception {
TaskBuilder.newTask()
.classificationSummary(defaultClassificationSummary)
.workbasketSummary(defaultWorkbasketSummary)
.primaryObjRef(defaultObjectReference)
.buildAndStore(taskService, "admin");
TaskBuilder.newTask()
.classificationSummary(defaultClassificationSummary)
.workbasketSummary(defaultWorkbasketSummary)
.primaryObjRef(defaultObjectReference)
.buildAndStore(taskService, "admin");

ThrowingCallable call = () -> taskService.setTaskRead("INVALID", true);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ void insertAndDeleteAttachmentsOnTaskUpdate(TaskImpl newTaskImpl, TaskImpl oldTa
ClassificationNotFoundException {
List<Attachment> newAttachments =
newTaskImpl.getAttachments().stream().filter(Objects::nonNull).toList();
newTaskImpl.setAttachments(newAttachments);
newTaskImpl.setAttachments(new ArrayList<>(newAttachments));

for (Attachment attachment : newAttachments) {
verifyAttachment((AttachmentImpl) attachment, newTaskImpl.getDomain());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,10 @@ public TaskSummary asSummary() {
@Override
public Attachment removeAttachment(String attachmentId) {

if (attachmentId == null) {
return null;
}

Optional<Attachment> removedAttachment =
attachments.stream()
.filter(attachment -> attachmentId.equals(attachment.getId()))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@
import java.util.Optional;
import java.util.UUID;
import java.util.function.Consumer;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import javax.security.auth.Subject;
import org.junit.jupiter.api.BeforeAll;
Expand Down Expand Up @@ -89,8 +88,7 @@ void should_ClaimDifferentTasks_For_ConcurrentSelectAndClaimCalls() throws Excep

List<String> accessIds =
Collections.synchronizedList(
Stream.of("admin", "teamlead-1", "teamlead-2", "taskadmin")
.toList());
new ArrayList<>(List.of("admin", "teamlead-1", "teamlead-2", "taskadmin")));

ParallelThreadHelper.runInThread(
getRunnableTest(selectedAndClaimedTasks, accessIds), accessIds.size());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
import io.kadai.workbasket.api.models.Workbasket;
import io.kadai.workbasket.api.models.WorkbasketSummary;
import java.util.List;
import java.util.stream.Collectors;
import org.assertj.core.api.ThrowableAssert.ThrowingCallable;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestTemplate;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,10 @@ private DockerContainerCreator() {
public static Optional<JdbcDatabaseContainer<?>> createDockerContainer(DB db) {
switch (db) {
case DB2:
try (Db2Container db2Container = new Db2Container(
DockerImageName.parse("taskana/db2:11.5")
.asCompatibleSubstituteFor("ibmcom/db2"))) {
try (Db2Container db2Container =
new Db2Container(
DockerImageName.parse("taskana/db2:11.5")
.asCompatibleSubstituteFor("ibmcom/db2"))) {

return Optional.of(
db2Container
Expand All @@ -55,8 +56,8 @@ public static Optional<JdbcDatabaseContainer<?>> createDockerContainer(DB db) {
.withDatabaseName("TSKDB"));
}
case POSTGRES:
try (PostgreSQLContainer<?> selfPostgreSQLContainer = new PostgreSQLContainer<>(
DockerImageName.parse("postgres:14.7"))) {
try (PostgreSQLContainer<?> selfPostgreSQLContainer =
new PostgreSQLContainer<>(DockerImageName.parse("postgres:14.7"))) {

return Optional.of(
selfPostgreSQLContainer
Expand All @@ -66,12 +67,15 @@ public static Optional<JdbcDatabaseContainer<?>> createDockerContainer(DB db) {
.withCommand(
"/bin/sh",
"-c",
"localedef -i de_DE -c -f UTF-8 -A /usr/share/locale/locale.alias de_DE.UTF-8 "
+ "&& export LANG=de_DE.UTF-8 "
+ "&& /usr/local/bin/docker-entrypoint.sh postgres -c fsync=off")
"""
localedef -i de_DE -c -f UTF-8 -A \
/usr/share/locale/locale.alias de_DE.UTF-8 \
&& export LANG=de_DE.UTF-8 \
&& /usr/local/bin/docker-entrypoint.sh postgres -c fsync=off""")
.waitingFor(
new LogMessageWaitStrategy()
.withRegEx(".*Datenbanksystem ist bereit, um Verbindungen anzunehmen.*\\s")
.withRegEx(
".*Datenbanksystem ist bereit, um Verbindungen anzunehmen.*\\s")
.withTimes(2)
.withStartupTimeout(Duration.of(60, SECONDS))));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,8 @@ private ResponseEntity<Object> buildResponse(
private List<MalformedQueryParameter> extractMalformedQueryParameters(FieldError fieldError) {
if (fieldError.contains(TypeMismatchException.class)) {
TypeMismatchException typeMismatchException = fieldError.unwrap(TypeMismatchException.class);
if (typeMismatchException.getCause() instanceof ConversionFailedException conversionFailedException) {
if (typeMismatchException.getCause()
instanceof ConversionFailedException conversionFailedException) {
Class<?> targetType = conversionFailedException.getTargetType().getType();
if (targetType.isEnum()) {
String queryParameter = fieldError.getField();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@
import java.util.Comparator;
import java.util.LinkedList;
import java.util.List;
import java.util.stream.Collectors;
import org.springframework.lang.NonNull;
import org.springframework.stereotype.Component;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,10 @@

package io.kadai.task.rest.assembler;

import static org.springframework.hateoas.server.mvc.WebMvcLinkBuilder.linkTo;

import io.kadai.classification.rest.assembler.ClassificationSummaryRepresentationModelAssembler;
import io.kadai.task.api.TaskService;
import io.kadai.task.api.models.Attachment;
import io.kadai.task.internal.models.AttachmentImpl;
import io.kadai.task.rest.AttachmentController;
import io.kadai.task.rest.models.AttachmentRepresentationModel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.hateoas.server.RepresentationModelAssembler;
Expand Down Expand Up @@ -65,7 +62,6 @@ public AttachmentRepresentationModel toModel(@NonNull Attachment attachment) {
repModel.setObjectReference(objectReferenceAssembler.toModel(attachment.getObjectReference()));
repModel.setChannel(attachment.getChannel());
repModel.setCustomAttributes(attachment.getCustomAttributeMap());
repModel.add(linkTo(AttachmentController.class).slash(attachment.getId()).withSelfRel());
return repModel;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,7 @@ class TaskControllerIntTest {
@Autowired KadaiConfiguration kadaiConfiguration;

@Autowired
TaskControllerIntTest(
RestHelper restHelper
) {
TaskControllerIntTest(RestHelper restHelper) {
this.restHelper = restHelper;
}

Expand Down Expand Up @@ -443,7 +441,9 @@ Stream<DynamicTest> should_GetAllTasks_For_SpecifiedWorkbasketIdAndCustomIntFiel
.isInstanceOf(HttpStatusCodeException.class)
.hasMessageContaining(
String.format(
"Each interval in 'custom-int-%s-within' shouldn't consist of two 'null' values",
"""
Each interval in 'custom-int-%s-within' \
shouldn't consist of two 'null' values""",
i))
.extracting(HttpStatusCodeException.class::cast)
.extracting(HttpStatusCodeException::getStatusCode)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,8 @@ private List<User> getUsers(Connection connection) throws Exception {
users.add(rs.getString("USER_ID"));
}

return users.stream().map(wrap(userService::getUser)).toList();
List<User> userList = users.stream().map(wrap(userService::getUser)).toList();
return new ArrayList<>(userList);
}

private List<String> getGroupInfo(Connection connection, String userId) throws Exception {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import java.util.stream.Collectors;
import org.assertj.core.api.ThrowableAssert.ThrowingCallable;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import java.io.File;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
import org.camunda.bpm.model.dmn.Dmn;
import org.camunda.bpm.model.dmn.DmnModelInstance;
import org.camunda.bpm.model.dmn.instance.InputEntry;
Expand All @@ -42,8 +41,7 @@ void should_SanitizeInputEntries_When_ContainingRegex() throws Exception {
File testDmnModel = new ClassPathResource(TEST_DMN).getFile();
DmnModelInstance dmnModelInstance = Dmn.readModelFromFile(testDmnModel);

List<Rule> allRules =
dmnModelInstance.getModelElementsByType(Rule.class).stream().toList();
List<Rule> allRules = dmnModelInstance.getModelElementsByType(Rule.class).stream().toList();

List<InputEntry> inputEntriesOfFirstRuleToSanitize =
new ArrayList(allRules.get(1).getInputEntries());
Expand Down

0 comments on commit 45fd917

Please sign in to comment.