email address creation tests
This commit is contained in:
@@ -2,8 +2,11 @@ package io.wkrzywiec.hexagonal.library;
|
||||
|
||||
import io.wkrzywiec.hexagonal.library.borrowing.BorrowingFacade;
|
||||
import io.wkrzywiec.hexagonal.library.borrowing.infrastructure.BorrowingDatabaseAdapter;
|
||||
import io.wkrzywiec.hexagonal.library.borrowing.infrastructure.SpringBorrowingEventPublisherAdapter;
|
||||
import io.wkrzywiec.hexagonal.library.borrowing.ports.incoming.MakeBookAvailable;
|
||||
import io.wkrzywiec.hexagonal.library.borrowing.ports.outgoing.BorrowingDatabase;
|
||||
import io.wkrzywiec.hexagonal.library.borrowing.ports.outgoing.BorrowingEventPublisher;
|
||||
import org.springframework.context.ApplicationEventPublisher;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
@@ -17,7 +20,12 @@ public class BorrowingDomainConfig {
|
||||
}
|
||||
|
||||
@Bean
|
||||
public MakeBookAvailable makeBookAvailable(BorrowingDatabase database) {
|
||||
return new BorrowingFacade(database);
|
||||
public BorrowingEventPublisher borrowingEventPublisher(ApplicationEventPublisher applicationEventPublisher){
|
||||
return new SpringBorrowingEventPublisherAdapter(applicationEventPublisher);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public MakeBookAvailable makeBookAvailable(BorrowingDatabase database, BorrowingEventPublisher borrowingEventPublisher) {
|
||||
return new BorrowingFacade(database, borrowingEventPublisher);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,4 +17,8 @@ public class EmailAddress {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public String getAsString() {
|
||||
return value;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
package io.wkrzywiec.hexagonal.library.borrowing;
|
||||
|
||||
import io.wkrzywiec.hexagonal.library.borrowing.model.BookReservedEvent;
|
||||
import io.wkrzywiec.hexagonal.library.borrowing.ports.outgoing.BorrowingEventPublisher;
|
||||
|
||||
public class BorrowingEventPublisherFake implements BorrowingEventPublisher {
|
||||
|
||||
@Override
|
||||
public void publish(BookReservedEvent event) {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -7,6 +7,7 @@ import io.wkrzywiec.hexagonal.library.borrowing.model.MakeBookAvailableCommand;
|
||||
import io.wkrzywiec.hexagonal.library.borrowing.model.exception.ActiveUserNotFoundException;
|
||||
import io.wkrzywiec.hexagonal.library.borrowing.model.exception.AvailableBookNotFoundExeption;
|
||||
import io.wkrzywiec.hexagonal.library.borrowing.model.exception.TooManyBooksAssignedToUserException;
|
||||
import io.wkrzywiec.hexagonal.library.borrowing.ports.outgoing.BorrowingEventPublisher;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.DisplayName;
|
||||
import org.junit.jupiter.api.Test;
|
||||
@@ -19,11 +20,13 @@ public class BorrowingFacadeTest {
|
||||
|
||||
private BorrowingFacade facade;
|
||||
private InMemoryBorrowingDatabase database;
|
||||
private BorrowingEventPublisher eventPublisher;
|
||||
|
||||
@BeforeEach
|
||||
public void init(){
|
||||
database = new InMemoryBorrowingDatabase();
|
||||
facade = new BorrowingFacade(database);
|
||||
eventPublisher = new BorrowingEventPublisherFake();
|
||||
facade = new BorrowingFacade(database, eventPublisher);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
package io.wkrzywiec.hexagonal.library.email.model;
|
||||
|
||||
import org.junit.jupiter.api.DisplayName;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
|
||||
public class EmailAddressTest {
|
||||
|
||||
|
||||
@Test
|
||||
@DisplayName("Create correct EmailAddress")
|
||||
public void givenCorrectEmailString_whenCreateEmailAddress_thenIsCreated(){
|
||||
//given
|
||||
String emailString = "john.doe@test.com";
|
||||
|
||||
//when
|
||||
EmailAddress emailAddress = new EmailAddress(emailString);
|
||||
|
||||
//then
|
||||
assertEquals(emailString, emailAddress.getAsString());
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("Throw IllegalArgument exception for incorrect email")
|
||||
public void givenInCorrectEmailString_whenCreateEmailAddress_thenThrowException(){
|
||||
//given
|
||||
String notAnEmailString = "not an email";
|
||||
String emailWithoutAt = "tom[at]test.com";
|
||||
String emailWithoutDomain = "tom@";
|
||||
|
||||
//when & then
|
||||
assertThrows(
|
||||
IllegalArgumentException.class,
|
||||
() -> new EmailAddress(notAnEmailString));
|
||||
|
||||
assertThrows(
|
||||
IllegalArgumentException.class,
|
||||
() -> new EmailAddress(emailWithoutAt));
|
||||
|
||||
assertThrows(
|
||||
IllegalArgumentException.class,
|
||||
() -> new EmailAddress(emailWithoutDomain));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user