Skip to content

Commit

Permalink
#33: fix sonar issues
Browse files Browse the repository at this point in the history
  • Loading branch information
gessnerfl committed Nov 12, 2020
1 parent 21d8e61 commit 67c884b
Show file tree
Hide file tree
Showing 22 changed files with 123 additions and 122 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,20 @@
@ExtendWith(SpringExtension.class)
@SpringBootTest
@AutoConfigureMockMvc
public class EmailControllerMVCIntegrationTest {
class EmailControllerMVCIntegrationTest {

@Autowired
private EmailRepository emailRepository;
@Autowired
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)))
Expand All @@ -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);
Expand All @@ -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"))
Expand All @@ -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()))
Expand All @@ -86,15 +86,15 @@ 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"))
.andExpect(status().isFound());
}

@Test
public void shouldDeleteEmail() throws Exception {
void shouldDeleteEmail() throws Exception {
var email = createRandomEmail(1);

this.mockMvc.perform(delete("/email/"+email.getId()))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import static org.mockito.Mockito.*;

@ExtendWith(MockitoExtension.class)
public class EmailControllerTest {
class EmailControllerTest {
@Mock
private Model model;
@Mock
Expand All @@ -30,7 +30,7 @@ public class EmailControllerTest {
private EmailController sut;

@Test
public void shouldReturnEmailsPaged() {
void shouldReturnEmailsPaged() {
final String appVersion = "appVersion";
final Page<Email> page = createFirstPageEmail();
when(emailRepository.findAll(any(Pageable.class))).thenReturn(page);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -82,31 +82,31 @@ public void shouldNotRedirectToFirstPageWhenNoDataIsAvailable() {
}

@Test
public void shouldRedirectToFirstPageWhenPageNumberIsBelowNull() {
void shouldRedirectToFirstPageWhenPageNumberIsBelowNull() {
var result = sut.getAll(-1, 5, model);

Assertions.assertEquals(EmailController.REDIRECT_EMAIL_LIST_VIEW, result);
verifyNoInteractions(emailRepository, buildProperties, model);
}

@Test
public void shouldRedirectToFirstPageWhenPageSizeIsNull() {
void shouldRedirectToFirstPageWhenPageSizeIsNull() {
String result = sut.getAll(0, 0, model);

Assertions.assertEquals(EmailController.REDIRECT_EMAIL_LIST_VIEW, result);
verifyNoInteractions(emailRepository, buildProperties, model);
}

@Test
public void shouldRedirectToFirstPageWhenPageSizeIsBelowNull() {
void shouldRedirectToFirstPageWhenPageSizeIsBelowNull() {
var result = sut.getAll(0, -1, model);

Assertions.assertEquals(EmailController.REDIRECT_EMAIL_LIST_VIEW, result);
verifyNoInteractions(emailRepository, buildProperties, model);
}

@Test
public void shouldReturnSingleEmailWhenIdIsValid() {
void shouldReturnSingleEmailWhenIdIsValid() {
final String appVersion = "appVersion";
var id = 12L;
var mail = mock(Email.class);
Expand All @@ -125,7 +125,7 @@ public void shouldReturnSingleEmailWhenIdIsValid() {
}

@Test
public void shouldReturnRedirectToListPageWhenIdIsNotValid() {
void shouldReturnRedirectToListPageWhenIdIsNotValid() {
var id = 12L;
when(emailRepository.findById(id)).thenReturn(Optional.empty());

Expand All @@ -150,7 +150,7 @@ private ArgumentMatcher<Pageable> matchPageable(int page, int size) {
}

@Test
public void shouldDeleteEmailByItsIdAndFlushChangesSoThatDeleteIsApplied(){
void shouldDeleteEmailByItsIdAndFlushChangesSoThatDeleteIsApplied(){
var emailId = 123L;

sut.deleteEmailById(emailId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
@ExtendWith(SpringExtension.class)
@SpringBootTest
@AutoConfigureMockMvc
public class EmailRestControllerMVCIntegrationTest {
class EmailRestControllerMVCIntegrationTest {

@Autowired
private EmailRepository emailRepository;
Expand All @@ -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());
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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();
Expand All @@ -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();
Expand All @@ -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);

Expand All @@ -120,23 +120,23 @@ 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"))
.andExpect(status().isNotFound());
}

@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()))
.andExpect(status().isNotFound());
}

@Test
public void shouldDeleteEmail() throws Exception {
void shouldDeleteEmail() throws Exception {
var email = createRandomEmail(1);

this.mockMvc.perform(delete("/api/email/"+email.getId()))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
import static org.mockito.Mockito.*;

@ExtendWith(MockitoExtension.class)
public class EmailRestControllerTest {
class EmailRestControllerTest {
@Mock
private EmailRepository emailRepository;
@Mock
Expand All @@ -40,7 +40,7 @@ public class EmailRestControllerTest {
private EmailRestController sut;

@Test
public void shouldReturnListOfEmails() {
void shouldReturnListOfEmails() {
final Page<Email> page = createFirstPageEmail();
when(emailRepository.findAll(any(Pageable.class))).thenReturn(page);

Expand All @@ -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));
Expand All @@ -74,7 +74,7 @@ private ArgumentMatcher<Pageable> 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;
Expand All @@ -100,7 +100,7 @@ public void shouldReturnResponseEntityForAttachment() {
}

@Test
public void shouldThrowExceptionWhenNoAttachmentExistsForTheGivenId() {
void shouldThrowExceptionWhenNoAttachmentExistsForTheGivenId() {
assertThrows(AttachmentNotFoundException.class, () -> {
var emailId = 123L;
var attachmentId = 456L;
Expand All @@ -116,7 +116,7 @@ public void shouldThrowExceptionWhenNoAttachmentExistsForTheGivenId() {
}

@Test
public void shouldThrowExceptionWhenAttachmentExistsForTheGivenIdButTheEmailIdDoesNotMatch() {
void shouldThrowExceptionWhenAttachmentExistsForTheGivenIdButTheEmailIdDoesNotMatch() {
assertThrows(AttachmentNotFoundException.class, () -> {
var emailId = 123L;
var attachmentId = 456L;
Expand All @@ -128,7 +128,7 @@ public void shouldThrowExceptionWhenAttachmentExistsForTheGivenIdButTheEmailIdDo
}

@Test
public void shouldDeleteEmailByItsIdAndFlushChangesSoThatDeleteIsApplied() {
void shouldDeleteEmailByItsIdAndFlushChangesSoThatDeleteIsApplied() {
var emailId = 123L;

sut.deleteEmailById(emailId);
Expand Down
Loading

0 comments on commit 67c884b

Please sign in to comment.