From 65ef270037a23c3f9c9e804e572f5a448edd85dd Mon Sep 17 00:00:00 2001
From: OZGCloud <ozgcloud@mgm-tp.com>
Date: Fri, 16 Feb 2024 21:03:15 +0100
Subject: [PATCH] OZG-4857 OZG-4934 replace spy call with annotation

---
 .../alfa/file/DokumentTypeBuilderTest.java    |  6 ++-
 .../kommentar/DokumentTypeBuilderTest.java    | 54 ++++++++++++-------
 2 files changed, 38 insertions(+), 22 deletions(-)

diff --git a/alfa-xdomea/src/test/java/de/ozgcloud/alfa/file/DokumentTypeBuilderTest.java b/alfa-xdomea/src/test/java/de/ozgcloud/alfa/file/DokumentTypeBuilderTest.java
index ed76f76f0f..1a7988fe6f 100644
--- a/alfa-xdomea/src/test/java/de/ozgcloud/alfa/file/DokumentTypeBuilderTest.java
+++ b/alfa-xdomea/src/test/java/de/ozgcloud/alfa/file/DokumentTypeBuilderTest.java
@@ -11,6 +11,7 @@ import org.junit.jupiter.api.Nested;
 import org.junit.jupiter.api.Test;
 import org.mockito.Mock;
 import org.mockito.MockedStatic;
+import org.mockito.Spy;
 
 import de.ozgcloud.alfa.common.FormatTypeTestFactory;
 import de.ozgcloud.alfa.common.PrimaerdokumentTypeBuilder;
@@ -34,10 +35,11 @@ class DokumentTypeBuilderTest {
 	private static final String FORM_ENGINE_NAME = "DUMMY_NAME";
 	private final OzgFile ozgFile = OzgFileTestFactory.create();
 
-	private final DokumentTypeBuilder builder = spy(DokumentTypeBuilder.builder()
+	@Spy
+	private final DokumentTypeBuilder builder = DokumentTypeBuilder.builder()
 			.withOzgFile(ozgFile)
 			.withFormEngineName(FORM_ENGINE_NAME)
-			.withOrdinalNumber(DOKUMENT_ORDINAL_NUMBER));
+			.withOrdinalNumber(DOKUMENT_ORDINAL_NUMBER);
 
 	private MockedStatic<UUIDConverter> uuidConverter;
 
diff --git a/alfa-xdomea/src/test/java/de/ozgcloud/alfa/kommentar/DokumentTypeBuilderTest.java b/alfa-xdomea/src/test/java/de/ozgcloud/alfa/kommentar/DokumentTypeBuilderTest.java
index 01e419fb33..ffdbfe1331 100644
--- a/alfa-xdomea/src/test/java/de/ozgcloud/alfa/kommentar/DokumentTypeBuilderTest.java
+++ b/alfa-xdomea/src/test/java/de/ozgcloud/alfa/kommentar/DokumentTypeBuilderTest.java
@@ -12,6 +12,7 @@ import org.junit.jupiter.api.Nested;
 import org.junit.jupiter.api.Test;
 import org.mockito.Mock;
 import org.mockito.MockedStatic;
+import org.mockito.Spy;
 
 import de.ozgcloud.alfa.common.DateiformatCodeTypeTestFactory;
 import de.ozgcloud.alfa.common.FormatTypeTestFactory;
@@ -29,7 +30,8 @@ import de.xoev.xdomea.VersionType;
 
 class DokumentTypeBuilderTest {
 
-	private DokumentTypeBuilder builder = spy(DokumentTypeBuilder.builder());
+	@Spy
+	private DokumentTypeBuilder builder = DokumentTypeBuilder.builder();
 
 	@Nested
 	class TestBuild {
@@ -41,7 +43,6 @@ class DokumentTypeBuilderTest {
 		@BeforeEach
 		void setUp() {
 			doReturn(identifikationObjektType).when(builder).createKommentarIdentifikation();
-			doReturn(anlageDokumentType).when(builder).createAnlage(ozgFile);
 		}
 
 		@Test
@@ -51,32 +52,45 @@ class DokumentTypeBuilderTest {
 			verify(builder).createKommentarIdentifikation();
 		}
 
-		@Test
-		void shouldHaveIdentifikation() {
-			var dokumentType = builder.build();
+		@Nested
+		class WithoutKommentareAttachments {
 
-			assertThat(dokumentType.getIdentifikation()).isEqualTo(identifikationObjektType);
-		}
+			@Test
+			void shouldHaveIdentifikation() {
+				var dokumentType = builder.build();
 
-		@Test
-		void shouldHaveTypNotiz() {
-			var dokumentType = builder.build();
+				assertThat(dokumentType.getIdentifikation()).isEqualTo(identifikationObjektType);
+			}
+
+			@Test
+			void shouldHaveTypNotiz() {
+				var dokumentType = builder.build();
 
-			assertThat(dokumentType.getTyp()).isEqualTo(DokumentTypeBuilder.TYP);
+				assertThat(dokumentType.getTyp()).isEqualTo(DokumentTypeBuilder.TYP);
+			}
 		}
 
-		@Test
-		void shouldCreateAnlagenForKommentarAttachments() {
-			builder.withKommentarAttachments(List.of(ozgFile)).build();
+		@Nested
+		class WithKommentareAttachments {
 
-			verify(builder).createAnlage(ozgFile);
-		}
+			@BeforeEach
+			void setUp() {
+				doReturn(anlageDokumentType).when(builder).createAnlage(ozgFile);
+			}
 
-		@Test
-		void shouldHaveAnlagen() {
-			var dokumentType = builder.withKommentarAttachments(List.of(ozgFile)).build();
+			@Test
+			void shouldCreateAnlagenForKommentarAttachments() {
+				builder.withKommentarAttachments(List.of(ozgFile)).build();
+
+				verify(builder).createAnlage(ozgFile);
+			}
+
+			@Test
+			void shouldHaveAnlagen() {
+				var dokumentType = builder.withKommentarAttachments(List.of(ozgFile)).build();
 
-			assertThat(dokumentType.getAnlage()).contains(anlageDokumentType);
+				assertThat(dokumentType.getAnlage()).contains(anlageDokumentType);
+			}
 		}
 	}
 
-- 
GitLab