From e05656e3fb2803dc3cca15e951b063951b8ae392 Mon Sep 17 00:00:00 2001 From: Florian Gessner Date: Thu, 12 Nov 2020 21:23:26 +0100 Subject: [PATCH 1/5] #33: add application version to UI --- build.gradle | 7 +++- .../fakesmtp/controller/EmailController.java | 12 ++++++- .../resources/templates/fragments/navbar.html | 5 ++- .../EmailControllerMVCIntegrationTest.java | 15 +++------ .../controller/EmailControllerTest.java | 33 +++++++++++++++---- ...EmailRestControllerMVCIntegrationTest.java | 9 ----- 6 files changed, 52 insertions(+), 29 deletions(-) diff --git a/build.gradle b/build.gradle index d49da862..f8943df3 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" } @@ -39,12 +39,17 @@ dependencies { implementation('org.webjars:material-design-icons:3.0.1') runtimeOnly('com.h2database:h2') + testImplementation('org.junit.vintage:junit-vintage-engine') testImplementation('org.springframework.boot:spring-boot-starter-test') testImplementation('org.ow2.asm:asm:9.0') testImplementation('org.apache.commons:commons-lang3:3.11') 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/controller/EmailControllerMVCIntegrationTest.java b/src/test/java/de/gessnerfl/fakesmtp/controller/EmailControllerMVCIntegrationTest.java index 05651481..c0cdbb07 100644 --- a/src/test/java/de/gessnerfl/fakesmtp/controller/EmailControllerMVCIntegrationTest.java +++ b/src/test/java/de/gessnerfl/fakesmtp/controller/EmailControllerMVCIntegrationTest.java @@ -1,28 +1,17 @@ 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.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.web.servlet.MockMvc; -import java.nio.charset.StandardCharsets; -import java.time.LocalDateTime; -import java.time.ZoneOffset; -import java.util.Date; - import static org.hamcrest.Matchers.*; import static org.junit.Assert.*; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.delete; @@ -50,6 +39,7 @@ public 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")); } @@ -63,12 +53,14 @@ 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")); } @@ -89,6 +81,7 @@ public void shouldReturnMailById() throws Exception { 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")); } diff --git a/src/test/java/de/gessnerfl/fakesmtp/controller/EmailControllerTest.java b/src/test/java/de/gessnerfl/fakesmtp/controller/EmailControllerTest.java index 875f443a..23cf51e6 100644 --- a/src/test/java/de/gessnerfl/fakesmtp/controller/EmailControllerTest.java +++ b/src/test/java/de/gessnerfl/fakesmtp/controller/EmailControllerTest.java @@ -8,6 +8,7 @@ import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.junit.MockitoJUnitRunner; +import org.springframework.boot.info.BuildProperties; import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; import org.springframework.ui.Model; @@ -23,21 +24,27 @@ public class EmailControllerTest { private Model model; @Mock private EmailRepository emailRepository; + @Mock + private BuildProperties buildProperties; @InjectMocks private EmailController sut; @Test public 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); 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 @@ -52,21 +59,26 @@ public void shouldReturnRedirectToFirstPageWhenRequestedPageIsOutOfRange() { assertEquals(EmailController.REDIRECT_EMAIL_LIST_VIEW, result); verify(emailRepository).findAll(argThat(matchPageable(3, 5))); - verifyNoMoreInteractions(emailRepository); + verifyNoMoreInteractions(emailRepository, buildProperties, model); } @Test public 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); 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 @@ -74,7 +86,7 @@ public void shouldRedirectToFirstPageWhenPageNumberIsBelowNull() { var result = sut.getAll(-1, 5, model); assertEquals(EmailController.REDIRECT_EMAIL_LIST_VIEW, result); - verifyNoInteractions(emailRepository); + verifyNoInteractions(emailRepository, buildProperties, model); } @Test @@ -82,7 +94,7 @@ public void shouldRedirectToFirstPageWhenPageSizeIsNull() { String result = sut.getAll(0, 0, model); assertEquals(EmailController.REDIRECT_EMAIL_LIST_VIEW, result); - verifyNoInteractions(emailRepository); + verifyNoInteractions(emailRepository, buildProperties, model); } @Test @@ -90,14 +102,16 @@ public void shouldRedirectToFirstPageWhenPageSizeIsBelowNull() { var result = sut.getAll(0, -1, model); assertEquals(EmailController.REDIRECT_EMAIL_LIST_VIEW, result); - verifyNoInteractions(emailRepository); + verifyNoInteractions(emailRepository, buildProperties, model); } @Test public 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); @@ -105,6 +119,9 @@ public void shouldReturnSingleEmailWhenIdIsValid() { 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 @@ -117,6 +134,8 @@ public void shouldReturnRedirectToListPageWhenIdIsNotValid() { assertEquals(EmailController.REDIRECT_EMAIL_LIST_VIEW, result); verify(emailRepository).findById(id); + verifyNoMoreInteractions(emailRepository); + verifyNoInteractions(buildProperties, model); } private Page createFirstPageEmail() { @@ -138,5 +157,7 @@ public void shouldDeleteEmailByItsIdAndFlushChangesSoThatDeleteIsApplied(){ 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..ce28cb18 100644 --- a/src/test/java/de/gessnerfl/fakesmtp/controller/EmailRestControllerMVCIntegrationTest.java +++ b/src/test/java/de/gessnerfl/fakesmtp/controller/EmailRestControllerMVCIntegrationTest.java @@ -1,13 +1,8 @@ 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; @@ -22,10 +17,6 @@ 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.Matchers.*; From 21d8e61710543bb78205dc19b00223f0b8f46005 Mon Sep 17 00:00:00 2001 From: Florian Gessner Date: Thu, 12 Nov 2020 21:47:40 +0100 Subject: [PATCH 2/5] #33: migrate to junit 5 --- build.gradle | 1 - .../gessnerfl/fakesmtp/TestResourceUtil.java | 2 +- ...onfigurationPropertiesIntegrationTest.java | 10 +- ...tiesWithAuthenticationIntegrationTest.java | 27 ++--- ...pertiesWithPersistenceIntegrationTest.java | 23 ++-- .../EmailControllerMVCIntegrationTest.java | 14 +-- .../controller/EmailControllerTest.java | 26 ++-- ...EmailRestControllerMVCIntegrationTest.java | 15 +-- .../controller/EmailRestControllerTest.java | 47 ++++---- .../EmailRepositoryIntegrationTest.java | 15 +-- .../fakesmtp/server/EmailServerTest.java | 10 +- .../BasicUsernamePasswordValidatorTest.java | 113 ++++++++++-------- .../server/impl/EmailFactoryTest.java | 11 +- .../fakesmtp/server/impl/EmailFilterTest.java | 10 +- .../server/impl/JavaMailSenderFacadeTest.java | 2 +- .../server/impl/MessageForwarderTest.java | 16 +-- .../impl/MessageListenerIntegrationTest.java | 15 +-- .../server/impl/MessageListenerTest.java | 32 ++--- .../fakesmtp/server/impl/RawDataTest.java | 7 +- .../impl/SmtpServerConfiguratorTest.java | 11 +- .../impl/SmtpServerFactoryImplTest.java | 16 +-- .../server/impl/SmtpServerImplTest.java | 2 +- .../service/EmailRetentionTimerTest.java | 8 +- .../fakesmtp/util/MediaTypeUtilTest.java | 8 +- 24 files changed, 227 insertions(+), 214 deletions(-) diff --git a/build.gradle b/build.gradle index f8943df3..c6467b5a 100644 --- a/build.gradle +++ b/build.gradle @@ -39,7 +39,6 @@ dependencies { implementation('org.webjars:material-design-icons:3.0.1') runtimeOnly('com.h2database:h2') - testImplementation('org.junit.vintage:junit-vintage-engine') testImplementation('org.springframework.boot:spring-boot-starter-test') testImplementation('org.ow2.asm:asm:9.0') testImplementation('org.apache.commons:commons-lang3:3.11') 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..e13936fd 100644 --- a/src/test/java/de/gessnerfl/fakesmtp/config/FakeSmtpConfigurationPropertiesIntegrationTest.java +++ b/src/test/java/de/gessnerfl/fakesmtp/config/FakeSmtpConfigurationPropertiesIntegrationTest.java @@ -1,18 +1,18 @@ 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 { diff --git a/src/test/java/de/gessnerfl/fakesmtp/config/FakeSmtpConfigurationPropertiesWithAuthenticationIntegrationTest.java b/src/test/java/de/gessnerfl/fakesmtp/config/FakeSmtpConfigurationPropertiesWithAuthenticationIntegrationTest.java index 371bfc40..0d005a67 100644 --- a/src/test/java/de/gessnerfl/fakesmtp/config/FakeSmtpConfigurationPropertiesWithAuthenticationIntegrationTest.java +++ b/src/test/java/de/gessnerfl/fakesmtp/config/FakeSmtpConfigurationPropertiesWithAuthenticationIntegrationTest.java @@ -1,20 +1,17 @@ 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 { @@ -23,12 +20,12 @@ public class FakeSmtpConfigurationPropertiesWithAuthenticationIntegrationTest { @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()); + 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..db17e1d3 100644 --- a/src/test/java/de/gessnerfl/fakesmtp/config/FakeSmtpConfigurationPropertiesWithPersistenceIntegrationTest.java +++ b/src/test/java/de/gessnerfl/fakesmtp/config/FakeSmtpConfigurationPropertiesWithPersistenceIntegrationTest.java @@ -1,20 +1,17 @@ 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 { @@ -23,10 +20,10 @@ public class FakeSmtpConfigurationPropertiesWithPersistenceIntegrationTest { @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()); + 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 c0cdbb07..859aec12 100644 --- a/src/test/java/de/gessnerfl/fakesmtp/controller/EmailControllerMVCIntegrationTest.java +++ b/src/test/java/de/gessnerfl/fakesmtp/controller/EmailControllerMVCIntegrationTest.java @@ -2,24 +2,24 @@ import de.gessnerfl.fakesmtp.model.Email; 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.autoconfigure.web.servlet.AutoConfigureMockMvc; 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 org.springframework.test.web.servlet.MockMvc; +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 { @@ -29,7 +29,7 @@ public class EmailControllerMVCIntegrationTest { @Autowired private MockMvc mockMvc; - @Before + @BeforeEach public void init(){ emailRepository.deleteAll(); } diff --git a/src/test/java/de/gessnerfl/fakesmtp/controller/EmailControllerTest.java b/src/test/java/de/gessnerfl/fakesmtp/controller/EmailControllerTest.java index 23cf51e6..e0117362 100644 --- a/src/test/java/de/gessnerfl/fakesmtp/controller/EmailControllerTest.java +++ b/src/test/java/de/gessnerfl/fakesmtp/controller/EmailControllerTest.java @@ -2,12 +2,13 @@ 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; @@ -15,10 +16,9 @@ import java.util.Optional; -import static org.junit.Assert.assertEquals; import static org.mockito.Mockito.*; -@RunWith(MockitoJUnitRunner.class) +@ExtendWith(MockitoExtension.class) public class EmailControllerTest { @Mock private Model model; @@ -38,7 +38,7 @@ public void shouldReturnEmailsPaged() { 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))); verify(model).addAttribute(EmailController.EMAIL_LIST_MODEL_NAME, page); @@ -56,7 +56,7 @@ 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, buildProperties, model); @@ -72,7 +72,7 @@ public void shouldNotRedirectToFirstPageWhenNoDataIsAvailable() { 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))); verify(model).addAttribute(EmailController.EMAIL_LIST_MODEL_NAME, page); @@ -85,7 +85,7 @@ public void shouldNotRedirectToFirstPageWhenNoDataIsAvailable() { public void shouldRedirectToFirstPageWhenPageNumberIsBelowNull() { var result = sut.getAll(-1, 5, model); - assertEquals(EmailController.REDIRECT_EMAIL_LIST_VIEW, result); + Assertions.assertEquals(EmailController.REDIRECT_EMAIL_LIST_VIEW, result); verifyNoInteractions(emailRepository, buildProperties, model); } @@ -93,7 +93,7 @@ public void shouldRedirectToFirstPageWhenPageNumberIsBelowNull() { public void shouldRedirectToFirstPageWhenPageSizeIsNull() { String result = sut.getAll(0, 0, model); - assertEquals(EmailController.REDIRECT_EMAIL_LIST_VIEW, result); + Assertions.assertEquals(EmailController.REDIRECT_EMAIL_LIST_VIEW, result); verifyNoInteractions(emailRepository, buildProperties, model); } @@ -101,7 +101,7 @@ public void shouldRedirectToFirstPageWhenPageSizeIsNull() { public void shouldRedirectToFirstPageWhenPageSizeIsBelowNull() { var result = sut.getAll(0, -1, model); - assertEquals(EmailController.REDIRECT_EMAIL_LIST_VIEW, result); + Assertions.assertEquals(EmailController.REDIRECT_EMAIL_LIST_VIEW, result); verifyNoInteractions(emailRepository, buildProperties, model); } @@ -115,7 +115,7 @@ public void shouldReturnSingleEmailWhenIdIsValid() { 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); @@ -131,7 +131,7 @@ public void shouldReturnRedirectToListPageWhenIdIsNotValid() { 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); diff --git a/src/test/java/de/gessnerfl/fakesmtp/controller/EmailRestControllerMVCIntegrationTest.java b/src/test/java/de/gessnerfl/fakesmtp/controller/EmailRestControllerMVCIntegrationTest.java index ce28cb18..8e0e12ff 100644 --- a/src/test/java/de/gessnerfl/fakesmtp/controller/EmailRestControllerMVCIntegrationTest.java +++ b/src/test/java/de/gessnerfl/fakesmtp/controller/EmailRestControllerMVCIntegrationTest.java @@ -3,30 +3,31 @@ import com.fasterxml.jackson.databind.ObjectMapper; import de.gessnerfl.fakesmtp.model.Email; 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.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.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 { @@ -37,7 +38,7 @@ public class EmailRestControllerMVCIntegrationTest { @Autowired private MockMvc mockMvc; - @Before + @BeforeEach public void init(){ emailRepository.deleteAll(); } diff --git a/src/test/java/de/gessnerfl/fakesmtp/controller/EmailRestControllerTest.java b/src/test/java/de/gessnerfl/fakesmtp/controller/EmailRestControllerTest.java index 5d520402..1496179a 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,11 +22,10 @@ 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) +@ExtendWith(MockitoExtension.class) public class EmailRestControllerTest { @Mock private EmailRepository emailRepository; @@ -100,28 +99,32 @@ public void shouldReturnResponseEntityForAttachment() { assertArrayEquals(fileContent, result.getBody().getByteArray()); } - @Test(expected = AttachmentNotFoundException.class) + @Test public void shouldThrowExceptionWhenNoAttachmentExistsForTheGivenId() { - var emailId = 123L; - var attachmentId = 456L; - var email = mock(Email.class); - var attachment = mock(EmailAttachment.class); - - when(email.getId()).thenReturn(789L); - when(attachment.getEmail()).thenReturn(email); - when(emailAttachmentRepository.findById(attachmentId)).thenReturn(Optional.of(attachment)); - - sut.getEmailAttachmentById(emailId, attachmentId); + assertThrows(AttachmentNotFoundException.class, () -> { + var emailId = 123L; + var attachmentId = 456L; + var email = mock(Email.class); + var attachment = mock(EmailAttachment.class); + + when(email.getId()).thenReturn(789L); + when(attachment.getEmail()).thenReturn(email); + when(emailAttachmentRepository.findById(attachmentId)).thenReturn(Optional.of(attachment)); + + sut.getEmailAttachmentById(emailId, attachmentId); + }); } - @Test(expected = AttachmentNotFoundException.class) + @Test public void shouldThrowExceptionWhenAttachmentExistsForTheGivenIdButTheEmailIdDoesNotMatch() { - var emailId = 123L; - var attachmentId = 456L; + assertThrows(AttachmentNotFoundException.class, () -> { + var emailId = 123L; + var attachmentId = 456L; - when(emailAttachmentRepository.findById(attachmentId)).thenReturn(Optional.empty()); + when(emailAttachmentRepository.findById(attachmentId)).thenReturn(Optional.empty()); - sut.getEmailAttachmentById(emailId, attachmentId); + sut.getEmailAttachmentById(emailId, attachmentId); + }); } @Test diff --git a/src/test/java/de/gessnerfl/fakesmtp/repository/EmailRepositoryIntegrationTest.java b/src/test/java/de/gessnerfl/fakesmtp/repository/EmailRepositoryIntegrationTest.java index 199ceb07..51ec7d9d 100644 --- a/src/test/java/de/gessnerfl/fakesmtp/repository/EmailRepositoryIntegrationTest.java +++ b/src/test/java/de/gessnerfl/fakesmtp/repository/EmailRepositoryIntegrationTest.java @@ -4,27 +4,28 @@ 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 { @@ -32,7 +33,7 @@ public class EmailRepositoryIntegrationTest { @Autowired private EmailRepository sut; - @Before + @BeforeEach public void init(){ sut.deleteAll(); } diff --git a/src/test/java/de/gessnerfl/fakesmtp/server/EmailServerTest.java b/src/test/java/de/gessnerfl/fakesmtp/server/EmailServerTest.java index 421acbfa..41037b8f 100644 --- a/src/test/java/de/gessnerfl/fakesmtp/server/EmailServerTest.java +++ b/src/test/java/de/gessnerfl/fakesmtp/server/EmailServerTest.java @@ -1,16 +1,16 @@ 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) +@ExtendWith(MockitoExtension.class) public class EmailServerTest { @Mock 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..c0e6cff7 100644 --- a/src/test/java/de/gessnerfl/fakesmtp/server/impl/BasicUsernamePasswordValidatorTest.java +++ b/src/test/java/de/gessnerfl/fakesmtp/server/impl/BasicUsernamePasswordValidatorTest.java @@ -1,18 +1,19 @@ 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) +@ExtendWith(MockitoExtension.class) public class BasicUsernamePasswordValidatorTest { @Mock @@ -37,61 +38,71 @@ 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 + public 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 + public 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 { - var username = "username"; - var password = "password"; - when(fakeSmtpConfigurationProperties.getAuthentication()).thenReturn(null); - - sut.login(username, password); + @Test + public void shouldThrowNullPointerExceptionWhenAuthenticationIsMissing() { + Assertions.assertThrows(NullPointerException.class, () -> { + var username = "username"; + var password = "password"; + when(fakeSmtpConfigurationProperties.getAuthentication()).thenReturn(null); + + sut.login(username, password); + }); } - @Test(expected = NullPointerException.class) - public void shouldThrowNullPointerExceptionWhenUsernameIsMissingInAuthentication() throws Exception { - 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); + @Test + public void shouldThrowNullPointerExceptionWhenUsernameIsMissingInAuthentication() { + Assertions.assertThrows(NullPointerException.class, () -> { + 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); + }); } - @Test(expected = NullPointerException.class) - public void shouldThrowNullPointerExceptionWhenPasswordIsMissingInAuthentication() throws Exception { - var username = "username"; - var password = "password"; - var authentication = mock(FakeSmtpConfigurationProperties.Authentication.class); - when(authentication.getUsername()).thenReturn(username); - when(authentication.getPassword()).thenReturn(null); - when(fakeSmtpConfigurationProperties.getAuthentication()).thenReturn(authentication); - - sut.login(username, password); + @Test + public void shouldThrowNullPointerExceptionWhenPasswordIsMissingInAuthentication() { + Assertions.assertThrows(NullPointerException.class, () -> { + var username = "username"; + var password = "password"; + var authentication = mock(FakeSmtpConfigurationProperties.Authentication.class); + when(authentication.getUsername()).thenReturn(username); + when(authentication.getPassword()).thenReturn(null); + when(fakeSmtpConfigurationProperties.getAuthentication()).thenReturn(authentication); + + 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..7961e74f 100644 --- a/src/test/java/de/gessnerfl/fakesmtp/server/impl/EmailFactoryTest.java +++ b/src/test/java/de/gessnerfl/fakesmtp/server/impl/EmailFactoryTest.java @@ -5,21 +5,22 @@ 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) +@ExtendWith(MockitoExtension.class) public class EmailFactoryTest { private static final String SENDER = "sender"; 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..e9e0771e 100644 --- a/src/test/java/de/gessnerfl/fakesmtp/server/impl/EmailFilterTest.java +++ b/src/test/java/de/gessnerfl/fakesmtp/server/impl/EmailFilterTest.java @@ -1,17 +1,17 @@ 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) +@ExtendWith(MockitoExtension.class) public class EmailFilterTest { private static final String TEST_EMAIL_ADDRESS_1 = "john@doe.com"; private static final String TEST_EMAIL_ADDRESS_2 = "jane@doe.com"; 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..262520fb 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; 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..ecdebbe6 100644 --- a/src/test/java/de/gessnerfl/fakesmtp/server/impl/MessageForwarderTest.java +++ b/src/test/java/de/gessnerfl/fakesmtp/server/impl/MessageForwarderTest.java @@ -1,22 +1,22 @@ 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) +@ExtendWith(MockitoExtension.class) public class MessageForwarderTest { @Mock @@ -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..b2e4fac3 100644 --- a/src/test/java/de/gessnerfl/fakesmtp/server/impl/MessageListenerIntegrationTest.java +++ b/src/test/java/de/gessnerfl/fakesmtp/server/impl/MessageListenerIntegrationTest.java @@ -2,24 +2,25 @@ 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 { private static final String SENDER = "sender"; @@ -31,7 +32,7 @@ public class MessageListenerIntegrationTest { @Autowired private MessageListener sut; - @Before + @BeforeEach public void setup(){ emailRepository.deleteAll(); } 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..6fc690c5 100644 --- a/src/test/java/de/gessnerfl/fakesmtp/server/impl/MessageListenerTest.java +++ b/src/test/java/de/gessnerfl/fakesmtp/server/impl/MessageListenerTest.java @@ -2,22 +2,22 @@ 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) +@ExtendWith(MockitoExtension.class) public class MessageListenerTest { @Mock @@ -62,18 +62,20 @@ public void shouldCreateEmailEntityAndStoreItInDatabaseWhenEmailIsDelivered() th verify(messageForwarder).forward(rawData); } - @Test(expected = IOException.class) - public void shouldThrowExceptionWhenEmailEntityCannotBeCreatedWhenEmailIsDelivered() throws IOException { - var from = "from"; - var to = "to"; - var content = "content".getBytes(StandardCharsets.UTF_8); - var contentStream = new ByteArrayInputStream(content); + @Test + public void shouldThrowExceptionWhenEmailEntityCannotBeCreatedWhenEmailIsDelivered() { + assertThrows(IOException.class, () -> { + var from = "from"; + var to = "to"; + var content = "content".getBytes(StandardCharsets.UTF_8); + var contentStream = new ByteArrayInputStream(content); - when(emailFactory.convert(any(RawData.class))).thenThrow(new IOException("foo")); + when(emailFactory.convert(any(RawData.class))).thenThrow(new IOException("foo")); - sut.deliver(from, to, contentStream); + 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..087757d0 100644 --- a/src/test/java/de/gessnerfl/fakesmtp/server/impl/RawDataTest.java +++ b/src/test/java/de/gessnerfl/fakesmtp/server/impl/RawDataTest.java @@ -1,12 +1,11 @@ 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 { @Test @@ -14,7 +13,7 @@ public 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..36600329 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,11 +14,12 @@ 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) +@ExtendWith(MockitoExtension.class) public class SmtpServerConfiguratorTest { @Mock 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..3c4e51c0 100644 --- a/src/test/java/de/gessnerfl/fakesmtp/server/impl/SmtpServerFactoryImplTest.java +++ b/src/test/java/de/gessnerfl/fakesmtp/server/impl/SmtpServerFactoryImplTest.java @@ -1,17 +1,17 @@ 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) +@ExtendWith(MockitoExtension.class) public class SmtpServerFactoryImplTest { private final int PORT = 25; @@ -27,9 +27,9 @@ public class SmtpServerFactoryImplTest { public 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..6a94b7e0 100644 --- a/src/test/java/de/gessnerfl/fakesmtp/server/impl/SmtpServerImplTest.java +++ b/src/test/java/de/gessnerfl/fakesmtp/server/impl/SmtpServerImplTest.java @@ -1,6 +1,6 @@ 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; diff --git a/src/test/java/de/gessnerfl/fakesmtp/service/EmailRetentionTimerTest.java b/src/test/java/de/gessnerfl/fakesmtp/service/EmailRetentionTimerTest.java index f8825e20..6990d093 100644 --- a/src/test/java/de/gessnerfl/fakesmtp/service/EmailRetentionTimerTest.java +++ b/src/test/java/de/gessnerfl/fakesmtp/service/EmailRetentionTimerTest.java @@ -2,16 +2,16 @@ 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) +@ExtendWith(MockitoExtension.class) public class EmailRetentionTimerTest { @Mock diff --git a/src/test/java/de/gessnerfl/fakesmtp/util/MediaTypeUtilTest.java b/src/test/java/de/gessnerfl/fakesmtp/util/MediaTypeUtilTest.java index 3cc70394..170c15f4 100644 --- a/src/test/java/de/gessnerfl/fakesmtp/util/MediaTypeUtilTest.java +++ b/src/test/java/de/gessnerfl/fakesmtp/util/MediaTypeUtilTest.java @@ -1,12 +1,12 @@ 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; @@ -15,7 +15,7 @@ public class MediaTypeUtilTest { private MediaTypeUtil sut; - @Before + @BeforeEach public void init(){ servletContext = mock(ServletContext.class); From 67c884bc5af0c0f805b0d94f9ee0da52d8a24353 Mon Sep 17 00:00:00 2001 From: Florian Gessner Date: Thu, 12 Nov 2020 23:31:23 +0100 Subject: [PATCH 3/5] #33: fix sonar issues --- ...onfigurationPropertiesIntegrationTest.java | 4 ++-- ...tiesWithAuthenticationIntegrationTest.java | 4 ++-- ...pertiesWithPersistenceIntegrationTest.java | 4 ++-- .../EmailControllerMVCIntegrationTest.java | 16 ++++++------- .../controller/EmailControllerTest.java | 20 ++++++++-------- ...EmailRestControllerMVCIntegrationTest.java | 24 +++++++++---------- .../controller/EmailRestControllerTest.java | 14 +++++------ .../EmailRepositoryIntegrationTest.java | 8 +++---- .../fakesmtp/server/EmailServerTest.java | 8 +++---- .../BasicUsernamePasswordValidatorTest.java | 14 +++++------ .../server/impl/EmailFactoryTest.java | 20 ++++++++-------- .../fakesmtp/server/impl/EmailFilterTest.java | 14 +++++------ .../server/impl/JavaMailSenderFacadeTest.java | 10 ++++---- .../server/impl/MessageForwarderTest.java | 8 +++---- .../impl/MessageListenerIntegrationTest.java | 10 ++++---- .../server/impl/MessageListenerTest.java | 21 ++++++++-------- .../fakesmtp/server/impl/RawDataTest.java | 4 ++-- .../impl/SmtpServerConfiguratorTest.java | 14 +++++------ .../impl/SmtpServerFactoryImplTest.java | 4 ++-- .../server/impl/SmtpServerImplTest.java | 4 ++-- .../service/EmailRetentionTimerTest.java | 10 ++++---- .../fakesmtp/util/MediaTypeUtilTest.java | 10 ++++---- 22 files changed, 123 insertions(+), 122 deletions(-) diff --git a/src/test/java/de/gessnerfl/fakesmtp/config/FakeSmtpConfigurationPropertiesIntegrationTest.java b/src/test/java/de/gessnerfl/fakesmtp/config/FakeSmtpConfigurationPropertiesIntegrationTest.java index e13936fd..7565aa1f 100644 --- a/src/test/java/de/gessnerfl/fakesmtp/config/FakeSmtpConfigurationPropertiesIntegrationTest.java +++ b/src/test/java/de/gessnerfl/fakesmtp/config/FakeSmtpConfigurationPropertiesIntegrationTest.java @@ -14,13 +14,13 @@ @ActiveProfiles({"integrationtest","config_integrationtest"}) @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 0d005a67..de72db4b 100644 --- a/src/test/java/de/gessnerfl/fakesmtp/config/FakeSmtpConfigurationPropertiesWithAuthenticationIntegrationTest.java +++ b/src/test/java/de/gessnerfl/fakesmtp/config/FakeSmtpConfigurationPropertiesWithAuthenticationIntegrationTest.java @@ -13,13 +13,13 @@ @ActiveProfiles({"integrationtest", "config_with_auth_integrationtest"}) @ExtendWith(SpringExtension.class) @SpringBootTest -public class FakeSmtpConfigurationPropertiesWithAuthenticationIntegrationTest { +class FakeSmtpConfigurationPropertiesWithAuthenticationIntegrationTest { @Autowired private FakeSmtpConfigurationProperties sut; @Test - public void shouldLoadConfigurationParameters() throws Exception { + void shouldLoadConfigurationParameters() throws Exception { Assertions.assertEquals(1234, sut.getPort().intValue()); Assertions.assertEquals(InetAddress.getByName("127.0.0.1"), sut.getBindAddress()); Assertions.assertNotNull(sut.getAuthentication()); diff --git a/src/test/java/de/gessnerfl/fakesmtp/config/FakeSmtpConfigurationPropertiesWithPersistenceIntegrationTest.java b/src/test/java/de/gessnerfl/fakesmtp/config/FakeSmtpConfigurationPropertiesWithPersistenceIntegrationTest.java index db17e1d3..5f6a0839 100644 --- a/src/test/java/de/gessnerfl/fakesmtp/config/FakeSmtpConfigurationPropertiesWithPersistenceIntegrationTest.java +++ b/src/test/java/de/gessnerfl/fakesmtp/config/FakeSmtpConfigurationPropertiesWithPersistenceIntegrationTest.java @@ -13,13 +13,13 @@ @ActiveProfiles({"integrationtest","config_with_persistence_integrationtest"}) @ExtendWith(SpringExtension.class) @SpringBootTest -public class FakeSmtpConfigurationPropertiesWithPersistenceIntegrationTest { +class FakeSmtpConfigurationPropertiesWithPersistenceIntegrationTest { @Autowired private FakeSmtpConfigurationProperties sut; @Test - public void shouldLoadConfigurationParameters() throws Exception { + void shouldLoadConfigurationParameters() throws Exception { Assertions.assertEquals(1234, sut.getPort().intValue()); Assertions.assertEquals(InetAddress.getByName("127.0.0.1"), sut.getBindAddress()); Assertions.assertNull(sut.getAuthentication()); diff --git a/src/test/java/de/gessnerfl/fakesmtp/controller/EmailControllerMVCIntegrationTest.java b/src/test/java/de/gessnerfl/fakesmtp/controller/EmailControllerMVCIntegrationTest.java index 859aec12..15bf0ee8 100644 --- a/src/test/java/de/gessnerfl/fakesmtp/controller/EmailControllerMVCIntegrationTest.java +++ b/src/test/java/de/gessnerfl/fakesmtp/controller/EmailControllerMVCIntegrationTest.java @@ -22,7 +22,7 @@ @ExtendWith(SpringExtension.class) @SpringBootTest @AutoConfigureMockMvc -public class EmailControllerMVCIntegrationTest { +class EmailControllerMVCIntegrationTest { @Autowired private EmailRepository emailRepository; @@ -30,12 +30,12 @@ public class EmailControllerMVCIntegrationTest { private MockMvc mockMvc; @BeforeEach - public void init(){ + 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))) @@ -44,7 +44,7 @@ public void shouldReturnEmptyListWhenNoEmailsAreAvailable() throws Exception { } @Test - public void shouldReturnListOfEmailsPagedWhenEmailsAreAvailable() throws Exception { + void shouldReturnListOfEmailsPagedWhenEmailsAreAvailable() throws Exception { var email1 = createRandomEmail(5); var email2 = createRandomEmail(2); var email3 = createRandomEmail(1); @@ -65,7 +65,7 @@ public void shouldReturnListOfEmailsPagedWhenEmailsAreAvailable() throws Excepti } @Test - public void shouldReturnFirstPageWhenGivenPageIsOutOfRange() throws Exception { + void shouldReturnFirstPageWhenGivenPageIsOutOfRange() throws Exception { createRandomEmail(1); this.mockMvc.perform(get("/email?page=1&size=2")) @@ -75,7 +75,7 @@ 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())) @@ -86,7 +86,7 @@ public void shouldReturnMailById() throws Exception { } @Test - public void shouldReturnErrorWhenMailIdIsNotValid() throws Exception { + void shouldReturnErrorWhenMailIdIsNotValid() throws Exception { this.mockMvc.perform(get("/email/123")) .andExpect(redirectedUrl("/email")) .andExpect(model().attributeDoesNotExist("mails", "mail")) @@ -94,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 e0117362..37635960 100644 --- a/src/test/java/de/gessnerfl/fakesmtp/controller/EmailControllerTest.java +++ b/src/test/java/de/gessnerfl/fakesmtp/controller/EmailControllerTest.java @@ -19,7 +19,7 @@ import static org.mockito.Mockito.*; @ExtendWith(MockitoExtension.class) -public class EmailControllerTest { +class EmailControllerTest { @Mock private Model model; @Mock @@ -30,7 +30,7 @@ public class EmailControllerTest { 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); @@ -48,7 +48,7 @@ public void shouldReturnEmailsPaged() { } @Test - public void shouldReturnRedirectToFirstPageWhenRequestedPageIsOutOfRange() { + void shouldReturnRedirectToFirstPageWhenRequestedPageIsOutOfRange() { var page = mock(Page.class); when(page.getTotalPages()).thenReturn(2); when(page.getNumber()).thenReturn(3); @@ -63,7 +63,7 @@ public void shouldReturnRedirectToFirstPageWhenRequestedPageIsOutOfRange() { } @Test - public void shouldNotRedirectToFirstPageWhenNoDataIsAvailable() { + void shouldNotRedirectToFirstPageWhenNoDataIsAvailable() { final String appVersion = "appVersion"; var page = mock(Page.class); when(page.getNumber()).thenReturn(0); @@ -82,7 +82,7 @@ public void shouldNotRedirectToFirstPageWhenNoDataIsAvailable() { } @Test - public void shouldRedirectToFirstPageWhenPageNumberIsBelowNull() { + void shouldRedirectToFirstPageWhenPageNumberIsBelowNull() { var result = sut.getAll(-1, 5, model); Assertions.assertEquals(EmailController.REDIRECT_EMAIL_LIST_VIEW, result); @@ -90,7 +90,7 @@ public void shouldRedirectToFirstPageWhenPageNumberIsBelowNull() { } @Test - public void shouldRedirectToFirstPageWhenPageSizeIsNull() { + void shouldRedirectToFirstPageWhenPageSizeIsNull() { String result = sut.getAll(0, 0, model); Assertions.assertEquals(EmailController.REDIRECT_EMAIL_LIST_VIEW, result); @@ -98,7 +98,7 @@ public void shouldRedirectToFirstPageWhenPageSizeIsNull() { } @Test - public void shouldRedirectToFirstPageWhenPageSizeIsBelowNull() { + void shouldRedirectToFirstPageWhenPageSizeIsBelowNull() { var result = sut.getAll(0, -1, model); Assertions.assertEquals(EmailController.REDIRECT_EMAIL_LIST_VIEW, result); @@ -106,7 +106,7 @@ public void shouldRedirectToFirstPageWhenPageSizeIsBelowNull() { } @Test - public void shouldReturnSingleEmailWhenIdIsValid() { + void shouldReturnSingleEmailWhenIdIsValid() { final String appVersion = "appVersion"; var id = 12L; var mail = mock(Email.class); @@ -125,7 +125,7 @@ public void shouldReturnSingleEmailWhenIdIsValid() { } @Test - public void shouldReturnRedirectToListPageWhenIdIsNotValid() { + void shouldReturnRedirectToListPageWhenIdIsNotValid() { var id = 12L; when(emailRepository.findById(id)).thenReturn(Optional.empty()); @@ -150,7 +150,7 @@ private ArgumentMatcher matchPageable(int page, int size) { } @Test - public void shouldDeleteEmailByItsIdAndFlushChangesSoThatDeleteIsApplied(){ + void shouldDeleteEmailByItsIdAndFlushChangesSoThatDeleteIsApplied(){ var emailId = 123L; sut.deleteEmailById(emailId); diff --git a/src/test/java/de/gessnerfl/fakesmtp/controller/EmailRestControllerMVCIntegrationTest.java b/src/test/java/de/gessnerfl/fakesmtp/controller/EmailRestControllerMVCIntegrationTest.java index 8e0e12ff..ba9a188b 100644 --- a/src/test/java/de/gessnerfl/fakesmtp/controller/EmailRestControllerMVCIntegrationTest.java +++ b/src/test/java/de/gessnerfl/fakesmtp/controller/EmailRestControllerMVCIntegrationTest.java @@ -30,7 +30,7 @@ @ExtendWith(SpringExtension.class) @SpringBootTest @AutoConfigureMockMvc -public class EmailRestControllerMVCIntegrationTest { +class EmailRestControllerMVCIntegrationTest { @Autowired private EmailRepository emailRepository; @@ -39,12 +39,12 @@ public class EmailRestControllerMVCIntegrationTest { private MockMvc mockMvc; @BeforeEach - public void init(){ + 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()); @@ -53,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); @@ -66,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); @@ -79,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(); @@ -90,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(); @@ -101,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); @@ -120,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")) @@ -128,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())) @@ -136,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 1496179a..49cdc387 100644 --- a/src/test/java/de/gessnerfl/fakesmtp/controller/EmailRestControllerTest.java +++ b/src/test/java/de/gessnerfl/fakesmtp/controller/EmailRestControllerTest.java @@ -26,7 +26,7 @@ import static org.mockito.Mockito.*; @ExtendWith(MockitoExtension.class) -public class EmailRestControllerTest { +class EmailRestControllerTest { @Mock private EmailRepository emailRepository; @Mock @@ -40,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); @@ -52,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)); @@ -74,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,7 +100,7 @@ public void shouldReturnResponseEntityForAttachment() { } @Test - public void shouldThrowExceptionWhenNoAttachmentExistsForTheGivenId() { + void shouldThrowExceptionWhenNoAttachmentExistsForTheGivenId() { assertThrows(AttachmentNotFoundException.class, () -> { var emailId = 123L; var attachmentId = 456L; @@ -116,7 +116,7 @@ public void shouldThrowExceptionWhenNoAttachmentExistsForTheGivenId() { } @Test - public void shouldThrowExceptionWhenAttachmentExistsForTheGivenIdButTheEmailIdDoesNotMatch() { + void shouldThrowExceptionWhenAttachmentExistsForTheGivenIdButTheEmailIdDoesNotMatch() { assertThrows(AttachmentNotFoundException.class, () -> { var emailId = 123L; var attachmentId = 456L; @@ -128,7 +128,7 @@ public void shouldThrowExceptionWhenAttachmentExistsForTheGivenIdButTheEmailIdDo } @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 51ec7d9d..0e331833 100644 --- a/src/test/java/de/gessnerfl/fakesmtp/repository/EmailRepositoryIntegrationTest.java +++ b/src/test/java/de/gessnerfl/fakesmtp/repository/EmailRepositoryIntegrationTest.java @@ -27,19 +27,19 @@ @ActiveProfiles("integrationtest") @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; @BeforeEach - public void init(){ + void init(){ sut.deleteAll(); } @Test - public void shouldDeleteEmailsWhichExceedTheRetentionLimitOfMaximumNumberOfEmails(){ + void shouldDeleteEmailsWhichExceedTheRetentionLimitOfMaximumNumberOfEmails(){ var mail1 = createRandomEmail(5); var mail2 = createRandomEmail(4); var mail3 = createRandomEmail(3); @@ -59,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 41037b8f..1586a886 100644 --- a/src/test/java/de/gessnerfl/fakesmtp/server/EmailServerTest.java +++ b/src/test/java/de/gessnerfl/fakesmtp/server/EmailServerTest.java @@ -11,7 +11,7 @@ import static org.mockito.Mockito.*; @ExtendWith(MockitoExtension.class) -public class EmailServerTest { +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 c0e6cff7..937f88d1 100644 --- a/src/test/java/de/gessnerfl/fakesmtp/server/impl/BasicUsernamePasswordValidatorTest.java +++ b/src/test/java/de/gessnerfl/fakesmtp/server/impl/BasicUsernamePasswordValidatorTest.java @@ -14,7 +14,7 @@ import static org.mockito.Mockito.when; @ExtendWith(MockitoExtension.class) -public class BasicUsernamePasswordValidatorTest { +class BasicUsernamePasswordValidatorTest { @Mock private FakeSmtpConfigurationProperties fakeSmtpConfigurationProperties; @@ -24,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); @@ -39,7 +39,7 @@ public void shouldSuccessfullyValidateCorrectUsernameAndPassword() throws Except } @Test - public void shouldThrowLoginFailedExceptionWhenUsernameIsNotValid() { + void shouldThrowLoginFailedExceptionWhenUsernameIsNotValid() { Assertions.assertThrows(LoginFailedException.class, () -> { var username = "username"; var invalidUsername = "inValidUsername"; @@ -53,7 +53,7 @@ public void shouldThrowLoginFailedExceptionWhenUsernameIsNotValid() { } @Test - public void shouldThrowLoginFailedExceptionWhenPasswordIsNotValid() { + void shouldThrowLoginFailedExceptionWhenPasswordIsNotValid() { Assertions.assertThrows(LoginFailedException.class, () -> { var username = "username"; var password = "password"; @@ -68,7 +68,7 @@ public void shouldThrowLoginFailedExceptionWhenPasswordIsNotValid() { } @Test - public void shouldThrowNullPointerExceptionWhenAuthenticationIsMissing() { + void shouldThrowNullPointerExceptionWhenAuthenticationIsMissing() { Assertions.assertThrows(NullPointerException.class, () -> { var username = "username"; var password = "password"; @@ -79,7 +79,7 @@ public void shouldThrowNullPointerExceptionWhenAuthenticationIsMissing() { } @Test - public void shouldThrowNullPointerExceptionWhenUsernameIsMissingInAuthentication() { + void shouldThrowNullPointerExceptionWhenUsernameIsMissingInAuthentication() { Assertions.assertThrows(NullPointerException.class, () -> { var username = "username"; var password = "password"; @@ -92,7 +92,7 @@ public void shouldThrowNullPointerExceptionWhenUsernameIsMissingInAuthentication } @Test - public void shouldThrowNullPointerExceptionWhenPasswordIsMissingInAuthentication() { + void shouldThrowNullPointerExceptionWhenPasswordIsMissingInAuthentication() { Assertions.assertThrows(NullPointerException.class, () -> { var username = "username"; var password = "password"; 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 7961e74f..ca8ddb64 100644 --- a/src/test/java/de/gessnerfl/fakesmtp/server/impl/EmailFactoryTest.java +++ b/src/test/java/de/gessnerfl/fakesmtp/server/impl/EmailFactoryTest.java @@ -21,7 +21,7 @@ import static org.mockito.Mockito.when; @ExtendWith(MockitoExtension.class) -public class EmailFactoryTest { +class EmailFactoryTest { private static final String SENDER = "sender"; private static final String RECEIVER = "receiver"; @@ -33,7 +33,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); @@ -57,7 +57,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); @@ -81,7 +81,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); @@ -105,7 +105,7 @@ public void shouldCreateEmailForEmlFileWithSubjectAndWithoutContentType() throws } @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); @@ -129,7 +129,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); @@ -152,7 +152,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); @@ -177,7 +177,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); @@ -201,7 +201,7 @@ public void shouldCreateMailForMultipartWithoutContentTypeHtml() throws Exceptio } @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); @@ -226,7 +226,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 e9e0771e..c1e97254 100644 --- a/src/test/java/de/gessnerfl/fakesmtp/server/impl/EmailFilterTest.java +++ b/src/test/java/de/gessnerfl/fakesmtp/server/impl/EmailFilterTest.java @@ -12,7 +12,7 @@ import static org.mockito.Mockito.*; @ExtendWith(MockitoExtension.class) -public class EmailFilterTest { +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 262520fb..bc0194c4 100644 --- a/src/test/java/de/gessnerfl/fakesmtp/server/impl/JavaMailSenderFacadeTest.java +++ b/src/test/java/de/gessnerfl/fakesmtp/server/impl/JavaMailSenderFacadeTest.java @@ -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 ecdebbe6..d7dd8776 100644 --- a/src/test/java/de/gessnerfl/fakesmtp/server/impl/MessageForwarderTest.java +++ b/src/test/java/de/gessnerfl/fakesmtp/server/impl/MessageForwarderTest.java @@ -17,7 +17,7 @@ import static org.mockito.Mockito.*; @ExtendWith(MockitoExtension.class) -public class MessageForwarderTest { +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"; 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 b2e4fac3..b4787cf8 100644 --- a/src/test/java/de/gessnerfl/fakesmtp/server/impl/MessageListenerIntegrationTest.java +++ b/src/test/java/de/gessnerfl/fakesmtp/server/impl/MessageListenerIntegrationTest.java @@ -22,7 +22,7 @@ @ActiveProfiles("integrationtest") @ExtendWith(SpringExtension.class) @SpringBootTest -public class MessageListenerIntegrationTest { +class MessageListenerIntegrationTest { private static final String SENDER = "sender"; private static final String RECEIVER = "receiver"; @@ -33,12 +33,12 @@ public class MessageListenerIntegrationTest { private MessageListener sut; @BeforeEach - public void setup(){ + 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); @@ -62,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); @@ -86,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 6fc690c5..e44113df 100644 --- a/src/test/java/de/gessnerfl/fakesmtp/server/impl/MessageListenerTest.java +++ b/src/test/java/de/gessnerfl/fakesmtp/server/impl/MessageListenerTest.java @@ -18,7 +18,7 @@ import static org.mockito.Mockito.*; @ExtendWith(MockitoExtension.class) -public class MessageListenerTest { +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"; @@ -63,14 +63,15 @@ public void shouldCreateEmailEntityAndStoreItInDatabaseWhenEmailIsDelivered() th } @Test - public void shouldThrowExceptionWhenEmailEntityCannotBeCreatedWhenEmailIsDelivered() { - assertThrows(IOException.class, () -> { - var from = "from"; - var to = "to"; - var content = "content".getBytes(StandardCharsets.UTF_8); - var contentStream = new ByteArrayInputStream(content); + void shouldThrowExceptionWhenEmailEntityCannotBeCreatedWhenEmailIsDelivered() throws IOException { + var from = "from"; + var to = "to"; + var content = "content".getBytes(StandardCharsets.UTF_8); + var contentStream = new ByteArrayInputStream(content); + + when(emailFactory.convert(any(RawData.class))).thenThrow(new IOException("foo")); - when(emailFactory.convert(any(RawData.class))).thenThrow(new IOException("foo")); + assertThrows(IOException.class, () -> { sut.deliver(from, to, contentStream); 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 087757d0..7c0fa7ef 100644 --- a/src/test/java/de/gessnerfl/fakesmtp/server/impl/RawDataTest.java +++ b/src/test/java/de/gessnerfl/fakesmtp/server/impl/RawDataTest.java @@ -6,10 +6,10 @@ import javax.mail.internet.MimeMessage; -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(); 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 36600329..8fba39ef 100644 --- a/src/test/java/de/gessnerfl/fakesmtp/server/impl/SmtpServerConfiguratorTest.java +++ b/src/test/java/de/gessnerfl/fakesmtp/server/impl/SmtpServerConfiguratorTest.java @@ -20,7 +20,7 @@ import static org.mockito.Mockito.*; @ExtendWith(MockitoExtension.class) -public class SmtpServerConfiguratorTest { +class SmtpServerConfiguratorTest { @Mock private FakeSmtpConfigurationProperties fakeSmtpConfigurationProperties; @@ -33,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); @@ -49,7 +49,7 @@ public void shouldConfigureBasicParameters(){ } @Test - public void shouldConfigureAuthenticationWhenAuthenticationIsConfiguredProperly(){ + void shouldConfigureAuthenticationWhenAuthenticationIsConfiguredProperly(){ var username = "username"; var password = "password"; var authentication = mock(FakeSmtpConfigurationProperties.Authentication.class); @@ -73,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); @@ -87,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); @@ -101,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); @@ -117,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 3c4e51c0..e31d51e3 100644 --- a/src/test/java/de/gessnerfl/fakesmtp/server/impl/SmtpServerFactoryImplTest.java +++ b/src/test/java/de/gessnerfl/fakesmtp/server/impl/SmtpServerFactoryImplTest.java @@ -12,7 +12,7 @@ import static org.mockito.Mockito.verify; @ExtendWith(MockitoExtension.class) -public class SmtpServerFactoryImplTest { +class SmtpServerFactoryImplTest { private final int PORT = 25; @Mock @@ -24,7 +24,7 @@ public class SmtpServerFactoryImplTest { private SmtpServerFactoryImpl sut; @Test - public void shouldCreateAndConfigureNewInsance(){ + void shouldCreateAndConfigureNewInsance(){ var smtpServer = sut.create(); MatcherAssert.assertThat(smtpServer, instanceOf(SmtpServerImpl.class)); 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 6a94b7e0..e18f0741 100644 --- a/src/test/java/de/gessnerfl/fakesmtp/server/impl/SmtpServerImplTest.java +++ b/src/test/java/de/gessnerfl/fakesmtp/server/impl/SmtpServerImplTest.java @@ -6,10 +6,10 @@ 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 6990d093..224fde3f 100644 --- a/src/test/java/de/gessnerfl/fakesmtp/service/EmailRetentionTimerTest.java +++ b/src/test/java/de/gessnerfl/fakesmtp/service/EmailRetentionTimerTest.java @@ -12,7 +12,7 @@ import static org.mockito.Mockito.*; @ExtendWith(MockitoExtension.class) -public class EmailRetentionTimerTest { +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 170c15f4..e72f58d3 100644 --- a/src/test/java/de/gessnerfl/fakesmtp/util/MediaTypeUtilTest.java +++ b/src/test/java/de/gessnerfl/fakesmtp/util/MediaTypeUtilTest.java @@ -10,20 +10,20 @@ import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; -public class MediaTypeUtilTest { +class MediaTypeUtilTest { private ServletContext servletContext; private MediaTypeUtil sut; @BeforeEach - public void init(){ + 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"); From 25fd169e5515bd092c3da1453e505a9cdda71984 Mon Sep 17 00:00:00 2001 From: Florian Gessner Date: Fri, 13 Nov 2020 08:15:14 +0100 Subject: [PATCH 4/5] #33: Sonar fixes --- .../controller/EmailRestControllerTest.java | 24 ++++++------- .../BasicUsernamePasswordValidatorTest.java | 34 +++++++++---------- .../server/impl/EmailFactoryTest.java | 27 ++++----------- 3 files changed, 36 insertions(+), 49 deletions(-) diff --git a/src/test/java/de/gessnerfl/fakesmtp/controller/EmailRestControllerTest.java b/src/test/java/de/gessnerfl/fakesmtp/controller/EmailRestControllerTest.java index 49cdc387..81ca97fa 100644 --- a/src/test/java/de/gessnerfl/fakesmtp/controller/EmailRestControllerTest.java +++ b/src/test/java/de/gessnerfl/fakesmtp/controller/EmailRestControllerTest.java @@ -101,28 +101,28 @@ void shouldReturnResponseEntityForAttachment() { @Test void shouldThrowExceptionWhenNoAttachmentExistsForTheGivenId() { - assertThrows(AttachmentNotFoundException.class, () -> { - var emailId = 123L; - var attachmentId = 456L; - var email = mock(Email.class); - var attachment = mock(EmailAttachment.class); + var emailId = 123L; + var attachmentId = 456L; + var email = mock(Email.class); + var attachment = mock(EmailAttachment.class); - when(email.getId()).thenReturn(789L); - when(attachment.getEmail()).thenReturn(email); - when(emailAttachmentRepository.findById(attachmentId)).thenReturn(Optional.of(attachment)); + when(email.getId()).thenReturn(789L); + when(attachment.getEmail()).thenReturn(email); + when(emailAttachmentRepository.findById(attachmentId)).thenReturn(Optional.of(attachment)); + assertThrows(AttachmentNotFoundException.class, () -> { sut.getEmailAttachmentById(emailId, attachmentId); }); } @Test void shouldThrowExceptionWhenAttachmentExistsForTheGivenIdButTheEmailIdDoesNotMatch() { - assertThrows(AttachmentNotFoundException.class, () -> { - var emailId = 123L; - var attachmentId = 456L; + var emailId = 123L; + var attachmentId = 456L; - when(emailAttachmentRepository.findById(attachmentId)).thenReturn(Optional.empty()); + when(emailAttachmentRepository.findById(attachmentId)).thenReturn(Optional.empty()); + assertThrows(AttachmentNotFoundException.class, () -> { sut.getEmailAttachmentById(emailId, attachmentId); }); } 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 937f88d1..d5f2a1ac 100644 --- a/src/test/java/de/gessnerfl/fakesmtp/server/impl/BasicUsernamePasswordValidatorTest.java +++ b/src/test/java/de/gessnerfl/fakesmtp/server/impl/BasicUsernamePasswordValidatorTest.java @@ -69,38 +69,38 @@ void shouldThrowLoginFailedExceptionWhenPasswordIsNotValid() { @Test void shouldThrowNullPointerExceptionWhenAuthenticationIsMissing() { - Assertions.assertThrows(NullPointerException.class, () -> { - var username = "username"; - var password = "password"; - when(fakeSmtpConfigurationProperties.getAuthentication()).thenReturn(null); + var username = "username"; + var password = "password"; + when(fakeSmtpConfigurationProperties.getAuthentication()).thenReturn(null); + Assertions.assertThrows(NullPointerException.class, () -> { sut.login(username, password); }); } @Test void shouldThrowNullPointerExceptionWhenUsernameIsMissingInAuthentication() { - Assertions.assertThrows(NullPointerException.class, () -> { - var username = "username"; - var password = "password"; - var authentication = mock(FakeSmtpConfigurationProperties.Authentication.class); - when(authentication.getUsername()).thenReturn(null); - when(fakeSmtpConfigurationProperties.getAuthentication()).thenReturn(authentication); + var username = "username"; + var password = "password"; + var authentication = mock(FakeSmtpConfigurationProperties.Authentication.class); + when(authentication.getUsername()).thenReturn(null); + when(fakeSmtpConfigurationProperties.getAuthentication()).thenReturn(authentication); + Assertions.assertThrows(NullPointerException.class, () -> { sut.login(username, password); }); } @Test void shouldThrowNullPointerExceptionWhenPasswordIsMissingInAuthentication() { - Assertions.assertThrows(NullPointerException.class, () -> { - var username = "username"; - var password = "password"; - var authentication = mock(FakeSmtpConfigurationProperties.Authentication.class); - when(authentication.getUsername()).thenReturn(username); - when(authentication.getPassword()).thenReturn(null); - when(fakeSmtpConfigurationProperties.getAuthentication()).thenReturn(authentication); + var username = "username"; + var password = "password"; + var authentication = mock(FakeSmtpConfigurationProperties.Authentication.class); + when(authentication.getUsername()).thenReturn(username); + when(authentication.getPassword()).thenReturn(null); + when(fakeSmtpConfigurationProperties.getAuthentication()).thenReturn(authentication); + Assertions.assertThrows(NullPointerException.class, () -> { sut.login(username, password); }); } 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 ca8ddb64..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,6 +2,7 @@ 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; @@ -44,6 +45,10 @@ void shouldCreateEmailForEmlFileWithSubjectAndContentTypePlain() throws Exceptio 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()); @@ -92,16 +97,7 @@ void shouldCreateEmailForEmlFileWithSubjectAndWithoutContentType() throws Except 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 @@ -188,16 +184,7 @@ void shouldCreateMailForMultipartWithoutContentTypeHtml() throws Exception { 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 From 3e6e3e2131640d052e393088776379c319eaefe5 Mon Sep 17 00:00:00 2001 From: Florian Gessner Date: Fri, 13 Nov 2020 10:45:55 +0100 Subject: [PATCH 5/5] #33: Update docker image --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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