From eec72fe91ef1f27c83bf60ae56a1456fbd2a43c4 Mon Sep 17 00:00:00 2001
From: OZGCloud <ozgcloud@mgm-tp.com>
Date: Thu, 28 Oct 2021 17:10:15 +0200
Subject: [PATCH] OZG-1194 return loaded nachricht

---
 .../goofy/postfach/PostfachMailRemoteService.java    |  5 +++--
 .../goofy/postfach/GrpcPostfachMailTestFactory.java  |  7 +++++++
 .../postfach/PostfachMailRemoteServiceTest.java      | 12 ++++++++++++
 3 files changed, 22 insertions(+), 2 deletions(-)

diff --git a/goofy-server/src/main/java/de/itvsh/goofy/postfach/PostfachMailRemoteService.java b/goofy-server/src/main/java/de/itvsh/goofy/postfach/PostfachMailRemoteService.java
index f8be24fef2..3a86a2826c 100644
--- a/goofy-server/src/main/java/de/itvsh/goofy/postfach/PostfachMailRemoteService.java
+++ b/goofy-server/src/main/java/de/itvsh/goofy/postfach/PostfachMailRemoteService.java
@@ -52,8 +52,9 @@ class PostfachMailRemoteService {
 	}
 
 	public Optional<PostfachMail> findById(PostfachNachrichtId nachrichtId) {
-		serviceStub.findPostfachMail(buildFindPostfachMailRequest(nachrichtId));
-		return Optional.empty();
+		var response = serviceStub.findPostfachMail(buildFindPostfachMailRequest(nachrichtId));
+
+		return Optional.ofNullable(response.getNachricht()).map(mailMapper::toPostfachMail);
 	}
 
 	private GrpcFindPostfachMailRequest buildFindPostfachMailRequest(PostfachNachrichtId nachrichtId) {
diff --git a/goofy-server/src/test/java/de/itvsh/goofy/postfach/GrpcPostfachMailTestFactory.java b/goofy-server/src/test/java/de/itvsh/goofy/postfach/GrpcPostfachMailTestFactory.java
index d0c7de56fe..bba3c6d06a 100644
--- a/goofy-server/src/test/java/de/itvsh/goofy/postfach/GrpcPostfachMailTestFactory.java
+++ b/goofy-server/src/test/java/de/itvsh/goofy/postfach/GrpcPostfachMailTestFactory.java
@@ -5,6 +5,7 @@ import static de.itvsh.goofy.postfach.PostfachMailTestFactory.*;
 import java.util.Arrays;
 
 import de.itvsh.ozg.mail.postfach.GrpcDirection;
+import de.itvsh.ozg.mail.postfach.GrpcFindPostfachMailResponse;
 import de.itvsh.ozg.mail.postfach.GrpcFindPostfachMailsResponse;
 import de.itvsh.ozg.mail.postfach.GrpcPostfachMail;
 
@@ -36,4 +37,10 @@ public class GrpcPostfachMailTestFactory {
 				.addAllMails(Arrays.asList(create()))
 				.build();
 	}
+
+	public static GrpcFindPostfachMailResponse createFindPostfachMailResponse() {
+		return GrpcFindPostfachMailResponse.newBuilder()
+				.setNachricht(create())
+				.build();
+	}
 }
\ No newline at end of file
diff --git a/goofy-server/src/test/java/de/itvsh/goofy/postfach/PostfachMailRemoteServiceTest.java b/goofy-server/src/test/java/de/itvsh/goofy/postfach/PostfachMailRemoteServiceTest.java
index d0f6efab46..3e92af7804 100644
--- a/goofy-server/src/test/java/de/itvsh/goofy/postfach/PostfachMailRemoteServiceTest.java
+++ b/goofy-server/src/test/java/de/itvsh/goofy/postfach/PostfachMailRemoteServiceTest.java
@@ -84,6 +84,11 @@ class PostfachMailRemoteServiceTest {
 		@Captor
 		private ArgumentCaptor<GrpcFindPostfachMailRequest> requestCaptor;
 
+		@BeforeEach
+		void init() {
+			when(serviceStub.findPostfachMail(any())).thenReturn(GrpcPostfachMailTestFactory.createFindPostfachMailResponse());
+		}
+
 		@Test
 		void shouldCallStub() {
 			service.findById(PostfachMailTestFactory.NACHRICHT_ID);
@@ -106,6 +111,13 @@ class PostfachMailRemoteServiceTest {
 
 			assertThat(requestCaptor.getValue().getNachrichtId()).isEqualTo(PostfachMailTestFactory.ID);
 		}
+
+		@Test
+		void shouldCallMapper() {
+			service.findById(PostfachMailTestFactory.NACHRICHT_ID);
+
+			verify(mapper).toPostfachMail(any());
+		}
 	}
 
 	@Nested
-- 
GitLab