Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save larsgroeber/93c5ef8fb94c0da88132d4e62b3c18ef to your computer and use it in GitHub Desktop.
Save larsgroeber/93c5ef8fb94c0da88132d4e62b3c18ef to your computer and use it in GitHub Desktop.
@MockBean
private lateinit var mailSenderProxy: MailSenderProxyService;
@Test
@WithMockUser(authorities = ["SEND_MAIL"])
@Throws(Exception::class)
fun shouldSendMail() {
val mockMessage = mock(MimeMessage::class.java)
Mockito.`when`(mailSenderProxy.createMimeMessage()).thenReturn(mockMessage)
val builder = MockMvcRequestBuilders.multipart("/email/sendMail")
.param("body", "body").param("toMail", "toMail").param("subject", "subject")
mockMvc.perform(builder).andExpect(MockMvcResultMatchers.status().isNoContent)
verify(mailSenderProxy).send(mockMessage)
val logs = mongoTemplate.findAll(EMailLogEntity::class.java)
assertThat(logs).hasSize(1);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment