diff --git a/alfa-service/src/test/java/de/ozgcloud/alfa/historie/AktenzeichenChangeHistoryBuilderTest.java b/alfa-service/src/test/java/de/ozgcloud/alfa/historie/AktenzeichenChangeHistoryBuilderTest.java index 8e93aebbbe2b07ebd56c415094528926fe13165d..b53c71a74f848aa6613238fa0cd6c36bd6ce6e8f 100644 --- a/alfa-service/src/test/java/de/ozgcloud/alfa/historie/AktenzeichenChangeHistoryBuilderTest.java +++ b/alfa-service/src/test/java/de/ozgcloud/alfa/historie/AktenzeichenChangeHistoryBuilderTest.java @@ -28,9 +28,6 @@ public class AktenzeichenChangeHistoryBuilderTest { private final Command command = commandFinishedAt(LocalDateTime.of(2023, 6, 1, 12, 0)); private final List<Command> commands = List.of(previousCommand, command); - private final CommandWithPrevious commandWithoutPrevious = CommandWithPreviousTestFactory.createBuilder().command(previousCommand).previous(null).build(); - private final CommandWithPrevious commandWithPrevious = CommandWithPreviousTestFactory.createBuilder().command(command).previous(previousCommand).build(); - @Spy private AktenzeichenChangeHistoryBuilder builder = AktenzeichenChangeHistoryBuilder.builder() .withCommands(commands) @@ -90,6 +87,8 @@ public class AktenzeichenChangeHistoryBuilderTest { private static final String EXPECTED_AKTENZEICHEN_BEFORE_CHANGE = LoremIpsum.getInstance().getWords(2); private static final String EXPECTED_AKTENZEICHEN_AFTER_CHANGE = LoremIpsum.getInstance().getWords(2); + private final CommandWithPrevious commandWithPrevious = CommandWithPreviousTestFactory.createBuilder().command(command).previous(previousCommand).build(); + @BeforeEach void init() { when(builder.getAktenzeichenBeforeChange(commandWithPrevious)).thenReturn(EXPECTED_AKTENZEICHEN_BEFORE_CHANGE); @@ -125,6 +124,9 @@ public class AktenzeichenChangeHistoryBuilderTest { @Nested class TestGetAktenzeichenBeforeChange { + private final CommandWithPrevious commandWithoutPrevious = CommandWithPreviousTestFactory.createBuilder().command(previousCommand).previous(null).build(); + private final CommandWithPrevious commandWithPrevious = CommandWithPreviousTestFactory.createBuilder().command(command).previous(previousCommand).build(); + @Test void shouldReturnEmptyIfPreviousIsNull() { var aktenzeichen = builder.getAktenzeichenBeforeChange(commandWithoutPrevious); @@ -148,6 +150,8 @@ public class AktenzeichenChangeHistoryBuilderTest { private static final String EXPECTED_AKTENZEICHEN = LoremIpsum.getInstance().getWords(2); + private final CommandWithPrevious commandWithPrevious = CommandWithPreviousTestFactory.createBuilder().command(command).previous(previousCommand).build(); + @BeforeEach void init() { doReturn(EXPECTED_AKTENZEICHEN).when(builder).getAktenzeichen(command); diff --git a/alfa-service/src/test/java/de/ozgcloud/alfa/historie/AssignedUserChangeHistoryBuilderTest.java b/alfa-service/src/test/java/de/ozgcloud/alfa/historie/AssignedUserChangeHistoryBuilderTest.java index 74b1071ce618c71cff34b01ba7ed7a0172f2041f..7bda2c2adc0529d939bf48a1e8ce7b02179fa4e9 100644 --- a/alfa-service/src/test/java/de/ozgcloud/alfa/historie/AssignedUserChangeHistoryBuilderTest.java +++ b/alfa-service/src/test/java/de/ozgcloud/alfa/historie/AssignedUserChangeHistoryBuilderTest.java @@ -33,9 +33,6 @@ public class AssignedUserChangeHistoryBuilderTest { private final Command command = commandFinishedAt(LocalDateTime.of(2023, 6, 1, 12, 0)); private final List<Command> commands = List.of(previousCommand, command); - private final CommandWithPrevious commandWithoutPrevious = CommandWithPreviousTestFactory.createBuilder().command(previousCommand).previous(null).build(); - private final CommandWithPrevious commandWithPrevious = CommandWithPreviousTestFactory.createBuilder().command(command).previous(previousCommand).build(); - @Mock private UserProfileCache userProfileCache; @@ -99,6 +96,8 @@ public class AssignedUserChangeHistoryBuilderTest { private static final String ASSIGNED_USER_BEFORE_CHANGE = LoremIpsum.getInstance().getWords(2); private static final String ASSIGNED_USER_AFTER_CHANGE = LoremIpsum.getInstance().getWords(2); + private final CommandWithPrevious commandWithPrevious = CommandWithPreviousTestFactory.createBuilder().command(command).previous(previousCommand).build(); + @BeforeEach void init() { doReturn(ASSIGNED_USER_BEFORE_CHANGE).when(builder).getAssignedUserBeforeChange(commandWithPrevious); @@ -136,6 +135,9 @@ public class AssignedUserChangeHistoryBuilderTest { private static final String EXPECTED_ASSIGNED_USER = LoremIpsum.getInstance().getWords(2); + private final CommandWithPrevious commandWithoutPrevious = CommandWithPreviousTestFactory.createBuilder().command(previousCommand).previous(null).build(); + private final CommandWithPrevious commandWithPrevious = CommandWithPreviousTestFactory.createBuilder().command(command).previous(previousCommand).build(); + @Test void shouldReturnEmptyStringIfPreviousIsNull() { var assignedUser = builder.getAssignedUserBeforeChange(commandWithoutPrevious); @@ -175,8 +177,7 @@ public class AssignedUserChangeHistoryBuilderTest { private static final String EXPECTED_ASSIGNED_USER = LoremIpsum.getInstance().getWords(2); - @Mock - UserProfileCache userProfileCache; + private final CommandWithPrevious commandWithPrevious = CommandWithPreviousTestFactory.createBuilder().command(command).previous(previousCommand).build(); @Test void shouldGetAssignedUserFromCommand() { diff --git a/alfa-service/src/test/java/de/ozgcloud/alfa/historie/ChangeHistoryBuilderTest.java b/alfa-service/src/test/java/de/ozgcloud/alfa/historie/ChangeHistoryBuilderTest.java index ca6b54e3fcdc086231cbe07ece9cc2cda82d2f8b..b74e3731d50037845599f1743d0173e50a11b6ce 100644 --- a/alfa-service/src/test/java/de/ozgcloud/alfa/historie/ChangeHistoryBuilderTest.java +++ b/alfa-service/src/test/java/de/ozgcloud/alfa/historie/ChangeHistoryBuilderTest.java @@ -25,6 +25,7 @@ import com.thedeanda.lorem.LoremIpsum; import de.ozgcloud.alfa.common.command.Command; import de.ozgcloud.alfa.common.command.CommandTestFactory; import de.ozgcloud.alfa.common.user.UserProfileTestFactory; +import de.ozgcloud.alfa.historie.ChangeHistoryBuilder.CommandWithChangeValues; public class ChangeHistoryBuilderTest { @@ -34,17 +35,6 @@ public class ChangeHistoryBuilderTest { private final Command command = commandFinishedAt(LocalDateTime.of(2023, 6, 1, 12, 0)); private final List<Command> commands = List.of(previousCommand, command); - private final CommandWithPrevious commandWithoutPrevious = CommandWithPreviousTestFactory.createBuilder().command(previousCommand).previous(null).build(); - private final CommandWithPrevious commandWithPrevious = CommandWithPreviousTestFactory.createBuilder().command(command).previous(previousCommand).build(); - private final List<CommandWithPrevious> commandsWithPrevious = List.of(commandWithoutPrevious, commandWithPrevious); - - private final ChangeHistoryBuilder.CommandWithChangeValues previousCommandWithChangeValues = new ChangeHistoryBuilder.CommandWithChangeValues( - previousCommand, "a", "b"); - private final ChangeHistoryBuilder.CommandWithChangeValues commandWithChangeValues = new ChangeHistoryBuilder.CommandWithChangeValues( - command, "b", "c"); - private final List<ChangeHistoryBuilder.CommandWithChangeValues> commandsWithChangeValues = List.of(previousCommandWithChangeValues, - commandWithChangeValues); - @Spy private TestChangeHistoryBuilder builder = new TestChangeHistoryBuilder() .withCommands(commands) @@ -52,6 +42,14 @@ public class ChangeHistoryBuilderTest { @Nested class TestBuild { + + private final CommandWithChangeValues previousCommandWithChangeValues = new CommandWithChangeValues( + previousCommand, "a", "b"); + private final CommandWithChangeValues commandWithChangeValues = new CommandWithChangeValues( + command, "b", "c"); + private final List<CommandWithChangeValues> commandsWithChangeValues = List.of(previousCommandWithChangeValues, + commandWithChangeValues); + @Test void shouldCallInOrder() { var orderVerifier = Mockito.inOrder(builder); @@ -106,6 +104,17 @@ public class ChangeHistoryBuilderTest { @Nested class TestToCommandsWithChangeValues { + private final CommandWithPrevious commandWithoutPrevious = CommandWithPreviousTestFactory.createBuilder().command(previousCommand).previous(null).build(); + private final CommandWithPrevious commandWithPrevious = CommandWithPreviousTestFactory.createBuilder().command(command).previous(previousCommand).build(); + private final List<CommandWithPrevious> commandsWithPrevious = List.of(commandWithoutPrevious, commandWithPrevious); + + private final ChangeHistoryBuilder.CommandWithChangeValues previousCommandWithChangeValues = new ChangeHistoryBuilder.CommandWithChangeValues( + previousCommand, "a", "b"); + private final ChangeHistoryBuilder.CommandWithChangeValues commandWithChangeValues = new ChangeHistoryBuilder.CommandWithChangeValues( + command, "b", "c"); + private final List<ChangeHistoryBuilder.CommandWithChangeValues> commandsWithChangeValues = List.of(previousCommandWithChangeValues, + commandWithChangeValues); + @BeforeEach void init() { doReturn(previousCommandWithChangeValues).when(builder).toCommandWithChangeValues(commandWithoutPrevious); @@ -127,26 +136,29 @@ public class ChangeHistoryBuilderTest { assertThat(historieEntries).containsExactly(previousCommandWithChangeValues, commandWithChangeValues); } - private Stream<ChangeHistoryBuilder.CommandWithChangeValues> callBuilder() { + private Stream<CommandWithChangeValues> callBuilder() { return builder.toCommandsWithChangeValues(commandsWithPrevious.stream()); } } @Nested class TestToVorgangChange { - + + private final ChangeHistoryBuilder.CommandWithChangeValues commandWithChangeValues = new ChangeHistoryBuilder.CommandWithChangeValues( + previousCommand, "a", "b"); + @Test void shouldSeValueBeforeChange() { var vorgangChange = callBuilder(); - assertThat(vorgangChange.getValueBeforeChange()).isNotBlank().isEqualTo(previousCommandWithChangeValues.valueBeforeChange()); + assertThat(vorgangChange.getValueBeforeChange()).isNotBlank().isEqualTo(commandWithChangeValues.valueBeforeChange()); } @Test void shouldSeValueAfterChange() { var vorgangChange = callBuilder(); - assertThat(vorgangChange.getValueAfterChange()).isNotBlank().isEqualTo(previousCommandWithChangeValues.valueAfterChange()); + assertThat(vorgangChange.getValueAfterChange()).isNotBlank().isEqualTo(commandWithChangeValues.valueAfterChange()); } @Test @@ -178,7 +190,7 @@ public class ChangeHistoryBuilderTest { } private VorgangChange callBuilder() { - return builder.toVorgangChange(previousCommandWithChangeValues); + return builder.toVorgangChange(commandWithChangeValues); } } diff --git a/alfa-service/src/test/java/de/ozgcloud/alfa/historie/StatusChangeHistoryBuilderTest.java b/alfa-service/src/test/java/de/ozgcloud/alfa/historie/StatusChangeHistoryBuilderTest.java index 9914352adeca6a527f4f03a2cd9a29d7522f7887..824bce9b0ce2ef6df80e084c27a5eef8e177bab2 100644 --- a/alfa-service/src/test/java/de/ozgcloud/alfa/historie/StatusChangeHistoryBuilderTest.java +++ b/alfa-service/src/test/java/de/ozgcloud/alfa/historie/StatusChangeHistoryBuilderTest.java @@ -31,9 +31,6 @@ public class StatusChangeHistoryBuilderTest { private final Command command = commandFinishedAt(LocalDateTime.of(2023, 6, 1, 12, 0)); private final List<Command> commands = List.of(previousCommand, command); - private final CommandWithPrevious commandWithoutPrevious = CommandWithPreviousTestFactory.createBuilder().command(previousCommand).previous(null).build(); - private final CommandWithPrevious commandWithPrevious = CommandWithPreviousTestFactory.createBuilder().command(command).previous(previousCommand).build(); - @Spy private StatusChangeHistoryBuilder builder = StatusChangeHistoryBuilder.builder() .withCommands(commands) @@ -89,6 +86,8 @@ public class StatusChangeHistoryBuilderTest { private static final String EXPECTED_STATUS_BEFORE_CHANGE = LoremIpsum.getInstance().getWords(2); private static final String EXPECTED_STATUS_AFTER_CHANGE = LoremIpsum.getInstance().getWords(2); + private final CommandWithPrevious commandWithPrevious = CommandWithPreviousTestFactory.createBuilder().command(command).previous(previousCommand).build(); + @BeforeEach void init() { doReturn(EXPECTED_STATUS_BEFORE_CHANGE).when(builder).getStatusBeforeChange(commandWithPrevious); @@ -124,6 +123,9 @@ public class StatusChangeHistoryBuilderTest { @Nested class TestGetStatusBeforeChange { + private final CommandWithPrevious commandWithoutPrevious = CommandWithPreviousTestFactory.createBuilder().command(previousCommand).previous(null).build(); + private final CommandWithPrevious commandWithPrevious = CommandWithPreviousTestFactory.createBuilder().command(command).previous(previousCommand).build(); + @Test void shouldReturnStatusBeforeChange() { var status = "Status"; @@ -145,6 +147,8 @@ public class StatusChangeHistoryBuilderTest { @Nested class TestGetStatusAfterChange { + private final CommandWithPrevious commandWithPrevious = CommandWithPreviousTestFactory.createBuilder().command(command).previous(previousCommand).build(); + @Test void shouldReturnStatusAfterChange() { var status = "Status";