BroadcastingFacade extends DefaultFacade<BroadcastingMessage, BroadcastingMessageResource, BroadcastingMessage,
		BroadcastingMessageResource, DefaultService<BroadcastingMessage,
		BroadcastingMessage, Long, Dao<BroadcastingMessage, BroadcastingMessage, Long>>, Long> { @Override public BroadcastingMessageResource createResource(final BroadcastingMessageResource resource) { BroadcastingMessageResource createdResource = super.createResource(resource); Email email = broadcastResourceEmailConverter.convert(resource); mailService.send(email); BroadcastingMessageResource result = new BroadcastingMessageResource(); emailBroadcastingConverter.convert(email, result); broadcastingConverter.convert(createdResource, result); return result; }  @Override BroadcastingMessageResource createResource(final BroadcastingMessageResource resource); void setBroadcastResourceEmailConverter(final Converter<BroadcastingMessageResource, Email> broadcastResourceEmailConverter); void setMailService(final MailService<Email> mailService); void setEmailBroadcastingConverter(final Converter<Email, BroadcastingMessageResource> emailBroadcastingConverter); void setBroadcastinConverter(final Converter<BroadcastingMessageResource, BroadcastingMessageResource> broadcastinConverter);  }
@Test public void testCreateEntity() throws Exception { BroadcastingMessageResource expected = new BroadcastingMessageResource(); BroadcastingMessage broadcastingMessage = new BroadcastingMessage(); Email email = new Email(); when(resourceConverter.convert(any(BroadcastingMessageResource.class))).thenReturn(broadcastingMessage); when(entityConverter.convert(any(BroadcastingMessage.class))).thenReturn(expected); when(broadcastResourceEmailConverter.convert(any(BroadcastingMessageResource.class))).thenReturn(email); BroadcastingMessageResource actual = unit.createResource(expected); verify(emailBroadcastingConverter).convert(any(Email.class), any(BroadcastingMessageResource.class)); verify(broadcastingConverter).convert(any(BroadcastingMessageResource.class), any(BroadcastingMessageResource.class)); verify(mailService).send(email); assertEquals(expected, actual); }
@Test(expected = MailException.class) public void testCreateEntityWithException() throws Exception { BroadcastingMessageResource expected = new BroadcastingMessageResource(); Email email = new Email(); when(broadcastResourceEmailConverter.convert(any(BroadcastingMessageResource.class))).thenReturn(email); doThrow(MailException.class).when(mailService).send(email); BroadcastingMessageResource actual = unit.createResource(expected); verify(broadcastResourceEmailConverter).convert(expected); verify(mailService).send(email); assertEquals(expected, actual); }