diff --git a/nachrichten-manager-server/src/main/java/de/ozgcloud/nachrichten/postfach/PostfachService.java b/nachrichten-manager-server/src/main/java/de/ozgcloud/nachrichten/postfach/PostfachService.java index 650a7a0bd7209e6d1ca8dfd90269c85a42c7cb80..2d6341f5d91d755bff17204a8cf23e7de051abc5 100644 --- a/nachrichten-manager-server/src/main/java/de/ozgcloud/nachrichten/postfach/PostfachService.java +++ b/nachrichten-manager-server/src/main/java/de/ozgcloud/nachrichten/postfach/PostfachService.java @@ -28,6 +28,7 @@ import java.util.EnumSet; import java.util.Map; import java.util.Optional; import java.util.Set; +import java.util.function.Supplier; import java.util.stream.Stream; import jakarta.annotation.PostConstruct; @@ -240,21 +241,19 @@ class PostfachService { } public Stream<Postfach> getPostfachs() { - return postfachRemoteServices.stream().flatMap(Collection::stream).map(this::buildPostfach); - } - - // TODO wieder einbauen - private Stream<Postfach> getPostfaecher() { - var postfach = buildPostfach(postfachRemoteService); - // TODO Nach Umstellung auf BAYERN_ID entfernen - if (postfachRemoteService.getPostfachType().equals("BAYERN_ID")) { - return Stream.of(postfach, Postfach.builder() - .type("BayernId") - .isReplyAllowed(postfach.isReplyAllowed()) - .build()); - } - // - return Stream.of(postfach); + Supplier<Stream<PostfachRemoteService>> postfachRemoteServicesStream = () -> postfachRemoteServices.stream().flatMap(Collection::stream); + var oldBayernIdPostfachStream = buildOldBayernIdPostfach(postfachRemoteServicesStream.get()); + var postfachsStream = postfachRemoteServicesStream.get().map(this::buildPostfach); + return Stream.concat(postfachsStream, oldBayernIdPostfachStream); + } + + // TODO Nach Umstellung auf BAYERN_ID entfernen + private Stream<Postfach> buildOldBayernIdPostfach(Stream<PostfachRemoteService> postfachRemoteServicesStream) { + return postfachRemoteServicesStream.filter(remotePostfach -> "BAYERN_ID".equals(remotePostfach.getPostfachType())) + .map(remotePostfach -> Postfach.builder() + .type("BayernId") + .isReplyAllowed(isReplyAllowed(remotePostfach)) + .build()); } Postfach buildPostfach(PostfachRemoteService postfachRemoteService) { diff --git a/nachrichten-manager-server/src/test/java/de/ozgcloud/nachrichten/postfach/PostfachServiceTest.java b/nachrichten-manager-server/src/test/java/de/ozgcloud/nachrichten/postfach/PostfachServiceTest.java index 2271307270f746e7d8fd0ea0ff197a4cd638d6f3..ca8bde69ac33680ed7dc28b5ab92d491934d5e8a 100644 --- a/nachrichten-manager-server/src/test/java/de/ozgcloud/nachrichten/postfach/PostfachServiceTest.java +++ b/nachrichten-manager-server/src/test/java/de/ozgcloud/nachrichten/postfach/PostfachServiceTest.java @@ -860,11 +860,6 @@ class PostfachServiceTest { private final Postfach postfach = PostfachTestFactory.create(); - @BeforeEach - void init() { - doReturn(postfach).when(service).buildPostfach(any()); - } - @Test void shouldCallBuildPostfach() { when(postfachRemoteService.getPostfachType()).thenReturn(PostfachTestFactory.POSTFACH_TYPE); @@ -898,7 +893,6 @@ class PostfachServiceTest { @BeforeEach void mock() { - doReturn(true).when(service).isPostfachConfigured(); when(postfachRemoteService.getPostfachType()).thenReturn(BAYERN_ID_POSTFACH); }