Skip to content
Snippets Groups Projects
Commit 19e3a382 authored by OZGCloud's avatar OZGCloud
Browse files

OZG-2626 OZG-3065 handle validation inline

parent 73dca533
Branches
Tags
No related merge requests found
package de.itvsh.kop.notification.user;
import java.util.List;
import javax.validation.constraints.NotNull;
import java.util.Objects;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated;
......@@ -24,8 +24,12 @@ public class UserNotificationService {
@Autowired
private UserRemoteService userRemoteService;
public void sendNotification(@NotNull String organisationEinheitId) {
var recipients = userRemoteService.getRecipients(organisationEinheitId);
@Async
public void sendNotification(String organisationsEinheitId) {
if (Objects.isNull(organisationsEinheitId)) {
throw new IllegalArgumentException("organisationsEinheitId cannot be null.");
}
var recipients = userRemoteService.getRecipients(organisationsEinheitId);
emailRemoteService.sendEmail(buildUserEmail(recipients));
}
......
package de.itvsh.kop.notification.user;
import static org.assertj.core.api.Assertions.*;
import static org.mockito.ArgumentMatchers.*;
import static org.mockito.Mockito.*;
......@@ -31,9 +32,9 @@ class UserNotificationServiceTest {
@Nested
class TestSendNotification {
@DisplayName("with valid orgaIds")
@DisplayName("with valid orgaId")
@Nested
class TestWithValidOrgaIds {
class TestWithValidOrgaId {
@BeforeEach
void init() {
......@@ -55,5 +56,31 @@ class UserNotificationServiceTest {
verify(emailRemoteService).sendEmail(UserEmailTestFactory.create());
}
}
@DisplayName("with valid orgaId")
@Nested
class TestWithInValidOrgaId {
@Test
void shouldSendEmail() {
assertThatThrownBy(() -> service.sendNotification(null))
.isInstanceOf(IllegalArgumentException.class)
.withFailMessage("organisationsEinheitId cannot be null.");
}
@Test
void shouldNotCallUserRemoteService() {
assertThatThrownBy(() -> service.sendNotification(null));
verify(userRemoteService, never()).getRecipients(anyString());
}
@Test
void shouldNotCallEmailRemoteSErvie() {
assertThatThrownBy(() -> service.sendNotification(null));
verify(emailRemoteService, never()).sendEmail(any(UserEmail.class));
}
}
}
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment