Skip to content
Snippets Groups Projects
Commit 3e944211 authored by OZGCloud's avatar OZGCloud
Browse files

OZG-6362 Test aktualisiert.

parent abd99cb8
Branches
Tags
No related merge requests found
......@@ -22,14 +22,12 @@
*/
package de.ozgcloud.nachrichten.postfach;
import static de.ozgcloud.nachrichten.postfach.PersistPostfachNachrichtServiceImpl.*;
import static org.assertj.core.api.Assertions.*;
import static org.mockito.ArgumentMatchers.*;
import static org.mockito.Mockito.*;
import java.time.ZonedDateTime;
import java.time.temporal.ChronoUnit;
import java.util.Map;
import java.util.Optional;
import java.util.UUID;
import java.util.stream.Stream;
......@@ -52,7 +50,6 @@ import org.springframework.boot.logging.LogLevel;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.test.util.ReflectionTestUtils;
import de.ozgcloud.common.errorhandling.TechnicalException;
import de.ozgcloud.nachrichten.antragraum.AntragraumService;
import de.ozgcloud.nachrichten.attributes.ClientAttributeService;
import de.ozgcloud.nachrichten.info.InfoManagerService;
......@@ -68,24 +65,23 @@ import nl.altindag.log.LogCaptor;
class PostfachServiceTest {
static final String COMMAND_ID = UUID.randomUUID().toString();
static final String USER_ID = UUID.randomUUID().toString();
@Spy
@InjectMocks
private PostfachService service;
@Mock
private PostfachRemoteService postfachRemoteService;
@Mock
private PersistPostfachNachrichtService persistingService;
@Spy
private PostfachNachrichtMapper mapper = Mappers.getMapper(PostfachNachrichtMapper.class);
@Mock
private ClientAttributeService clientAttributeService;
@Mock
private MessageAttachmentService messageAttachmentService;
@Mock
private ApplicationEventPublisher publisher;
@Mock
private CurrentUserService userService;
@Spy
......@@ -93,9 +89,6 @@ class PostfachServiceTest {
@Spy
private Optional<InfoManagerService> infomanagerService = Optional.of(mock(InfoManagerService.class));
static final String COMMAND_ID = UUID.randomUUID().toString();
static final String USER_ID = UUID.randomUUID().toString();
@Nested
class TestSaveDraft {
......@@ -316,6 +309,10 @@ class PostfachServiceTest {
@Mock
private PostfachNachricht mail;
private Optional<PostfachNachricht> adjustMail() {
return service.adjustMail(mail);
}
@Nested
class TestReplaceBody {
......@@ -339,10 +336,6 @@ class PostfachServiceTest {
assertThat(result).isPresent().get().extracting(PostfachNachricht::getMailBody).isEqualTo(expectedMailBody);
}
}
private Optional<PostfachNachricht> adjustMail() {
return service.adjustMail(mail);
}
}
}
......@@ -804,8 +797,8 @@ class PostfachServiceTest {
@Nested
class TestSavingMukAntwort {
private PostfachNachricht antwort;
private final String refId = ObjectId.get().toHexString();
private PostfachNachricht antwort;
@BeforeEach
void setup() {
......@@ -824,8 +817,6 @@ class PostfachServiceTest {
@Nested
class TestLinkingMukAntwortToVorgang {
private final String vorgangId = ObjectId.get().toHexString();
@BeforeEach
void setup() {
antwort = PostfachNachrichtTestFactory.createBuilder().vorgangId(null).referencedNachricht(refId).build();
......@@ -834,28 +825,12 @@ class PostfachServiceTest {
}
@Test
void shouldLoadLinkedNachricht() {
when(service.findById(eq(refId))).thenReturn(Optional.of(Map.of(VORGANG_ID_FIELD, vorgangId)));
service.fetchAndPersistReplies();
verify(service).findById(anyString());
}
@Test
void shouldSetVorgangId() {
when(service.findById(anyString())).thenReturn(Optional.of(Map.of(VORGANG_ID_FIELD, vorgangId)));
void shouldLoadPersistedNachricht() {
when(persistingService.getById(anyString())).thenReturn(PostfachNachrichtTestFactory.asMap());
service.fetchAndPersistReplies();
verify(service).setVorgangId(anyString(), any(PostfachNachricht.class));
}
@Test
void shouldThrowExceptionWhenVorgangIdEmpty() {
when(service.findById(anyString())).thenReturn(Optional.of(Map.of("otherId", ObjectId.get().toHexString())));
assertThatExceptionOfType(TechnicalException.class).isThrownBy(() -> service.fetchAndPersistReplies());
verify(service).getNachricht(anyString());
}
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment