Skip to content
Snippets Groups Projects
Commit ad6b5b03 authored by OZGCloud's avatar OZGCloud
Browse files

OZG-6335 apply code review changes

parent 05eae236
Branches
Tags
No related merge requests found
......@@ -30,13 +30,14 @@ import java.util.stream.Stream;
import jakarta.validation.Valid;
import org.apache.commons.collections.MapUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated;
import de.ozgcloud.alfa.loeschanforderung.DeleteLoeschAnforderung;
import lombok.NonNull;
import lombok.RequiredArgsConstructor;
@RequiredArgsConstructor
@Validated
@Service
public class CommandService {
......@@ -45,8 +46,7 @@ public class CommandService {
private static final int WAIT_TIME_MS = 500;
private static final int COMMAND_REQUEST_THRESHOLD_MILLIS = 10000;
@Autowired
private CommandRemoteService remoteService;
private final CommandRemoteService remoteService;
/**
* @deprecated use {@link #createCommand(CreateCommand)} instead
......
......@@ -310,7 +310,7 @@ class CommandServiceTest {
class OnFinishedCommand {
@Test
void shouldReturnDoneCommand() {
void shouldReturnFinishedCommand() {
var resultCommand = service.waitUntilDone(finishedCommand);
assertThat(resultCommand).isEqualTo(finishedCommand);
......@@ -336,7 +336,7 @@ class CommandServiceTest {
void shouldReloadCommand() {
service.waitUntilDone(pendingCommand);
verify(service, times(1)).reloadCommand(pendingCommand.getId());
verify(service).reloadCommand(pendingCommand.getId());
}
@Test
......@@ -366,7 +366,21 @@ class CommandServiceTest {
}
@Test
void shouldReloadOnceAndReturnPendingCommand() {
void shouldReloadPendingCommand() {
doReturn(pendingCommand).when(service).reloadCommand(pendingCommand.getId());
try (MockedStatic<Calendar> calendarMockedStatic = mockStatic(Calendar.class)) {
calendarMockedStatic.when(Calendar::getInstance).thenReturn(calendar);
when(calendar.getTimeInMillis()).thenReturn(0L, 0L, 15000L);
service.waitUntilDone(pendingCommand);
verify(service).reloadCommand(pendingCommand.getId());
}
}
@Test
void shouldReturnPendingCommandAfterReload() {
doReturn(pendingCommand).when(service).reloadCommand(pendingCommand.getId());
try (MockedStatic<Calendar> calendarMockedStatic = mockStatic(Calendar.class)) {
......@@ -375,7 +389,6 @@ class CommandServiceTest {
var resultCommand = service.waitUntilDone(pendingCommand);
verify(service, times(1)).reloadCommand(pendingCommand.getId());
assertThat(resultCommand).isEqualTo(pendingCommand);
}
}
......
......@@ -14,7 +14,7 @@ class CommandStatusTest {
@ParameterizedTest
@EnumSource(names = { "PENDING", "REVOKE_PENDING" })
public void shouldReturnTrue(CommandStatus status) {
void shouldReturnTrue(CommandStatus status) {
var istNotDone = status.isNotDone();
assertThat(istNotDone).isTrue();
......@@ -23,7 +23,7 @@ class CommandStatusTest {
@ParameterizedTest
@EnumSource(names = { "PENDING", "REVOKE_PENDING" }, mode = Mode.EXCLUDE)
public void shouldReturnFalse(CommandStatus status) {
void shouldReturnFalse(CommandStatus status) {
var istNotDone = status.isNotDone();
assertThat(istNotDone).isFalse();
......
......@@ -9,6 +9,7 @@ import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.EnumSource;
import org.junit.jupiter.params.provider.EnumSource.Mode;
import org.junit.jupiter.params.provider.ValueSource;
import org.mockito.Mock;
import com.thedeanda.lorem.LoremIpsum;
......@@ -18,10 +19,9 @@ class CommandTest {
@Nested
class TestIsFinishedSuccessfully {
@ParameterizedTest
@EnumSource(names = "FINISHED")
void shouldReturnTrue(CommandStatus commandStatus) {
var command = CommandTestFactory.createBuilder().status(commandStatus).build();
@Test
void shouldReturnTrue() {
var command = CommandTestFactory.createBuilder().status(CommandStatus.FINISHED).build();
var isDoneSuccessfully = command.isFinishedSuccessfully();
......@@ -63,19 +63,20 @@ class CommandTest {
}
@Test
public void shouldCallIsNotDone() {
void shouldCallIsNotDone() {
command.isNotDone();
verify(commandStatus).isNotDone();
}
@Test
public void shouldReturnIsNotDone() {
when(commandStatus.isNotDone()).thenReturn(true);
@ParameterizedTest
@ValueSource(booleans = { true, false })
void shouldReturnIsNotDone(boolean isNotDone) {
when(commandStatus.isNotDone()).thenReturn(isNotDone);
var isNotDone = command.isNotDone();
var result = command.isNotDone();
assertThat(isNotDone).isTrue();
assertThat(result).isEqualTo(isNotDone);
}
}
......
......@@ -272,13 +272,13 @@ class WiedervorlageServiceTest {
@Test
void shouldReturnDoneCommand() {
var errorCommand = CommandTestFactory.createBuilder().status(CommandStatus.ERROR).build();
var doneCommand = CommandTestFactory.createBuilder().status(CommandStatus.FINISHED).build();
var command = CommandTestFactory.create();
when(commandService.waitUntilDone(command)).thenReturn(errorCommand);
when(commandService.waitUntilDone(command)).thenReturn(doneCommand);
var result = service.updateNextFrist(command, VorgangHeaderTestFactory.ID);
assertThat(result).isEqualTo(errorCommand);
assertThat(result).isEqualTo(doneCommand);
}
@Nested
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment