diff --git a/Dockerfile b/Dockerfile
index 39805a10..c02ba431 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -1,4 +1,4 @@
-FROM adoptopenjdk/openjdk11:x86_64-alpine-jdk-11.0.8_10
+FROM adoptopenjdk/openjdk11:x86_64-alpine-jdk-11.0.9_11
VOLUME /tmp
diff --git a/build.gradle b/build.gradle
index d49da862..c6467b5a 100644
--- a/build.gradle
+++ b/build.gradle
@@ -1,6 +1,6 @@
plugins {
id "com.cinnober.gradle.semver-git" version "3.0.0"
- id 'org.springframework.boot' version '2.3.4.RELEASE'
+ id 'org.springframework.boot' version '2.4.0'
id "org.sonarqube" version "3.0"
}
@@ -45,6 +45,10 @@ dependencies {
testImplementation('org.hamcrest:hamcrest-core:2.2')
}
+springBoot {
+ buildInfo()
+}
+
sonarqube {
properties {
property "sonar.projectName", "Fake SMTP Server"
diff --git a/src/main/java/de/gessnerfl/fakesmtp/controller/EmailController.java b/src/main/java/de/gessnerfl/fakesmtp/controller/EmailController.java
index 47118acf..f919f904 100644
--- a/src/main/java/de/gessnerfl/fakesmtp/controller/EmailController.java
+++ b/src/main/java/de/gessnerfl/fakesmtp/controller/EmailController.java
@@ -3,6 +3,7 @@
import de.gessnerfl.fakesmtp.model.Email;
import de.gessnerfl.fakesmtp.repository.EmailRepository;
import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.info.BuildProperties;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Sort;
import org.springframework.stereotype.Controller;
@@ -16,6 +17,7 @@
public class EmailController {
private static final Sort DEFAULT_SORT = Sort.by(Sort.Direction.DESC, "receivedOn");
private static final int DEFAULT_PAGE_SIZE = 10;
+ static final String APP_VERSION_MODEL_NAME = "appVersion";
static final String EMAIL_LIST_VIEW = "email-list";
static final String EMAIL_LIST_MODEL_NAME = "mails";
static final String SINGLE_EMAIL_VIEW = "email";
@@ -23,10 +25,12 @@ public class EmailController {
static final String REDIRECT_EMAIL_LIST_VIEW = "redirect:/email";
private final EmailRepository emailRepository;
+ private final BuildProperties buildProperties;
@Autowired
- public EmailController(EmailRepository emailRepository) {
+ public EmailController(EmailRepository emailRepository, BuildProperties buildProperties) {
this.emailRepository = emailRepository;
+ this.buildProperties = buildProperties;
}
@GetMapping({"/", "/email"})
@@ -43,6 +47,7 @@ private String getAllEmailsPaged(int page, int size, Model model) {
return REDIRECT_EMAIL_LIST_VIEW;
}
model.addAttribute(EMAIL_LIST_MODEL_NAME, result);
+ addApplicationVersion(model);
return EMAIL_LIST_VIEW;
}
@@ -53,6 +58,7 @@ public String getEmailById(@PathVariable Long id, Model model) {
private String appendToModelAndReturnView(Model model, Email email) {
model.addAttribute(SINGLE_EMAIL_MODEL_NAME, email);
+ addApplicationVersion(model);
return SINGLE_EMAIL_VIEW;
}
@@ -63,4 +69,8 @@ public String deleteEmailById(@PathVariable Long id) {
return REDIRECT_EMAIL_LIST_VIEW;
}
+ private void addApplicationVersion(Model model){
+ model.addAttribute(APP_VERSION_MODEL_NAME, buildProperties.getVersion());
+ }
+
}
diff --git a/src/main/resources/templates/fragments/navbar.html b/src/main/resources/templates/fragments/navbar.html
index 89bda1b4..553dc4ce 100644
--- a/src/main/resources/templates/fragments/navbar.html
+++ b/src/main/resources/templates/fragments/navbar.html
@@ -5,9 +5,12 @@
diff --git a/src/test/java/de/gessnerfl/fakesmtp/TestResourceUtil.java b/src/test/java/de/gessnerfl/fakesmtp/TestResourceUtil.java
index bffd2f58..14e43ac6 100644
--- a/src/test/java/de/gessnerfl/fakesmtp/TestResourceUtil.java
+++ b/src/test/java/de/gessnerfl/fakesmtp/TestResourceUtil.java
@@ -6,7 +6,7 @@
import java.io.InputStream;
import java.nio.charset.StandardCharsets;
-import static org.junit.Assert.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
public class TestResourceUtil {
private static final String TEST_DATA_FOLDER = "/test-data/";
diff --git a/src/test/java/de/gessnerfl/fakesmtp/config/FakeSmtpConfigurationPropertiesIntegrationTest.java b/src/test/java/de/gessnerfl/fakesmtp/config/FakeSmtpConfigurationPropertiesIntegrationTest.java
index 67f9b67b..7565aa1f 100644
--- a/src/test/java/de/gessnerfl/fakesmtp/config/FakeSmtpConfigurationPropertiesIntegrationTest.java
+++ b/src/test/java/de/gessnerfl/fakesmtp/config/FakeSmtpConfigurationPropertiesIntegrationTest.java
@@ -1,26 +1,26 @@
package de.gessnerfl.fakesmtp.config;
-import org.junit.Test;
-import org.junit.runner.RunWith;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.ActiveProfiles;
-import org.springframework.test.context.junit4.SpringRunner;
+import org.springframework.test.context.junit.jupiter.SpringExtension;
import java.net.InetAddress;
-import static org.junit.Assert.*;
+import static org.junit.jupiter.api.Assertions.*;
@ActiveProfiles({"integrationtest","config_integrationtest"})
-@RunWith(SpringRunner.class)
+@ExtendWith(SpringExtension.class)
@SpringBootTest
-public class FakeSmtpConfigurationPropertiesIntegrationTest {
+class FakeSmtpConfigurationPropertiesIntegrationTest {
@Autowired
private FakeSmtpConfigurationProperties sut;
@Test
- public void shouldLoadConfigurationParameters() throws Exception {
+ void shouldLoadConfigurationParameters() throws Exception {
assertEquals(1234, sut.getPort().intValue());
assertEquals(InetAddress.getByName("127.0.0.1"), sut.getBindAddress());
assertNull(sut.getAuthentication());
diff --git a/src/test/java/de/gessnerfl/fakesmtp/config/FakeSmtpConfigurationPropertiesWithAuthenticationIntegrationTest.java b/src/test/java/de/gessnerfl/fakesmtp/config/FakeSmtpConfigurationPropertiesWithAuthenticationIntegrationTest.java
index 371bfc40..de72db4b 100644
--- a/src/test/java/de/gessnerfl/fakesmtp/config/FakeSmtpConfigurationPropertiesWithAuthenticationIntegrationTest.java
+++ b/src/test/java/de/gessnerfl/fakesmtp/config/FakeSmtpConfigurationPropertiesWithAuthenticationIntegrationTest.java
@@ -1,34 +1,31 @@
package de.gessnerfl.fakesmtp.config;
-import org.junit.Test;
-import org.junit.runner.RunWith;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.ActiveProfiles;
-import org.springframework.test.context.junit4.SpringRunner;
+import org.springframework.test.context.junit.jupiter.SpringExtension;
import java.net.InetAddress;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-
@ActiveProfiles({"integrationtest", "config_with_auth_integrationtest"})
-@RunWith(SpringRunner.class)
+@ExtendWith(SpringExtension.class)
@SpringBootTest
-public class FakeSmtpConfigurationPropertiesWithAuthenticationIntegrationTest {
+class FakeSmtpConfigurationPropertiesWithAuthenticationIntegrationTest {
@Autowired
private FakeSmtpConfigurationProperties sut;
@Test
- public void shouldLoadConfigurationParameters() throws Exception {
- assertEquals(1234, sut.getPort().intValue());
- assertEquals(InetAddress.getByName("127.0.0.1"), sut.getBindAddress());
- assertNotNull(sut.getAuthentication());
- assertEquals("user", sut.getAuthentication().getUsername());
- assertEquals("password", sut.getAuthentication().getPassword());
- assertNotNull(sut.getPersistence());
- assertEquals(FakeSmtpConfigurationProperties.Persistence.DEFAULT_MAX_NUMBER_EMAILS, sut.getPersistence().getMaxNumberEmails().intValue());
+ void shouldLoadConfigurationParameters() throws Exception {
+ Assertions.assertEquals(1234, sut.getPort().intValue());
+ Assertions.assertEquals(InetAddress.getByName("127.0.0.1"), sut.getBindAddress());
+ Assertions.assertNotNull(sut.getAuthentication());
+ Assertions.assertEquals("user", sut.getAuthentication().getUsername());
+ Assertions.assertEquals("password", sut.getAuthentication().getPassword());
+ Assertions.assertNotNull(sut.getPersistence());
+ Assertions.assertEquals(FakeSmtpConfigurationProperties.Persistence.DEFAULT_MAX_NUMBER_EMAILS, sut.getPersistence().getMaxNumberEmails().intValue());
}
}
\ No newline at end of file
diff --git a/src/test/java/de/gessnerfl/fakesmtp/config/FakeSmtpConfigurationPropertiesWithPersistenceIntegrationTest.java b/src/test/java/de/gessnerfl/fakesmtp/config/FakeSmtpConfigurationPropertiesWithPersistenceIntegrationTest.java
index 36dcc48b..5f6a0839 100644
--- a/src/test/java/de/gessnerfl/fakesmtp/config/FakeSmtpConfigurationPropertiesWithPersistenceIntegrationTest.java
+++ b/src/test/java/de/gessnerfl/fakesmtp/config/FakeSmtpConfigurationPropertiesWithPersistenceIntegrationTest.java
@@ -1,32 +1,29 @@
package de.gessnerfl.fakesmtp.config;
-import org.junit.Test;
-import org.junit.runner.RunWith;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.ActiveProfiles;
-import org.springframework.test.context.junit4.SpringRunner;
+import org.springframework.test.context.junit.jupiter.SpringExtension;
import java.net.InetAddress;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-
@ActiveProfiles({"integrationtest","config_with_persistence_integrationtest"})
-@RunWith(SpringRunner.class)
+@ExtendWith(SpringExtension.class)
@SpringBootTest
-public class FakeSmtpConfigurationPropertiesWithPersistenceIntegrationTest {
+class FakeSmtpConfigurationPropertiesWithPersistenceIntegrationTest {
@Autowired
private FakeSmtpConfigurationProperties sut;
@Test
- public void shouldLoadConfigurationParameters() throws Exception {
- assertEquals(1234, sut.getPort().intValue());
- assertEquals(InetAddress.getByName("127.0.0.1"), sut.getBindAddress());
- assertNull(sut.getAuthentication());
- assertNotNull(sut.getPersistence());
- assertEquals(5, sut.getPersistence().getMaxNumberEmails().intValue());
+ void shouldLoadConfigurationParameters() throws Exception {
+ Assertions.assertEquals(1234, sut.getPort().intValue());
+ Assertions.assertEquals(InetAddress.getByName("127.0.0.1"), sut.getBindAddress());
+ Assertions.assertNull(sut.getAuthentication());
+ Assertions.assertNotNull(sut.getPersistence());
+ Assertions.assertEquals(5, sut.getPersistence().getMaxNumberEmails().intValue());
}
}
\ No newline at end of file
diff --git a/src/test/java/de/gessnerfl/fakesmtp/controller/EmailControllerMVCIntegrationTest.java b/src/test/java/de/gessnerfl/fakesmtp/controller/EmailControllerMVCIntegrationTest.java
index 05651481..15bf0ee8 100644
--- a/src/test/java/de/gessnerfl/fakesmtp/controller/EmailControllerMVCIntegrationTest.java
+++ b/src/test/java/de/gessnerfl/fakesmtp/controller/EmailControllerMVCIntegrationTest.java
@@ -1,60 +1,50 @@
package de.gessnerfl.fakesmtp.controller;
-import de.gessnerfl.fakesmtp.model.ContentType;
import de.gessnerfl.fakesmtp.model.Email;
-import de.gessnerfl.fakesmtp.model.EmailAttachment;
-import de.gessnerfl.fakesmtp.model.EmailContent;
import de.gessnerfl.fakesmtp.repository.EmailRepository;
-import org.apache.commons.lang3.RandomStringUtils;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
import org.springframework.boot.test.context.SpringBootTest;
-import org.springframework.http.HttpHeaders;
-import org.springframework.http.MediaType;
import org.springframework.test.context.ActiveProfiles;
-import org.springframework.test.context.junit4.SpringRunner;
+import org.springframework.test.context.junit.jupiter.SpringExtension;
import org.springframework.test.web.servlet.MockMvc;
-import java.nio.charset.StandardCharsets;
-import java.time.LocalDateTime;
-import java.time.ZoneOffset;
-import java.util.Date;
-
+import static org.hamcrest.MatcherAssert.*;
import static org.hamcrest.Matchers.*;
-import static org.junit.Assert.*;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.delete;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;
@ActiveProfiles("integrationtest")
-@RunWith(SpringRunner.class)
+@ExtendWith(SpringExtension.class)
@SpringBootTest
@AutoConfigureMockMvc
-public class EmailControllerMVCIntegrationTest {
+class EmailControllerMVCIntegrationTest {
@Autowired
private EmailRepository emailRepository;
@Autowired
private MockMvc mockMvc;
- @Before
- public void init(){
+ @BeforeEach
+ void init(){
emailRepository.deleteAll();
}
@Test
- public void shouldReturnEmptyListWhenNoEmailsAreAvailable() throws Exception {
+ void shouldReturnEmptyListWhenNoEmailsAreAvailable() throws Exception {
this.mockMvc.perform(get("/email?page"))
.andExpect(status().isOk())
.andExpect(model().attribute("mails", emptyIterableOf(Email.class)))
+ .andExpect(model().attribute("appVersion", any(String.class)))
.andExpect(view().name("email-list"));
}
@Test
- public void shouldReturnListOfEmailsPagedWhenEmailsAreAvailable() throws Exception {
+ void shouldReturnListOfEmailsPagedWhenEmailsAreAvailable() throws Exception {
var email1 = createRandomEmail(5);
var email2 = createRandomEmail(2);
var email3 = createRandomEmail(1);
@@ -63,17 +53,19 @@ public void shouldReturnListOfEmailsPagedWhenEmailsAreAvailable() throws Excepti
.andExpect(status().isOk())
.andExpect(model().attribute("mails", iterableWithSize(2)))
.andExpect(model().attribute("mails", contains(equalTo(email3), equalTo(email2))))
+ .andExpect(model().attribute("appVersion", any(String.class)))
.andExpect(view().name("email-list"));
this.mockMvc.perform(get("/email?page=1&size=2"))
.andExpect(status().isOk())
.andExpect(model().attribute("mails", iterableWithSize(1)))
.andExpect(model().attribute("mails", contains(equalTo(email1))))
+ .andExpect(model().attribute("appVersion", any(String.class)))
.andExpect(view().name("email-list"));
}
@Test
- public void shouldReturnFirstPageWhenGivenPageIsOutOfRange() throws Exception {
+ void shouldReturnFirstPageWhenGivenPageIsOutOfRange() throws Exception {
createRandomEmail(1);
this.mockMvc.perform(get("/email?page=1&size=2"))
@@ -83,17 +75,18 @@ public void shouldReturnFirstPageWhenGivenPageIsOutOfRange() throws Exception {
}
@Test
- public void shouldReturnMailById() throws Exception {
+ void shouldReturnMailById() throws Exception {
var email = createRandomEmail(1);
this.mockMvc.perform(get("/email/"+email.getId()))
.andExpect(status().isOk())
.andExpect(model().attribute("mail", equalTo(email)))
+ .andExpect(model().attribute("appVersion", any(String.class)))
.andExpect(view().name("email"));
}
@Test
- public void shouldReturnErrorWhenMailIdIsNotValid() throws Exception {
+ void shouldReturnErrorWhenMailIdIsNotValid() throws Exception {
this.mockMvc.perform(get("/email/123"))
.andExpect(redirectedUrl("/email"))
.andExpect(model().attributeDoesNotExist("mails", "mail"))
@@ -101,7 +94,7 @@ public void shouldReturnErrorWhenMailIdIsNotValid() throws Exception {
}
@Test
- public void shouldDeleteEmail() throws Exception {
+ void shouldDeleteEmail() throws Exception {
var email = createRandomEmail(1);
this.mockMvc.perform(delete("/email/"+email.getId()))
diff --git a/src/test/java/de/gessnerfl/fakesmtp/controller/EmailControllerTest.java b/src/test/java/de/gessnerfl/fakesmtp/controller/EmailControllerTest.java
index 875f443a..37635960 100644
--- a/src/test/java/de/gessnerfl/fakesmtp/controller/EmailControllerTest.java
+++ b/src/test/java/de/gessnerfl/fakesmtp/controller/EmailControllerTest.java
@@ -2,46 +2,53 @@
import de.gessnerfl.fakesmtp.model.Email;
import de.gessnerfl.fakesmtp.repository.EmailRepository;
-import org.junit.Test;
-import org.junit.runner.RunWith;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.ArgumentMatcher;
import org.mockito.InjectMocks;
import org.mockito.Mock;
-import org.mockito.junit.MockitoJUnitRunner;
+import org.mockito.junit.jupiter.MockitoExtension;
+import org.springframework.boot.info.BuildProperties;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.ui.Model;
import java.util.Optional;
-import static org.junit.Assert.assertEquals;
import static org.mockito.Mockito.*;
-@RunWith(MockitoJUnitRunner.class)
-public class EmailControllerTest {
+@ExtendWith(MockitoExtension.class)
+class EmailControllerTest {
@Mock
private Model model;
@Mock
private EmailRepository emailRepository;
+ @Mock
+ private BuildProperties buildProperties;
@InjectMocks
private EmailController sut;
@Test
- public void shouldReturnEmailsPaged() {
+ void shouldReturnEmailsPaged() {
+ final String appVersion = "appVersion";
final Page page = createFirstPageEmail();
when(emailRepository.findAll(any(Pageable.class))).thenReturn(page);
+ when(buildProperties.getVersion()).thenReturn(appVersion);
var result = sut.getAll(0, 5, model);
- assertEquals(EmailController.EMAIL_LIST_VIEW, result);
+ Assertions.assertEquals(EmailController.EMAIL_LIST_VIEW, result);
verify(emailRepository).findAll(argThat(matchPageable(0, 5)));
- verifyNoMoreInteractions(emailRepository);
verify(model).addAttribute(EmailController.EMAIL_LIST_MODEL_NAME, page);
+ verify(buildProperties).getVersion();
+ verify(model).addAttribute(EmailController.APP_VERSION_MODEL_NAME, appVersion);
+ verifyNoMoreInteractions(emailRepository, buildProperties, model);
}
@Test
- public void shouldReturnRedirectToFirstPageWhenRequestedPageIsOutOfRange() {
+ void shouldReturnRedirectToFirstPageWhenRequestedPageIsOutOfRange() {
var page = mock(Page.class);
when(page.getTotalPages()).thenReturn(2);
when(page.getNumber()).thenReturn(3);
@@ -49,74 +56,86 @@ public void shouldReturnRedirectToFirstPageWhenRequestedPageIsOutOfRange() {
var result = sut.getAll(3, 5, model);
- assertEquals(EmailController.REDIRECT_EMAIL_LIST_VIEW, result);
+ Assertions.assertEquals(EmailController.REDIRECT_EMAIL_LIST_VIEW, result);
verify(emailRepository).findAll(argThat(matchPageable(3, 5)));
- verifyNoMoreInteractions(emailRepository);
+ verifyNoMoreInteractions(emailRepository, buildProperties, model);
}
@Test
- public void shouldNotRedirectToFirstPageWhenNoDataIsAvailable() {
+ void shouldNotRedirectToFirstPageWhenNoDataIsAvailable() {
+ final String appVersion = "appVersion";
var page = mock(Page.class);
when(page.getNumber()).thenReturn(0);
when(emailRepository.findAll(any(Pageable.class))).thenReturn(page);
+ when(buildProperties.getVersion()).thenReturn(appVersion);
var result = sut.getAll(0, 5, model);
- assertEquals(EmailController.EMAIL_LIST_VIEW, result);
+ Assertions.assertEquals(EmailController.EMAIL_LIST_VIEW, result);
verify(emailRepository).findAll(argThat(matchPageable(0, 5)));
- verifyNoMoreInteractions(emailRepository);
+ verify(model).addAttribute(EmailController.EMAIL_LIST_MODEL_NAME, page);
+ verify(buildProperties).getVersion();
+ verify(model).addAttribute(EmailController.APP_VERSION_MODEL_NAME, appVersion);
+ verifyNoMoreInteractions(emailRepository, emailRepository, model);
}
@Test
- public void shouldRedirectToFirstPageWhenPageNumberIsBelowNull() {
+ void shouldRedirectToFirstPageWhenPageNumberIsBelowNull() {
var result = sut.getAll(-1, 5, model);
- assertEquals(EmailController.REDIRECT_EMAIL_LIST_VIEW, result);
- verifyNoInteractions(emailRepository);
+ Assertions.assertEquals(EmailController.REDIRECT_EMAIL_LIST_VIEW, result);
+ verifyNoInteractions(emailRepository, buildProperties, model);
}
@Test
- public void shouldRedirectToFirstPageWhenPageSizeIsNull() {
+ void shouldRedirectToFirstPageWhenPageSizeIsNull() {
String result = sut.getAll(0, 0, model);
- assertEquals(EmailController.REDIRECT_EMAIL_LIST_VIEW, result);
- verifyNoInteractions(emailRepository);
+ Assertions.assertEquals(EmailController.REDIRECT_EMAIL_LIST_VIEW, result);
+ verifyNoInteractions(emailRepository, buildProperties, model);
}
@Test
- public void shouldRedirectToFirstPageWhenPageSizeIsBelowNull() {
+ void shouldRedirectToFirstPageWhenPageSizeIsBelowNull() {
var result = sut.getAll(0, -1, model);
- assertEquals(EmailController.REDIRECT_EMAIL_LIST_VIEW, result);
- verifyNoInteractions(emailRepository);
+ Assertions.assertEquals(EmailController.REDIRECT_EMAIL_LIST_VIEW, result);
+ verifyNoInteractions(emailRepository, buildProperties, model);
}
@Test
- public void shouldReturnSingleEmailWhenIdIsValid() {
+ void shouldReturnSingleEmailWhenIdIsValid() {
+ final String appVersion = "appVersion";
var id = 12L;
var mail = mock(Email.class);
when(emailRepository.findById(id)).thenReturn(Optional.of(mail));
+ when(buildProperties.getVersion()).thenReturn(appVersion);
var result = sut.getEmailById(id, model);
- assertEquals(EmailController.SINGLE_EMAIL_VIEW, result);
+ Assertions.assertEquals(EmailController.SINGLE_EMAIL_VIEW, result);
verify(emailRepository).findById(id);
verify(model).addAttribute(EmailController.SINGLE_EMAIL_MODEL_NAME, mail);
+ verify(buildProperties).getVersion();
+ verify(model).addAttribute(EmailController.APP_VERSION_MODEL_NAME, appVersion);
+ verifyNoMoreInteractions(emailRepository, buildProperties, model);
}
@Test
- public void shouldReturnRedirectToListPageWhenIdIsNotValid() {
+ void shouldReturnRedirectToListPageWhenIdIsNotValid() {
var id = 12L;
when(emailRepository.findById(id)).thenReturn(Optional.empty());
var result = sut.getEmailById(id, model);
- assertEquals(EmailController.REDIRECT_EMAIL_LIST_VIEW, result);
+ Assertions.assertEquals(EmailController.REDIRECT_EMAIL_LIST_VIEW, result);
verify(emailRepository).findById(id);
+ verifyNoMoreInteractions(emailRepository);
+ verifyNoInteractions(buildProperties, model);
}
private Page createFirstPageEmail() {
@@ -131,12 +150,14 @@ private ArgumentMatcher matchPageable(int page, int size) {
}
@Test
- public void shouldDeleteEmailByItsIdAndFlushChangesSoThatDeleteIsApplied(){
+ void shouldDeleteEmailByItsIdAndFlushChangesSoThatDeleteIsApplied(){
var emailId = 123L;
sut.deleteEmailById(emailId);
verify(emailRepository).deleteById(emailId);
verify(emailRepository).flush();
+ verifyNoMoreInteractions(emailRepository);
+ verifyNoInteractions(buildProperties);
}
}
\ No newline at end of file
diff --git a/src/test/java/de/gessnerfl/fakesmtp/controller/EmailRestControllerMVCIntegrationTest.java b/src/test/java/de/gessnerfl/fakesmtp/controller/EmailRestControllerMVCIntegrationTest.java
index 4873a50d..ba9a188b 100644
--- a/src/test/java/de/gessnerfl/fakesmtp/controller/EmailRestControllerMVCIntegrationTest.java
+++ b/src/test/java/de/gessnerfl/fakesmtp/controller/EmailRestControllerMVCIntegrationTest.java
@@ -1,44 +1,36 @@
package de.gessnerfl.fakesmtp.controller;
-import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
-import de.gessnerfl.fakesmtp.model.ContentType;
import de.gessnerfl.fakesmtp.model.Email;
-import de.gessnerfl.fakesmtp.model.EmailAttachment;
-import de.gessnerfl.fakesmtp.model.EmailContent;
import de.gessnerfl.fakesmtp.repository.EmailRepository;
-import org.apache.commons.lang3.RandomStringUtils;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.test.context.ActiveProfiles;
-import org.springframework.test.context.junit4.SpringRunner;
+import org.springframework.test.context.junit.jupiter.SpringExtension;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.MvcResult;
import java.io.IOException;
-import java.nio.charset.StandardCharsets;
-import java.time.LocalDateTime;
-import java.time.ZoneOffset;
-import java.util.Date;
import java.util.List;
+import static org.hamcrest.MatcherAssert.*;
import static org.hamcrest.Matchers.*;
-import static org.junit.Assert.*;
+import static org.junit.jupiter.api.Assertions.*;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.delete;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;
@ActiveProfiles("integrationtest")
-@RunWith(SpringRunner.class)
+@ExtendWith(SpringExtension.class)
@SpringBootTest
@AutoConfigureMockMvc
-public class EmailRestControllerMVCIntegrationTest {
+class EmailRestControllerMVCIntegrationTest {
@Autowired
private EmailRepository emailRepository;
@@ -46,13 +38,13 @@ public class EmailRestControllerMVCIntegrationTest {
@Autowired
private MockMvc mockMvc;
- @Before
- public void init(){
+ @BeforeEach
+ void init(){
emailRepository.deleteAll();
}
@Test
- public void shouldReturnEmptyListWhenNoEmailsAreAvailable() throws Exception {
+ void shouldReturnEmptyListWhenNoEmailsAreAvailable() throws Exception {
MvcResult mvcResult = mockMvc.perform(get("/api/email")).andReturn();
assertEquals(200, mvcResult.getResponse().getStatus());
@@ -61,7 +53,7 @@ public void shouldReturnEmptyListWhenNoEmailsAreAvailable() throws Exception {
}
@Test
- public void shouldReturnFirstPageOfEmails() throws Exception {
+ void shouldReturnFirstPageOfEmails() throws Exception {
var email1 = createRandomEmail(5);
var email2 = createRandomEmail(2);
var email3 = createRandomEmail(1);
@@ -74,7 +66,7 @@ public void shouldReturnFirstPageOfEmails() throws Exception {
}
@Test
- public void shouldReturnSecondPageOfEmails() throws Exception {
+ void shouldReturnSecondPageOfEmails() throws Exception {
var email1 = createRandomEmail(5);
var email2 = createRandomEmail(2);
var email3 = createRandomEmail(1);
@@ -87,7 +79,7 @@ public void shouldReturnSecondPageOfEmails() throws Exception {
}
@Test
- public void shouldReturnNoEmailsWhenGivenPageIsOutOfRange() throws Exception {
+ void shouldReturnNoEmailsWhenGivenPageIsOutOfRange() throws Exception {
var email1 = createRandomEmail(5);
MvcResult mvcResult = this.mockMvc.perform(get("/api/email?page=2&size=1")).andReturn();
@@ -98,7 +90,7 @@ public void shouldReturnNoEmailsWhenGivenPageIsOutOfRange() throws Exception {
}
@Test
- public void shouldReturnMailById() throws Exception {
+ void shouldReturnMailById() throws Exception {
var email = createRandomEmail(1);
MvcResult mvcResult = this.mockMvc.perform(get("/api/email/"+email.getId())).andReturn();
@@ -109,13 +101,13 @@ public void shouldReturnMailById() throws Exception {
}
@Test
- public void shouldReturnNotFoundCodeWhenMailIdIsNotValid() throws Exception {
+ void shouldReturnNotFoundCodeWhenMailIdIsNotValid() throws Exception {
this.mockMvc.perform(get("/api/email/123"))
.andExpect(status().isNotFound());
}
@Test
- public void shouldReturnAttachmentForEmail() throws Exception {
+ void shouldReturnAttachmentForEmail() throws Exception {
var email = createRandomEmail(1);
var attachment = email.getAttachments().get(0);
@@ -128,7 +120,7 @@ public void shouldReturnAttachmentForEmail() throws Exception {
}
@Test
- public void shouldReturnErrorWhenAttachmentIsRequestedButAttachmentIdIsNotValid() throws Exception {
+ void shouldReturnErrorWhenAttachmentIsRequestedButAttachmentIdIsNotValid() throws Exception {
var email = createRandomEmail(1);
this.mockMvc.perform(get("/api/email/"+email.getId()+"/attachment/123"))
@@ -136,7 +128,7 @@ public void shouldReturnErrorWhenAttachmentIsRequestedButAttachmentIdIsNotValid(
}
@Test
- public void shouldReturnErrorWhenAttachmentIsRequestedButMailIdIsNotValid() throws Exception {
+ void shouldReturnErrorWhenAttachmentIsRequestedButMailIdIsNotValid() throws Exception {
var email = createRandomEmail(1);
this.mockMvc.perform(get("/api/email/123/attachment/"+email.getAttachments().get(0).getId()))
@@ -144,7 +136,7 @@ public void shouldReturnErrorWhenAttachmentIsRequestedButMailIdIsNotValid() thro
}
@Test
- public void shouldDeleteEmail() throws Exception {
+ void shouldDeleteEmail() throws Exception {
var email = createRandomEmail(1);
this.mockMvc.perform(delete("/api/email/"+email.getId()))
diff --git a/src/test/java/de/gessnerfl/fakesmtp/controller/EmailRestControllerTest.java b/src/test/java/de/gessnerfl/fakesmtp/controller/EmailRestControllerTest.java
index 5d520402..81ca97fa 100644
--- a/src/test/java/de/gessnerfl/fakesmtp/controller/EmailRestControllerTest.java
+++ b/src/test/java/de/gessnerfl/fakesmtp/controller/EmailRestControllerTest.java
@@ -5,12 +5,12 @@
import de.gessnerfl.fakesmtp.repository.EmailAttachmentRepository;
import de.gessnerfl.fakesmtp.repository.EmailRepository;
import de.gessnerfl.fakesmtp.util.MediaTypeUtil;
-import org.junit.Test;
-import org.junit.runner.RunWith;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.ArgumentMatcher;
import org.mockito.InjectMocks;
import org.mockito.Mock;
-import org.mockito.junit.MockitoJUnitRunner;
+import org.mockito.junit.jupiter.MockitoExtension;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
@@ -22,12 +22,11 @@
import java.nio.charset.StandardCharsets;
import java.util.Optional;
-import static org.junit.Assert.assertArrayEquals;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.*;
import static org.mockito.Mockito.*;
-@RunWith(MockitoJUnitRunner.class)
-public class EmailRestControllerTest {
+@ExtendWith(MockitoExtension.class)
+class EmailRestControllerTest {
@Mock
private EmailRepository emailRepository;
@Mock
@@ -41,7 +40,7 @@ public class EmailRestControllerTest {
private EmailRestController sut;
@Test
- public void shouldReturnListOfEmails() {
+ void shouldReturnListOfEmails() {
final Page page = createFirstPageEmail();
when(emailRepository.findAll(any(Pageable.class))).thenReturn(page);
@@ -53,7 +52,7 @@ public void shouldReturnListOfEmails() {
}
@Test
- public void shouldReturnSingleEmailWhenIdIsValid() {
+ void shouldReturnSingleEmailWhenIdIsValid() {
var id = 12L;
var mail = mock(Email.class);
when(emailRepository.findById(id)).thenReturn(Optional.of(mail));
@@ -75,7 +74,7 @@ private ArgumentMatcher matchPageable(int page, int size) {
}
@Test
- public void shouldReturnResponseEntityForAttachment() {
+ void shouldReturnResponseEntityForAttachment() {
var fileContent = "this is the file content".getBytes(StandardCharsets.UTF_8);
var filename = "myfile.txt";
var emailId = 123L;
@@ -100,8 +99,8 @@ public void shouldReturnResponseEntityForAttachment() {
assertArrayEquals(fileContent, result.getBody().getByteArray());
}
- @Test(expected = AttachmentNotFoundException.class)
- public void shouldThrowExceptionWhenNoAttachmentExistsForTheGivenId() {
+ @Test
+ void shouldThrowExceptionWhenNoAttachmentExistsForTheGivenId() {
var emailId = 123L;
var attachmentId = 456L;
var email = mock(Email.class);
@@ -111,21 +110,25 @@ public void shouldThrowExceptionWhenNoAttachmentExistsForTheGivenId() {
when(attachment.getEmail()).thenReturn(email);
when(emailAttachmentRepository.findById(attachmentId)).thenReturn(Optional.of(attachment));
- sut.getEmailAttachmentById(emailId, attachmentId);
+ assertThrows(AttachmentNotFoundException.class, () -> {
+ sut.getEmailAttachmentById(emailId, attachmentId);
+ });
}
- @Test(expected = AttachmentNotFoundException.class)
- public void shouldThrowExceptionWhenAttachmentExistsForTheGivenIdButTheEmailIdDoesNotMatch() {
+ @Test
+ void shouldThrowExceptionWhenAttachmentExistsForTheGivenIdButTheEmailIdDoesNotMatch() {
var emailId = 123L;
var attachmentId = 456L;
when(emailAttachmentRepository.findById(attachmentId)).thenReturn(Optional.empty());
- sut.getEmailAttachmentById(emailId, attachmentId);
+ assertThrows(AttachmentNotFoundException.class, () -> {
+ sut.getEmailAttachmentById(emailId, attachmentId);
+ });
}
@Test
- public void shouldDeleteEmailByItsIdAndFlushChangesSoThatDeleteIsApplied() {
+ void shouldDeleteEmailByItsIdAndFlushChangesSoThatDeleteIsApplied() {
var emailId = 123L;
sut.deleteEmailById(emailId);
diff --git a/src/test/java/de/gessnerfl/fakesmtp/repository/EmailRepositoryIntegrationTest.java b/src/test/java/de/gessnerfl/fakesmtp/repository/EmailRepositoryIntegrationTest.java
index 199ceb07..0e331833 100644
--- a/src/test/java/de/gessnerfl/fakesmtp/repository/EmailRepositoryIntegrationTest.java
+++ b/src/test/java/de/gessnerfl/fakesmtp/repository/EmailRepositoryIntegrationTest.java
@@ -4,41 +4,42 @@
import de.gessnerfl.fakesmtp.model.Email;
import de.gessnerfl.fakesmtp.model.EmailContent;
import org.apache.commons.lang3.RandomStringUtils;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.data.domain.Sort;
import org.springframework.test.context.ActiveProfiles;
-import org.springframework.test.context.junit4.SpringRunner;
+import org.springframework.test.context.junit.jupiter.SpringExtension;
import javax.transaction.Transactional;
import java.time.LocalDateTime;
import java.time.ZoneOffset;
import java.util.Date;
+import static org.hamcrest.MatcherAssert.*;
import static org.hamcrest.Matchers.contains;
import static org.hamcrest.Matchers.hasSize;
-import static org.junit.Assert.*;
+import static org.junit.jupiter.api.Assertions.*;
@Transactional
@ActiveProfiles("integrationtest")
-@RunWith(SpringRunner.class)
+@ExtendWith(SpringExtension.class)
@SpringBootTest
-public class EmailRepositoryIntegrationTest {
+class EmailRepositoryIntegrationTest {
private static final Sort SORT_DESC_BY_RECEIVED_ON = Sort.by(Sort.Direction.DESC, "receivedOn");
@Autowired
private EmailRepository sut;
- @Before
- public void init(){
+ @BeforeEach
+ void init(){
sut.deleteAll();
}
@Test
- public void shouldDeleteEmailsWhichExceedTheRetentionLimitOfMaximumNumberOfEmails(){
+ void shouldDeleteEmailsWhichExceedTheRetentionLimitOfMaximumNumberOfEmails(){
var mail1 = createRandomEmail(5);
var mail2 = createRandomEmail(4);
var mail3 = createRandomEmail(3);
@@ -58,7 +59,7 @@ public void shouldDeleteEmailsWhichExceedTheRetentionLimitOfMaximumNumberOfEmail
}
@Test
- public void shouldNotDeleteAnyEmailWhenTheNumberOfEmailsDoesNotExceedTheRetentionLimitOfMaximumNumberOfEmails(){
+ void shouldNotDeleteAnyEmailWhenTheNumberOfEmailsDoesNotExceedTheRetentionLimitOfMaximumNumberOfEmails(){
var mail1 = createRandomEmail(5);
var mail2 = createRandomEmail(4);
var mail3 = createRandomEmail(3);
diff --git a/src/test/java/de/gessnerfl/fakesmtp/server/EmailServerTest.java b/src/test/java/de/gessnerfl/fakesmtp/server/EmailServerTest.java
index 421acbfa..1586a886 100644
--- a/src/test/java/de/gessnerfl/fakesmtp/server/EmailServerTest.java
+++ b/src/test/java/de/gessnerfl/fakesmtp/server/EmailServerTest.java
@@ -1,17 +1,17 @@
package de.gessnerfl.fakesmtp.server;
-import org.junit.Test;
-import org.junit.runner.RunWith;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
-import org.mockito.junit.MockitoJUnitRunner;
+import org.mockito.junit.jupiter.MockitoExtension;
import org.slf4j.Logger;
-import static org.junit.Assert.*;
+import static org.junit.jupiter.api.Assertions.*;
import static org.mockito.Mockito.*;
-@RunWith(MockitoJUnitRunner.class)
-public class EmailServerTest {
+@ExtendWith(MockitoExtension.class)
+class EmailServerTest {
@Mock
private SmtpServerFactory smtpServerFactory;
@@ -22,7 +22,7 @@ public class EmailServerTest {
private EmailServer sut;
@Test
- public void shouldSetSmtpServerOnPostConstruct(){
+ void shouldSetSmtpServerOnPostConstruct(){
var smtpServer = mock(SmtpServer.class);
when(smtpServerFactory.create()).thenReturn(smtpServer);
@@ -34,7 +34,7 @@ public void shouldSetSmtpServerOnPostConstruct(){
}
@Test
- public void shouldStopServerOnPreDestroy(){
+ void shouldStopServerOnPreDestroy(){
var smtpServer = mock(SmtpServer.class);
sut.smtpServer = smtpServer;
@@ -45,7 +45,7 @@ public void shouldStopServerOnPreDestroy(){
}
@Test
- public void shouldSilentlyShutdownWhenNoServerIsSet(){
+ void shouldSilentlyShutdownWhenNoServerIsSet(){
sut.shutdown();
verify(logger).debug(anyString());
diff --git a/src/test/java/de/gessnerfl/fakesmtp/server/impl/BasicUsernamePasswordValidatorTest.java b/src/test/java/de/gessnerfl/fakesmtp/server/impl/BasicUsernamePasswordValidatorTest.java
index 39f32577..d5f2a1ac 100644
--- a/src/test/java/de/gessnerfl/fakesmtp/server/impl/BasicUsernamePasswordValidatorTest.java
+++ b/src/test/java/de/gessnerfl/fakesmtp/server/impl/BasicUsernamePasswordValidatorTest.java
@@ -1,19 +1,20 @@
package de.gessnerfl.fakesmtp.server.impl;
import de.gessnerfl.fakesmtp.config.FakeSmtpConfigurationProperties;
-import org.junit.Test;
-import org.junit.runner.RunWith;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
-import org.mockito.junit.MockitoJUnitRunner;
+import org.mockito.junit.jupiter.MockitoExtension;
import org.subethamail.smtp.auth.LoginFailedException;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
-@RunWith(MockitoJUnitRunner.class)
-public class BasicUsernamePasswordValidatorTest {
+@ExtendWith(MockitoExtension.class)
+class BasicUsernamePasswordValidatorTest {
@Mock
private FakeSmtpConfigurationProperties fakeSmtpConfigurationProperties;
@@ -23,7 +24,7 @@ public class BasicUsernamePasswordValidatorTest {
@Test
- public void shouldSuccessfullyValidateCorrectUsernameAndPassword() throws Exception {
+ void shouldSuccessfullyValidateCorrectUsernameAndPassword() throws Exception {
var username = "username";
var password = "password";
var authentication = mock(FakeSmtpConfigurationProperties.Authentication.class);
@@ -37,53 +38,61 @@ public void shouldSuccessfullyValidateCorrectUsernameAndPassword() throws Except
verify(authentication).getPassword();
}
- @Test(expected = LoginFailedException.class)
- public void shouldThrowLoginFailedExceptionWhenUsernameIsNotValid() throws Exception {
- var username = "username";
- var invalidUsername = "inValidUsername";
- var password = "password";
- var authentication = mock(FakeSmtpConfigurationProperties.Authentication.class);
- when(authentication.getUsername()).thenReturn(username);
- when(fakeSmtpConfigurationProperties.getAuthentication()).thenReturn(authentication);
-
- sut.login(invalidUsername, password);
+ @Test
+ void shouldThrowLoginFailedExceptionWhenUsernameIsNotValid() {
+ Assertions.assertThrows(LoginFailedException.class, () -> {
+ var username = "username";
+ var invalidUsername = "inValidUsername";
+ var password = "password";
+ var authentication = mock(FakeSmtpConfigurationProperties.Authentication.class);
+ when(authentication.getUsername()).thenReturn(username);
+ when(fakeSmtpConfigurationProperties.getAuthentication()).thenReturn(authentication);
+
+ sut.login(invalidUsername, password);
+ });
}
- @Test(expected = LoginFailedException.class)
- public void shouldThrowLoginFailedExceptionWhenPasswordIsNotValid() throws Exception {
- var username = "username";
- var password = "password";
- var invalidPassword = "invalidPassword";
- var authentication = mock(FakeSmtpConfigurationProperties.Authentication.class);
- when(authentication.getUsername()).thenReturn(username);
- when(authentication.getPassword()).thenReturn(password);
- when(fakeSmtpConfigurationProperties.getAuthentication()).thenReturn(authentication);
-
- sut.login(username, invalidPassword);
+ @Test
+ void shouldThrowLoginFailedExceptionWhenPasswordIsNotValid() {
+ Assertions.assertThrows(LoginFailedException.class, () -> {
+ var username = "username";
+ var password = "password";
+ var invalidPassword = "invalidPassword";
+ var authentication = mock(FakeSmtpConfigurationProperties.Authentication.class);
+ when(authentication.getUsername()).thenReturn(username);
+ when(authentication.getPassword()).thenReturn(password);
+ when(fakeSmtpConfigurationProperties.getAuthentication()).thenReturn(authentication);
+
+ sut.login(username, invalidPassword);
+ });
}
- @Test(expected = NullPointerException.class)
- public void shouldThrowNullPointerExceptionWhenAuthenticationIsMissing() throws Exception {
+ @Test
+ void shouldThrowNullPointerExceptionWhenAuthenticationIsMissing() {
var username = "username";
var password = "password";
when(fakeSmtpConfigurationProperties.getAuthentication()).thenReturn(null);
- sut.login(username, password);
+ Assertions.assertThrows(NullPointerException.class, () -> {
+ sut.login(username, password);
+ });
}
- @Test(expected = NullPointerException.class)
- public void shouldThrowNullPointerExceptionWhenUsernameIsMissingInAuthentication() throws Exception {
+ @Test
+ void shouldThrowNullPointerExceptionWhenUsernameIsMissingInAuthentication() {
var username = "username";
var password = "password";
var authentication = mock(FakeSmtpConfigurationProperties.Authentication.class);
when(authentication.getUsername()).thenReturn(null);
when(fakeSmtpConfigurationProperties.getAuthentication()).thenReturn(authentication);
- sut.login(username, password);
+ Assertions.assertThrows(NullPointerException.class, () -> {
+ sut.login(username, password);
+ });
}
- @Test(expected = NullPointerException.class)
- public void shouldThrowNullPointerExceptionWhenPasswordIsMissingInAuthentication() throws Exception {
+ @Test
+ void shouldThrowNullPointerExceptionWhenPasswordIsMissingInAuthentication() {
var username = "username";
var password = "password";
var authentication = mock(FakeSmtpConfigurationProperties.Authentication.class);
@@ -91,7 +100,9 @@ public void shouldThrowNullPointerExceptionWhenPasswordIsMissingInAuthentication
when(authentication.getPassword()).thenReturn(null);
when(fakeSmtpConfigurationProperties.getAuthentication()).thenReturn(authentication);
- sut.login(username, password);
+ Assertions.assertThrows(NullPointerException.class, () -> {
+ sut.login(username, password);
+ });
}
}
\ No newline at end of file
diff --git a/src/test/java/de/gessnerfl/fakesmtp/server/impl/EmailFactoryTest.java b/src/test/java/de/gessnerfl/fakesmtp/server/impl/EmailFactoryTest.java
index 7258bcb9..41c4f1e1 100644
--- a/src/test/java/de/gessnerfl/fakesmtp/server/impl/EmailFactoryTest.java
+++ b/src/test/java/de/gessnerfl/fakesmtp/server/impl/EmailFactoryTest.java
@@ -2,25 +2,27 @@
import de.gessnerfl.fakesmtp.TestResourceUtil;
import de.gessnerfl.fakesmtp.model.ContentType;
+import de.gessnerfl.fakesmtp.model.Email;
import de.gessnerfl.fakesmtp.model.EmailAttachment;
import de.gessnerfl.fakesmtp.model.EmailContent;
import de.gessnerfl.fakesmtp.util.TimestampProvider;
-import org.junit.Test;
-import org.junit.runner.RunWith;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
-import org.mockito.junit.MockitoJUnitRunner;
+import org.mockito.junit.jupiter.MockitoExtension;
import java.nio.charset.StandardCharsets;
import java.util.Date;
import static java.util.stream.Collectors.toList;
-import static org.junit.Assert.*;
+import static org.hamcrest.MatcherAssert.*;
import static org.hamcrest.Matchers.*;
+import static org.junit.jupiter.api.Assertions.*;
import static org.mockito.Mockito.when;
-@RunWith(MockitoJUnitRunner.class)
-public class EmailFactoryTest {
+@ExtendWith(MockitoExtension.class)
+class EmailFactoryTest {
private static final String SENDER = "sender";
private static final String RECEIVER = "receiver";
@@ -32,7 +34,7 @@ public class EmailFactoryTest {
private EmailFactory sut;
@Test
- public void shouldCreateEmailForEmlFileWithSubjectAndContentTypePlain() throws Exception {
+ void shouldCreateEmailForEmlFileWithSubjectAndContentTypePlain() throws Exception {
var now = new Date();
var testFilename = "mail-with-subject.eml";
var data = TestResourceUtil.getTestFileContentBytes(testFilename);
@@ -43,6 +45,10 @@ public void shouldCreateEmailForEmlFileWithSubjectAndContentTypePlain() throws E
var result = sut.convert(rawData);
+ assertPlainTextEmail(now, dataAsString, result);
+ }
+
+ private void assertPlainTextEmail(Date now, String dataAsString, Email result) {
assertEquals(SENDER, result.getFromAddress());
assertEquals(RECEIVER, result.getToAddress());
assertEquals("This is the mail title", result.getSubject());
@@ -56,7 +62,7 @@ public void shouldCreateEmailForEmlFileWithSubjectAndContentTypePlain() throws E
}
@Test
- public void shouldCreateEmailForEmlFileWithSubjectAndContentTypeHtml() throws Exception {
+ void shouldCreateEmailForEmlFileWithSubjectAndContentTypeHtml() throws Exception {
var now = new Date();
var testFilename = "mail-with-subject-and-content-type-html.eml";
var data = TestResourceUtil.getTestFileContentBytes(testFilename);
@@ -80,7 +86,7 @@ public void shouldCreateEmailForEmlFileWithSubjectAndContentTypeHtml() throws Ex
}
@Test
- public void shouldCreateEmailForEmlFileWithSubjectAndWithoutContentType() throws Exception {
+ void shouldCreateEmailForEmlFileWithSubjectAndWithoutContentType() throws Exception {
var now = new Date();
var testFilename = "mail-with-subject-without-content-type.eml";
var data = TestResourceUtil.getTestFileContentBytes(testFilename);
@@ -91,20 +97,11 @@ public void shouldCreateEmailForEmlFileWithSubjectAndWithoutContentType() throws
var result = sut.convert(rawData);
- assertEquals(SENDER, result.getFromAddress());
- assertEquals(RECEIVER, result.getToAddress());
- assertEquals("This is the mail title", result.getSubject());
- assertEquals(dataAsString, result.getRawData());
- assertThat(result.getContents(), hasSize(1));
- assertFalse(result.getHtmlContent().isPresent());
- assertTrue(result.getPlainContent().isPresent());
- assertEquals("This is the message content", result.getPlainContent().get().getData());
- assertEquals(now, result.getReceivedOn());
- assertThat(result.getAttachments(), empty());
+ assertPlainTextEmail(now, dataAsString, result);
}
@Test
- public void shouldCreateEmailForEmlFileWithoutSubjectAndContentTypePlain() throws Exception {
+ void shouldCreateEmailForEmlFileWithoutSubjectAndContentTypePlain() throws Exception {
var now = new Date();
var testFilename = "mail-without-subject.eml";
var data = TestResourceUtil.getTestFileContentBytes(testFilename);
@@ -128,7 +125,7 @@ public void shouldCreateEmailForEmlFileWithoutSubjectAndContentTypePlain() throw
}
@Test
- public void shouldCreateMailForPlainText() throws Exception {
+ void shouldCreateMailForPlainText() throws Exception {
var now = new Date();
var dataAsString = "this is just some dummy content";
var data = dataAsString.getBytes(StandardCharsets.UTF_8);
@@ -151,7 +148,7 @@ public void shouldCreateMailForPlainText() throws Exception {
}
@Test
- public void shouldCreateMailForMultipartWithContentTypeHtmlAndPlain() throws Exception {
+ void shouldCreateMailForMultipartWithContentTypeHtmlAndPlain() throws Exception {
var now = new Date();
var testFilename = "multipart-mail.eml";
var data = TestResourceUtil.getTestFileContentBytes(testFilename);
@@ -176,7 +173,7 @@ public void shouldCreateMailForMultipartWithContentTypeHtmlAndPlain() throws Exc
}
@Test
- public void shouldCreateMailForMultipartWithoutContentTypeHtml() throws Exception {
+ void shouldCreateMailForMultipartWithoutContentTypeHtml() throws Exception {
var now = new Date();
var testFilename = "multipart-mail-plain-only.eml";
var data = TestResourceUtil.getTestFileContentBytes(testFilename);
@@ -187,20 +184,11 @@ public void shouldCreateMailForMultipartWithoutContentTypeHtml() throws Exceptio
var result = sut.convert(rawData);
- assertEquals(SENDER, result.getFromAddress());
- assertEquals(RECEIVER, result.getToAddress());
- assertEquals("This is the mail title", result.getSubject());
- assertEquals(dataAsString, result.getRawData());
- assertThat(result.getContents(), hasSize(1));
- assertFalse(result.getHtmlContent().isPresent());
- assertTrue(result.getPlainContent().isPresent());
- assertEquals("This is the message content", result.getPlainContent().get().getData());
- assertEquals(now, result.getReceivedOn());
- assertThat(result.getAttachments(), empty());
+ assertPlainTextEmail(now, dataAsString, result);
}
@Test
- public void shouldCreateMailForMultipartWithUnknownContentType() throws Exception {
+ void shouldCreateMailForMultipartWithUnknownContentType() throws Exception {
var now = new Date();
var testFilename = "multipart-mail-unknown-content-type.eml";
var data = TestResourceUtil.getTestFileContentBytes(testFilename);
@@ -225,7 +213,7 @@ public void shouldCreateMailForMultipartWithUnknownContentType() throws Exceptio
}
@Test
- public void shouldCreateMailForMultipartWithPlainAndHtmlContentAndAttachments() throws Exception {
+ void shouldCreateMailForMultipartWithPlainAndHtmlContentAndAttachments() throws Exception {
var now = new Date();
var testFilename = "multipart-mail-html-and-plain-with-attachments.eml";
var data = TestResourceUtil.getTestFileContentBytes(testFilename);
diff --git a/src/test/java/de/gessnerfl/fakesmtp/server/impl/EmailFilterTest.java b/src/test/java/de/gessnerfl/fakesmtp/server/impl/EmailFilterTest.java
index 4eaafed7..c1e97254 100644
--- a/src/test/java/de/gessnerfl/fakesmtp/server/impl/EmailFilterTest.java
+++ b/src/test/java/de/gessnerfl/fakesmtp/server/impl/EmailFilterTest.java
@@ -1,18 +1,18 @@
package de.gessnerfl.fakesmtp.server.impl;
import de.gessnerfl.fakesmtp.config.FakeSmtpConfigurationProperties;
-import org.junit.Test;
-import org.junit.runner.RunWith;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
-import org.mockito.junit.MockitoJUnitRunner;
+import org.mockito.junit.jupiter.MockitoExtension;
import org.slf4j.Logger;
-import static org.junit.Assert.*;
+import static org.junit.jupiter.api.Assertions.*;
import static org.mockito.Mockito.*;
-@RunWith(MockitoJUnitRunner.class)
-public class EmailFilterTest {
+@ExtendWith(MockitoExtension.class)
+class EmailFilterTest {
private static final String TEST_EMAIL_ADDRESS_1 = "john@doe.com";
private static final String TEST_EMAIL_ADDRESS_2 = "jane@doe.com";
@@ -26,7 +26,7 @@ public class EmailFilterTest {
private EmailFilter sut;
@Test
- public void emptyFilter(){
+ void emptyFilter(){
when(fakeSmtpConfigurationProperties.getFilteredEmailRegexList()).thenReturn(null);
assertFalse(sut.ignore(TEST_EMAIL_ADDRESS_1, TEST_EMAIL_ADDRESS_2));
@@ -35,31 +35,31 @@ public void emptyFilter(){
}
@Test
- public void noneMatchingFilter(){
+ void noneMatchingFilter(){
when(fakeSmtpConfigurationProperties.getFilteredEmailRegexList()).thenReturn(".*@google.com");
assertFalse(sut.ignore(TEST_EMAIL_ADDRESS_1,TEST_EMAIL_ADDRESS_2));
}
@Test
- public void matchingFilter(){
+ void matchingFilter(){
when(fakeSmtpConfigurationProperties.getFilteredEmailRegexList()).thenReturn(".*@doe.com");
assertTrue(sut.ignore(TEST_EMAIL_ADDRESS_1,TEST_EMAIL_ADDRESS_2));
}
@Test
- public void matchingFilterMultipleRegexAnyMatch(){
+ void matchingFilterMultipleRegexAnyMatch(){
when(fakeSmtpConfigurationProperties.getFilteredEmailRegexList()).thenReturn(".*@other\\.com,jane@.*");
assertTrue(sut.ignore(TEST_EMAIL_ADDRESS_1,TEST_EMAIL_ADDRESS_2));
}
@Test
- public void matchingFilterMultipleRegexAllMatch(){
+ void matchingFilterMultipleRegexAllMatch(){
when(fakeSmtpConfigurationProperties.getFilteredEmailRegexList()).thenReturn(".*@doe\\.com,jane@.*");
assertTrue(sut.ignore(TEST_EMAIL_ADDRESS_1,TEST_EMAIL_ADDRESS_2));
}
@Test
- public void invalidRegex(){
+ void invalidRegex(){
when(fakeSmtpConfigurationProperties.getFilteredEmailRegexList()).thenReturn("****");
assertFalse(sut.ignore(TEST_EMAIL_ADDRESS_1,TEST_EMAIL_ADDRESS_2));
}
diff --git a/src/test/java/de/gessnerfl/fakesmtp/server/impl/JavaMailSenderFacadeTest.java b/src/test/java/de/gessnerfl/fakesmtp/server/impl/JavaMailSenderFacadeTest.java
index 044cf815..bc0194c4 100644
--- a/src/test/java/de/gessnerfl/fakesmtp/server/impl/JavaMailSenderFacadeTest.java
+++ b/src/test/java/de/gessnerfl/fakesmtp/server/impl/JavaMailSenderFacadeTest.java
@@ -1,6 +1,6 @@
package de.gessnerfl.fakesmtp.server.impl;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;
@@ -9,10 +9,10 @@
import static org.mockito.Mockito.*;
-public class JavaMailSenderFacadeTest {
+class JavaMailSenderFacadeTest {
@Test
- public void shouldSendMimeMessageWhenMailSystemIsAvailable() {
+ void shouldSendMimeMessageWhenMailSystemIsAvailable() {
var javaMailSender = mock(JavaMailSender.class);
var logger = mock(Logger.class);
var mimeMessage = mock(MimeMessage.class);
@@ -29,7 +29,7 @@ public void shouldSendMimeMessageWhenMailSystemIsAvailable() {
}
@Test
- public void shouldLogErrorAndSkipSendingOfMimeMessageWhenMailSystemIsNotAvailable() {
+ void shouldLogErrorAndSkipSendingOfMimeMessageWhenMailSystemIsNotAvailable() {
var logger = mock(Logger.class);
var mimeMessage = mock(MimeMessage.class);
@@ -43,7 +43,7 @@ public void shouldLogErrorAndSkipSendingOfMimeMessageWhenMailSystemIsNotAvailabl
}
@Test
- public void shouldSendSimpleMessageWhenMailSystemIsAvailable() {
+ void shouldSendSimpleMessageWhenMailSystemIsAvailable() {
var javaMailSender = mock(JavaMailSender.class);
var logger = mock(Logger.class);
var message = mock(SimpleMailMessage.class);
@@ -60,7 +60,7 @@ public void shouldSendSimpleMessageWhenMailSystemIsAvailable() {
}
@Test
- public void shouldLogErrorAndSkipSendingOfSimpleMessageWhenMailSystemIsNotAvailable() {
+ void shouldLogErrorAndSkipSendingOfSimpleMessageWhenMailSystemIsNotAvailable() {
var logger = mock(Logger.class);
var message = mock(SimpleMailMessage.class);
diff --git a/src/test/java/de/gessnerfl/fakesmtp/server/impl/MessageForwarderTest.java b/src/test/java/de/gessnerfl/fakesmtp/server/impl/MessageForwarderTest.java
index f9c8b8ea..d7dd8776 100644
--- a/src/test/java/de/gessnerfl/fakesmtp/server/impl/MessageForwarderTest.java
+++ b/src/test/java/de/gessnerfl/fakesmtp/server/impl/MessageForwarderTest.java
@@ -1,23 +1,23 @@
package de.gessnerfl.fakesmtp.server.impl;
import de.gessnerfl.fakesmtp.config.FakeSmtpConfigurationProperties;
-import org.junit.Test;
-import org.junit.runner.RunWith;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.ArgumentCaptor;
import org.mockito.InjectMocks;
import org.mockito.Mock;
-import org.mockito.junit.MockitoJUnitRunner;
+import org.mockito.junit.jupiter.MockitoExtension;
import org.slf4j.Logger;
import org.springframework.mail.SimpleMailMessage;
import javax.mail.MessagingException;
import javax.mail.internet.MimeMessage;
-import static org.junit.Assert.assertEquals;
import static org.mockito.Mockito.*;
-@RunWith(MockitoJUnitRunner.class)
-public class MessageForwarderTest {
+@ExtendWith(MockitoExtension.class)
+class MessageForwarderTest {
@Mock
private FakeSmtpConfigurationProperties configurationProperties;
@@ -30,7 +30,7 @@ public class MessageForwarderTest {
private MessageForwarder sut;
@Test
- public void shouldSkipForwardingWhenForwardingIsNotEnabled() throws Exception {
+ void shouldSkipForwardingWhenForwardingIsNotEnabled() throws Exception {
var rawData = mock(RawData.class);
when(configurationProperties.isForwardEmails()).thenReturn(false);
@@ -41,7 +41,7 @@ public void shouldSkipForwardingWhenForwardingIsNotEnabled() throws Exception {
}
@Test
- public void shouldForwardMimeMessageWhenForwardingIsEnabledAndEmailCanBeConvertedToMimeMessage() throws Exception {
+ void shouldForwardMimeMessageWhenForwardingIsEnabledAndEmailCanBeConvertedToMimeMessage() throws Exception {
var mimeMessage = mock(MimeMessage.class);
var rawData = mock(RawData.class);
when(rawData.toMimeMessage()).thenReturn(mimeMessage);
@@ -55,7 +55,7 @@ public void shouldForwardMimeMessageWhenForwardingIsEnabledAndEmailCanBeConverte
}
@Test
- public void shouldForwardEmailAsSimpleMessageWhenForwardingIsEnabledAndEmailCannotBeConvertedToMimeMessage() throws Exception {
+ void shouldForwardEmailAsSimpleMessageWhenForwardingIsEnabledAndEmailCannotBeConvertedToMimeMessage() throws Exception {
var expectedException = new MessagingException("test");
var from = "from";
var to = "to";
@@ -80,9 +80,9 @@ public void shouldForwardEmailAsSimpleMessageWhenForwardingIsEnabledAndEmailCann
verifyNoMoreInteractions(rawData, javaMailSenderFacade);
var message = mailMessageArgumentCaptor.getValue();
- assertEquals(from, message.getFrom());
- assertEquals(to, message.getTo()[0]);
- assertEquals(content, message.getText());
+ Assertions.assertEquals(from, message.getFrom());
+ Assertions.assertEquals(to, message.getTo()[0]);
+ Assertions.assertEquals(content, message.getText());
}
}
\ No newline at end of file
diff --git a/src/test/java/de/gessnerfl/fakesmtp/server/impl/MessageListenerIntegrationTest.java b/src/test/java/de/gessnerfl/fakesmtp/server/impl/MessageListenerIntegrationTest.java
index 9e2929aa..b4787cf8 100644
--- a/src/test/java/de/gessnerfl/fakesmtp/server/impl/MessageListenerIntegrationTest.java
+++ b/src/test/java/de/gessnerfl/fakesmtp/server/impl/MessageListenerIntegrationTest.java
@@ -2,26 +2,27 @@
import de.gessnerfl.fakesmtp.TestResourceUtil;
import de.gessnerfl.fakesmtp.repository.EmailRepository;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.ActiveProfiles;
-import org.springframework.test.context.junit4.SpringRunner;
+import org.springframework.test.context.junit.jupiter.SpringExtension;
import javax.transaction.Transactional;
import java.io.ByteArrayInputStream;
import java.nio.charset.StandardCharsets;
+import static org.hamcrest.MatcherAssert.*;
import static org.hamcrest.Matchers.hasSize;
-import static org.junit.Assert.*;
+import static org.junit.jupiter.api.Assertions.*;
@Transactional
@ActiveProfiles("integrationtest")
-@RunWith(SpringRunner.class)
+@ExtendWith(SpringExtension.class)
@SpringBootTest
-public class MessageListenerIntegrationTest {
+class MessageListenerIntegrationTest {
private static final String SENDER = "sender";
private static final String RECEIVER = "receiver";
@@ -31,13 +32,13 @@ public class MessageListenerIntegrationTest {
@Autowired
private MessageListener sut;
- @Before
- public void setup(){
+ @BeforeEach
+ void setup(){
emailRepository.deleteAll();
}
@Test
- public void shouldCreateEmailForEmlFileWithSubject() throws Exception {
+ void shouldCreateEmailForEmlFileWithSubject() throws Exception {
var testFilename = "mail-with-subject.eml";
var data = TestResourceUtil.getTestFile(testFilename);
var rawData = TestResourceUtil.getTestFileContent(testFilename);
@@ -61,7 +62,7 @@ public void shouldCreateEmailForEmlFileWithSubject() throws Exception {
}
@Test
- public void shouldCreateEmailForEmlFileWithoutSubject() throws Exception {
+ void shouldCreateEmailForEmlFileWithoutSubject() throws Exception {
var testFilename = "mail-without-subject.eml";
var data = TestResourceUtil.getTestFile(testFilename);
var rawData = TestResourceUtil.getTestFileContent(testFilename);
@@ -85,7 +86,7 @@ public void shouldCreateEmailForEmlFileWithoutSubject() throws Exception {
}
@Test
- public void shouldCreateMailForPlainText() throws Exception {
+ void shouldCreateMailForPlainText() throws Exception {
var rawData = "this is just some dummy content";
var data = new ByteArrayInputStream(rawData.getBytes(StandardCharsets.UTF_8));
diff --git a/src/test/java/de/gessnerfl/fakesmtp/server/impl/MessageListenerTest.java b/src/test/java/de/gessnerfl/fakesmtp/server/impl/MessageListenerTest.java
index 6d9f9b98..e44113df 100644
--- a/src/test/java/de/gessnerfl/fakesmtp/server/impl/MessageListenerTest.java
+++ b/src/test/java/de/gessnerfl/fakesmtp/server/impl/MessageListenerTest.java
@@ -2,23 +2,23 @@
import de.gessnerfl.fakesmtp.model.Email;
import de.gessnerfl.fakesmtp.repository.EmailRepository;
-import org.junit.Test;
-import org.junit.runner.RunWith;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.ArgumentCaptor;
import org.mockito.InjectMocks;
import org.mockito.Mock;
-import org.mockito.junit.MockitoJUnitRunner;
+import org.mockito.junit.jupiter.MockitoExtension;
import org.slf4j.Logger;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
-import static org.junit.Assert.*;
+import static org.junit.jupiter.api.Assertions.*;
import static org.mockito.Mockito.*;
-@RunWith(MockitoJUnitRunner.class)
-public class MessageListenerTest {
+@ExtendWith(MockitoExtension.class)
+class MessageListenerTest {
@Mock
private EmailFactory emailFactory;
@@ -35,12 +35,12 @@ public class MessageListenerTest {
private MessageListener sut;
@Test
- public void shouldAcceptAllMails(){
+ void shouldAcceptAllMails(){
assertTrue(sut.accept("foo", "bar"));
}
@Test
- public void shouldCreateEmailEntityAndStoreItInDatabaseWhenEmailIsDelivered() throws IOException {
+ void shouldCreateEmailEntityAndStoreItInDatabaseWhenEmailIsDelivered() throws IOException {
var from = "from";
var to = "to";
var contentString = "content";
@@ -62,8 +62,8 @@ public void shouldCreateEmailEntityAndStoreItInDatabaseWhenEmailIsDelivered() th
verify(messageForwarder).forward(rawData);
}
- @Test(expected = IOException.class)
- public void shouldThrowExceptionWhenEmailEntityCannotBeCreatedWhenEmailIsDelivered() throws IOException {
+ @Test
+ void shouldThrowExceptionWhenEmailEntityCannotBeCreatedWhenEmailIsDelivered() throws IOException {
var from = "from";
var to = "to";
var content = "content".getBytes(StandardCharsets.UTF_8);
@@ -71,9 +71,12 @@ public void shouldThrowExceptionWhenEmailEntityCannotBeCreatedWhenEmailIsDeliver
when(emailFactory.convert(any(RawData.class))).thenThrow(new IOException("foo"));
- sut.deliver(from, to, contentStream);
+ assertThrows(IOException.class, () -> {
+
+ sut.deliver(from, to, contentStream);
- verify(emailRepository, never()).save(any(Email.class));
- verify(messageForwarder, never()).forward(any(RawData.class));
+ verify(emailRepository, never()).save(any(Email.class));
+ verify(messageForwarder, never()).forward(any(RawData.class));
+ });
}
}
\ No newline at end of file
diff --git a/src/test/java/de/gessnerfl/fakesmtp/server/impl/RawDataTest.java b/src/test/java/de/gessnerfl/fakesmtp/server/impl/RawDataTest.java
index cddcceb4..7c0fa7ef 100644
--- a/src/test/java/de/gessnerfl/fakesmtp/server/impl/RawDataTest.java
+++ b/src/test/java/de/gessnerfl/fakesmtp/server/impl/RawDataTest.java
@@ -1,20 +1,19 @@
package de.gessnerfl.fakesmtp.server.impl;
import de.gessnerfl.fakesmtp.TestResourceUtil;
-import org.junit.Test;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
import javax.mail.internet.MimeMessage;
-import static org.junit.Assert.assertEquals;
-
-public class RawDataTest {
+class RawDataTest {
@Test
- public void shouldReturnMimeMessage() throws Exception {
+ void shouldReturnMimeMessage() throws Exception {
RawData sut = new RawData("from", "to", TestResourceUtil.getTestFileContentBytes(("mail-with-subject.eml")));
MimeMessage message = sut.toMimeMessage();
- assertEquals("This is the mail title", message.getSubject());
+ Assertions.assertEquals("This is the mail title", message.getSubject());
}
}
\ No newline at end of file
diff --git a/src/test/java/de/gessnerfl/fakesmtp/server/impl/SmtpServerConfiguratorTest.java b/src/test/java/de/gessnerfl/fakesmtp/server/impl/SmtpServerConfiguratorTest.java
index f0f093a1..8fba39ef 100644
--- a/src/test/java/de/gessnerfl/fakesmtp/server/impl/SmtpServerConfiguratorTest.java
+++ b/src/test/java/de/gessnerfl/fakesmtp/server/impl/SmtpServerConfiguratorTest.java
@@ -1,12 +1,12 @@
package de.gessnerfl.fakesmtp.server.impl;
import de.gessnerfl.fakesmtp.config.FakeSmtpConfigurationProperties;
-import org.junit.Test;
-import org.junit.runner.RunWith;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.ArgumentCaptor;
import org.mockito.InjectMocks;
import org.mockito.Mock;
-import org.mockito.junit.MockitoJUnitRunner;
+import org.mockito.junit.jupiter.MockitoExtension;
import org.slf4j.Logger;
import org.subethamail.smtp.AuthenticationHandlerFactory;
import org.subethamail.smtp.auth.EasyAuthenticationHandlerFactory;
@@ -14,12 +14,13 @@
import java.net.InetAddress;
+import static org.hamcrest.MatcherAssert.*;
import static org.hamcrest.Matchers.instanceOf;
-import static org.junit.Assert.*;
+import static org.junit.jupiter.api.Assertions.*;
import static org.mockito.Mockito.*;
-@RunWith(MockitoJUnitRunner.class)
-public class SmtpServerConfiguratorTest {
+@ExtendWith(MockitoExtension.class)
+class SmtpServerConfiguratorTest {
@Mock
private FakeSmtpConfigurationProperties fakeSmtpConfigurationProperties;
@@ -32,7 +33,7 @@ public class SmtpServerConfiguratorTest {
private SmtpServerConfigurator sut;
@Test
- public void shouldConfigureBasicParameters(){
+ void shouldConfigureBasicParameters(){
var port = 1234;
var bindingAddress = mock(InetAddress.class);
when(fakeSmtpConfigurationProperties.getPort()).thenReturn(port);
@@ -48,7 +49,7 @@ public void shouldConfigureBasicParameters(){
}
@Test
- public void shouldConfigureAuthenticationWhenAuthenticationIsConfiguredProperly(){
+ void shouldConfigureAuthenticationWhenAuthenticationIsConfiguredProperly(){
var username = "username";
var password = "password";
var authentication = mock(FakeSmtpConfigurationProperties.Authentication.class);
@@ -72,7 +73,7 @@ public void shouldConfigureAuthenticationWhenAuthenticationIsConfiguredProperly(
}
@Test
- public void shouldSkipConfigurationOfAuthenticationWhenUsernameIsNull(){
+ void shouldSkipConfigurationOfAuthenticationWhenUsernameIsNull(){
var authentication = mock(FakeSmtpConfigurationProperties.Authentication.class);
when(authentication.getUsername()).thenReturn(null);
when(fakeSmtpConfigurationProperties.getAuthentication()).thenReturn(authentication);
@@ -86,7 +87,7 @@ public void shouldSkipConfigurationOfAuthenticationWhenUsernameIsNull(){
}
@Test
- public void shouldSkipConfigurationOfAuthenticationWhenUsernameIsEmptyString(){
+ void shouldSkipConfigurationOfAuthenticationWhenUsernameIsEmptyString(){
var authentication = mock(FakeSmtpConfigurationProperties.Authentication.class);
when(authentication.getUsername()).thenReturn("");
when(fakeSmtpConfigurationProperties.getAuthentication()).thenReturn(authentication);
@@ -100,7 +101,7 @@ public void shouldSkipConfigurationOfAuthenticationWhenUsernameIsEmptyString(){
}
@Test
- public void shouldSkipConfigurationOfAuthenticationWhenPasswordIsNull(){
+ void shouldSkipConfigurationOfAuthenticationWhenPasswordIsNull(){
var username = "username";
var authentication = mock(FakeSmtpConfigurationProperties.Authentication.class);
when(authentication.getUsername()).thenReturn(username);
@@ -116,7 +117,7 @@ public void shouldSkipConfigurationOfAuthenticationWhenPasswordIsNull(){
}
@Test
- public void shouldSkipConfigurationOfAuthenticationWhenPasswordIsEmptyString(){
+ void shouldSkipConfigurationOfAuthenticationWhenPasswordIsEmptyString(){
var username = "username";
var authentication = mock(FakeSmtpConfigurationProperties.Authentication.class);
when(authentication.getUsername()).thenReturn(username);
diff --git a/src/test/java/de/gessnerfl/fakesmtp/server/impl/SmtpServerFactoryImplTest.java b/src/test/java/de/gessnerfl/fakesmtp/server/impl/SmtpServerFactoryImplTest.java
index 2818f3fe..e31d51e3 100644
--- a/src/test/java/de/gessnerfl/fakesmtp/server/impl/SmtpServerFactoryImplTest.java
+++ b/src/test/java/de/gessnerfl/fakesmtp/server/impl/SmtpServerFactoryImplTest.java
@@ -1,18 +1,18 @@
package de.gessnerfl.fakesmtp.server.impl;
-import org.junit.Test;
-import org.junit.runner.RunWith;
+import org.hamcrest.MatcherAssert;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
-import org.mockito.junit.MockitoJUnitRunner;
+import org.mockito.junit.jupiter.MockitoExtension;
import static org.hamcrest.Matchers.instanceOf;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertThat;
import static org.mockito.Mockito.verify;
-@RunWith(MockitoJUnitRunner.class)
-public class SmtpServerFactoryImplTest {
+@ExtendWith(MockitoExtension.class)
+class SmtpServerFactoryImplTest {
private final int PORT = 25;
@Mock
@@ -24,12 +24,12 @@ public class SmtpServerFactoryImplTest {
private SmtpServerFactoryImpl sut;
@Test
- public void shouldCreateAndConfigureNewInsance(){
+ void shouldCreateAndConfigureNewInsance(){
var smtpServer = sut.create();
- assertThat(smtpServer, instanceOf(SmtpServerImpl.class));
+ MatcherAssert.assertThat(smtpServer, instanceOf(SmtpServerImpl.class));
var impl = (SmtpServerImpl)smtpServer;
- assertNotNull(impl.smtpServer);
+ Assertions.assertNotNull(impl.smtpServer);
verify(configurator).configure(impl.smtpServer);
}
diff --git a/src/test/java/de/gessnerfl/fakesmtp/server/impl/SmtpServerImplTest.java b/src/test/java/de/gessnerfl/fakesmtp/server/impl/SmtpServerImplTest.java
index a76573fd..e18f0741 100644
--- a/src/test/java/de/gessnerfl/fakesmtp/server/impl/SmtpServerImplTest.java
+++ b/src/test/java/de/gessnerfl/fakesmtp/server/impl/SmtpServerImplTest.java
@@ -1,15 +1,15 @@
package de.gessnerfl.fakesmtp.server.impl;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import org.subethamail.smtp.server.SMTPServer;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
-public class SmtpServerImplTest {
+class SmtpServerImplTest {
@Test
- public void shouldCreateNewInstanceAndDelegateCallsToRealImplementation(){
+ void shouldCreateNewInstanceAndDelegateCallsToRealImplementation(){
var delegate = mock(SMTPServer.class);
var sut = new SmtpServerImpl(delegate);
diff --git a/src/test/java/de/gessnerfl/fakesmtp/service/EmailRetentionTimerTest.java b/src/test/java/de/gessnerfl/fakesmtp/service/EmailRetentionTimerTest.java
index f8825e20..224fde3f 100644
--- a/src/test/java/de/gessnerfl/fakesmtp/service/EmailRetentionTimerTest.java
+++ b/src/test/java/de/gessnerfl/fakesmtp/service/EmailRetentionTimerTest.java
@@ -2,17 +2,17 @@
import de.gessnerfl.fakesmtp.config.FakeSmtpConfigurationProperties;
import de.gessnerfl.fakesmtp.repository.EmailRepository;
-import org.junit.Test;
-import org.junit.runner.RunWith;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
-import org.mockito.junit.MockitoJUnitRunner;
+import org.mockito.junit.jupiter.MockitoExtension;
import org.slf4j.Logger;
import static org.mockito.Mockito.*;
-@RunWith(MockitoJUnitRunner.class)
-public class EmailRetentionTimerTest {
+@ExtendWith(MockitoExtension.class)
+class EmailRetentionTimerTest {
@Mock
private FakeSmtpConfigurationProperties fakeSmtpConfigurationProperties;
@@ -25,7 +25,7 @@ public class EmailRetentionTimerTest {
private EmailRetentionTimer sut;
@Test
- public void shouldTriggerDeletionWhenDataRetentionIsConfigured(){
+ void shouldTriggerDeletionWhenDataRetentionIsConfigured(){
var maxNumber = 5;
var persistence = mock(FakeSmtpConfigurationProperties.Persistence.class);
when(persistence.getMaxNumberEmails()).thenReturn(maxNumber);
@@ -37,7 +37,7 @@ public void shouldTriggerDeletionWhenDataRetentionIsConfigured(){
}
@Test
- public void shouldNotTriggerDeletionWhenConfiguredMaxNumberIsNull(){
+ void shouldNotTriggerDeletionWhenConfiguredMaxNumberIsNull(){
var persistence = mock(FakeSmtpConfigurationProperties.Persistence.class);
when(persistence.getMaxNumberEmails()).thenReturn(null);
when(fakeSmtpConfigurationProperties.getPersistence()).thenReturn(persistence);
@@ -48,7 +48,7 @@ public void shouldNotTriggerDeletionWhenConfiguredMaxNumberIsNull(){
}
@Test
- public void shouldNotTriggerDeletionWhenConfiguredMaxNumberIsLessOrEqualToZero(){
+ void shouldNotTriggerDeletionWhenConfiguredMaxNumberIsLessOrEqualToZero(){
var persistence = mock(FakeSmtpConfigurationProperties.Persistence.class);
when(persistence.getMaxNumberEmails()).thenReturn(0);
when(fakeSmtpConfigurationProperties.getPersistence()).thenReturn(persistence);
@@ -59,7 +59,7 @@ public void shouldNotTriggerDeletionWhenConfiguredMaxNumberIsLessOrEqualToZero()
}
@Test
- public void shouldNotTriggerDeletionWhenNoPersistenceIsConfigured(){
+ void shouldNotTriggerDeletionWhenNoPersistenceIsConfigured(){
when(fakeSmtpConfigurationProperties.getPersistence()).thenReturn(null);
sut.deleteOutdatedMails();
diff --git a/src/test/java/de/gessnerfl/fakesmtp/util/MediaTypeUtilTest.java b/src/test/java/de/gessnerfl/fakesmtp/util/MediaTypeUtilTest.java
index 3cc70394..e72f58d3 100644
--- a/src/test/java/de/gessnerfl/fakesmtp/util/MediaTypeUtilTest.java
+++ b/src/test/java/de/gessnerfl/fakesmtp/util/MediaTypeUtilTest.java
@@ -1,29 +1,29 @@
package de.gessnerfl.fakesmtp.util;
-import org.junit.Before;
-import org.junit.Test;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
import org.springframework.http.MediaType;
import javax.servlet.ServletContext;
-import static org.junit.Assert.*;
+import static org.junit.jupiter.api.Assertions.*;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
-public class MediaTypeUtilTest {
+class MediaTypeUtilTest {
private ServletContext servletContext;
private MediaTypeUtil sut;
- @Before
- public void init(){
+ @BeforeEach
+ void init(){
servletContext = mock(ServletContext.class);
sut = new MediaTypeUtil();
}
@Test
- public void shouldReturnMediaTypeForDefaultMimeType(){
+ void shouldReturnMediaTypeForDefaultMimeType(){
var filename = "mypicture.png";
when(servletContext.getMimeType(filename)).thenReturn(MediaType.IMAGE_PNG_VALUE);
@@ -34,7 +34,7 @@ public void shouldReturnMediaTypeForDefaultMimeType(){
}
@Test
- public void shouldReturnMappedMimeTimeForNonDefaultMediaType(){
+ void shouldReturnMappedMimeTimeForNonDefaultMediaType(){
var filename = "my-word-file.docx";
when(servletContext.getMimeType(filename)).thenReturn("application/vnd.openxmlformats-officedocument.wordprocessingml.document");
@@ -45,7 +45,7 @@ public void shouldReturnMappedMimeTimeForNonDefaultMediaType(){
}
@Test
- public void shouldReturnOctedStreamForInvalidMediaType(){
+ void shouldReturnOctedStreamForInvalidMediaType(){
var filename = "my-word-file.foo";
when(servletContext.getMimeType(filename)).thenReturn("invalidMediaType");