email domain tests
This commit is contained in:
@@ -15,8 +15,10 @@ public class EmailFacade implements SendReservationConfirmation {
|
||||
|
||||
@Override
|
||||
public void handle(SendReservationConfirmationCommand sendReservationConfirmation) {
|
||||
String bookTitle = database.getTitleByBookId(sendReservationConfirmation.getBookId());
|
||||
String userEmailAddress = database.getUserEmailAddress(sendReservationConfirmation.getUserId());
|
||||
String bookTitle = database
|
||||
.getTitleByBookId(sendReservationConfirmation.getBookId());
|
||||
String userEmailAddress = database
|
||||
.getUserEmailAddress(sendReservationConfirmation.getUserId());
|
||||
|
||||
Email email = EmailCreator.reservationEmail(
|
||||
sendReservationConfirmation.getReservationId(),
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
package io.wkrzywiec.hexagonal.library.email;
|
||||
|
||||
import io.wkrzywiec.hexagonal.library.TestData;
|
||||
import io.wkrzywiec.hexagonal.library.email.model.SendReservationConfirmationCommand;
|
||||
import io.wkrzywiec.hexagonal.library.email.ports.outgoing.EmailSender;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.DisplayName;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
|
||||
|
||||
public class EmailFacadeTest {
|
||||
|
||||
private EmailFacade facade;
|
||||
private EmailSender emailSender;
|
||||
private InMemoryLibraryDatabase database;
|
||||
|
||||
|
||||
@BeforeEach
|
||||
public void init() {
|
||||
database = new InMemoryLibraryDatabase();
|
||||
emailSender = new EmailSenderFake();
|
||||
facade = new EmailFacade(emailSender, database);
|
||||
|
||||
database.bookTitles.put(1L, TestData.homoDeusBookTitle());
|
||||
database.emailAddresses.put(1L, "john.doe@test.com");
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("Prepare & send reservation confirmation email")
|
||||
public void shouldPrepareAndSendReservationConfirmation(){
|
||||
//given
|
||||
SendReservationConfirmationCommand sendReservationConfirmationCommand
|
||||
= new SendReservationConfirmationCommand(1L, 1L, 1L);
|
||||
|
||||
//when & then
|
||||
assertDoesNotThrow(() -> facade.handle(sendReservationConfirmationCommand));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package io.wkrzywiec.hexagonal.library.email;
|
||||
|
||||
import io.wkrzywiec.hexagonal.library.email.model.Email;
|
||||
import io.wkrzywiec.hexagonal.library.email.ports.outgoing.EmailSender;
|
||||
|
||||
public class EmailSenderFake implements EmailSender {
|
||||
|
||||
@Override
|
||||
public void sendReservationConfirmationEmail(Email email) {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package io.wkrzywiec.hexagonal.library.email;
|
||||
|
||||
import io.wkrzywiec.hexagonal.library.email.ports.outgoing.LibraryDatabase;
|
||||
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
public class InMemoryLibraryDatabase implements LibraryDatabase {
|
||||
|
||||
ConcurrentHashMap<Long, String> bookTitles = new ConcurrentHashMap<>();
|
||||
ConcurrentHashMap<Long, String> emailAddresses = new ConcurrentHashMap<>();
|
||||
|
||||
@Override
|
||||
public String getTitleByBookId(Long bookId) {
|
||||
return bookTitles.get(bookId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getUserEmailAddress(Long userId) {
|
||||
return emailAddresses.get(userId);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user