test: add unit and integration tests
This commit is contained in:
@@ -21,5 +21,33 @@
|
||||
<artifactId>slf4j-api</artifactId>
|
||||
<version>2.0.13</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.junit.jupiter</groupId>
|
||||
<artifactId>junit-jupiter</artifactId>
|
||||
<version>5.10.0</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.mockito</groupId>
|
||||
<artifactId>mockito-core</artifactId>
|
||||
<version>5.14.2</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.assertj</groupId>
|
||||
<artifactId>assertj-core</artifactId>
|
||||
<version>3.24.2</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>maven_central</id>
|
||||
<name>Maven Central</name>
|
||||
<url>https://repo.maven.apache.org/maven2/</url>
|
||||
</repository>
|
||||
</repositories>
|
||||
</project>
|
||||
@@ -0,0 +1,62 @@
|
||||
package com.pablotj.restemailbridge.domain.service;
|
||||
|
||||
import com.pablotj.restemailbridge.domain.model.Email;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThatThrownBy;
|
||||
|
||||
class EmailValidatorServiceTest {
|
||||
|
||||
private final EmailValidatorService validator = new EmailValidatorService();
|
||||
|
||||
@Test
|
||||
void shouldThrowIfEmailIsNull() {
|
||||
assertThatThrownBy(() -> validator.validate(null))
|
||||
.isInstanceOf(IllegalArgumentException.class)
|
||||
.hasMessage("Email cannot be null");
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldThrowIfRecipientInvalid() {
|
||||
Email email = Email.create("sender@example.com", "not-an-email", "Subject", "Body");
|
||||
|
||||
assertThatThrownBy(() -> validator.validate(email))
|
||||
.isInstanceOf(IllegalArgumentException.class)
|
||||
.hasMessage("Recipient email is invalid");
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldThrowIfSenderIsBlank() {
|
||||
Email email = Email.create("", "recipient@example.com", "Subject", "Body");
|
||||
|
||||
assertThatThrownBy(() -> validator.validate(email))
|
||||
.isInstanceOf(IllegalArgumentException.class)
|
||||
.hasMessage("Sender email is required");
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldThrowIfSubjectIsBlank() {
|
||||
Email email = Email.create("sender@example.com", "recipient@example.com", "", "Body");
|
||||
|
||||
assertThatThrownBy(() -> validator.validate(email))
|
||||
.isInstanceOf(IllegalArgumentException.class)
|
||||
.hasMessage("Subject is required");
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldThrowIfBodyIsBlank() {
|
||||
Email email = Email.create("sender@example.com", "recipient@example.com", "Subject", "");
|
||||
|
||||
assertThatThrownBy(() -> validator.validate(email))
|
||||
.isInstanceOf(IllegalArgumentException.class)
|
||||
.hasMessage("Body is required");
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldPassForValidEmail() {
|
||||
Email email = Email.create("sender@example.com", "recipient@example.com", "Subject", "Body");
|
||||
|
||||
// no debe lanzar excepción
|
||||
validator.validate(email);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user