@Test public void saveMessageThrowsMailStoreExceptionWhenError() throws Exception { Environment environment = this.mocker.getInstance(Environment.class); when(environment.getPermanentDirectory()).thenReturn(new File(TEMPORARY_DIRECTORY)); String batchId = UUID.randomUUID().toString(); String messageId = "ar1vm0Wca42E/dDn3dsH8ogs3/s="; ExtendedMimeMessage message = mock(ExtendedMimeMessage.class); when(message.getUniqueMessageId()).thenReturn(messageId); this.thrown.expect(MailStoreException.class); this.thrown.expectMessage( "Failed to save message (id [" + messageId + "], batch id [" + batchId + "]) into file"); when(message.getContent()) .thenReturn("Lorem ipsum dolor sit amet, consectetur adipiscing elit"); doThrow(new IOException()).when(message).writeTo(any(OutputStream.class)); this.mocker.getComponentUnderTest().save(batchId, message); }
@Test public void deleteMessage() throws Exception { Environment environment = this.mocker.getInstance(Environment.class); when(environment.getPermanentDirectory()).thenReturn(new File(TEMPORARY_DIRECTORY)); String batchId = UUID.randomUUID().toString(); String messageId = "ar1vm0Wca42E/dDn3dsH8ogs3/s="; File tempDir = new File(TEMPORARY_DIRECTORY); File batchDirectory = new File( new File(tempDir, this.mocker.getComponentUnderTest().ROOT_DIRECTORY), URLEncoder.encode(batchId, "UTF-8")); batchDirectory.mkdirs(); File messageFile = new File(batchDirectory, URLEncoder.encode(messageId, "UTF-8")); messageFile.createNewFile(); this.mocker.getComponentUnderTest().delete(batchId, messageId); assertTrue(!messageFile.exists()); }
@BeforeComponent public void registerMockComponents() throws Exception { Environment environment = this.mocker.registerMockComponent(Environment.class); when(environment.getPermanentDirectory()).thenReturn(new File(TEMPORARY_DIRECTORY)); }