From 5d6a7d44327f18e5aef057246e5b2309963a89d3 Mon Sep 17 00:00:00 2001 From: BartChris Date: Tue, 10 Dec 2024 18:35:58 +0100 Subject: [PATCH] Refactor tests to include review comments --- .../copyprocess/CreateProcessFormIT.java | 25 +++++++++++-------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/Kitodo/src/test/java/org/kitodo/production/forms/copyprocess/CreateProcessFormIT.java b/Kitodo/src/test/java/org/kitodo/production/forms/copyprocess/CreateProcessFormIT.java index 097954f0120..47a73108f80 100644 --- a/Kitodo/src/test/java/org/kitodo/production/forms/copyprocess/CreateProcessFormIT.java +++ b/Kitodo/src/test/java/org/kitodo/production/forms/copyprocess/CreateProcessFormIT.java @@ -24,6 +24,7 @@ import org.apache.commons.lang3.SystemUtils; import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; import org.kitodo.ExecutionPermission; @@ -50,6 +51,7 @@ public class CreateProcessFormIT { private static final ProcessService processService = ServiceManager.getProcessService(); private static final String firstProcess = "First process"; + private Process createdProcess; /** * Is running before the class runs. @@ -77,6 +79,16 @@ public static void cleanDatabase() throws Exception { MockDatabase.cleanDatabase(); } + @AfterEach + public void cleanUpAfterEach() throws Exception { + if (createdProcess != null && createdProcess.getId() != null) { + processService.remove(createdProcess.getId()); + fileService.delete(URI.create(createdProcess.getId().toString())); + } + createdProcess = null; + setScriptPermissions(false); + } + // Helper to create and initialize a CreateProcessForm with common properties private CreateProcessForm setupCreateProcessForm(String docType) throws Exception { CreateProcessForm form = new CreateProcessForm(); @@ -106,13 +118,6 @@ private void setScriptPermissions(boolean enable) throws Exception { } } - // Helper to clean up database and file system - private void cleanUpProcess(Process process) throws Exception { - Integer processId = process.getId(); - processService.remove(processId); - fileService.delete(URI.create(processId.toString())); - } - @Test public void shouldCreateNewProcess() throws Exception { CreateProcessForm underTest = setupCreateProcessForm("Monograph"); @@ -125,7 +130,7 @@ public void shouldCreateNewProcess() throws Exception { long after = processService.count(); assertEquals(before + 1, after, "No process was created!"); - cleanUpProcess(underTest.getMainProcess()); + createdProcess = underTest.getMainProcess(); } @Test @@ -142,7 +147,7 @@ public void shouldCreateNewProcessWithoutWorkflow() throws Exception { assertTrue(underTest.getMainProcess().getTasks().isEmpty(), "Process should not have tasks"); assertNull(underTest.getMainProcess().getSortHelperStatus(), "Process should not have sortHelperStatus"); - cleanUpProcess(underTest.getMainProcess()); + createdProcess = underTest.getMainProcess(); } @Test @@ -180,7 +185,7 @@ public void shouldNotAllowDuplicateTitles() throws Exception { long afterDuplicate = processService.count(); assertEquals(beforeDuplicate, afterDuplicate, "A duplicate process with the same title was created!"); - cleanUpProcess(underTest.getMainProcess()); + createdProcess = underTest.getMainProcess(); } }