### Question:
AcmFilesystemMailTemplateConfigurationService implements AcmMailTemplateConfigurationService { @Override public void updateEmailTemplate(EmailTemplateConfiguration templateData, MultipartFile template) throws AcmEmailConfigurationException { File templateFolder = getTemplateFolder(); List<EmailTemplateConfiguration> configurations = getTemplateConfigurations(templateData); Lock writeLock = lock.writeLock(); writeLock.lock(); try (OutputStream os = getTemplateResourceOutputStream()) { String configurationsString = getObjectConverter().getJsonMarshaller().marshal(configurations); if (configurationsString == null) { log.warn("Error while serializing email templates configuration to {} file.", templateConfigurations.getDescription(), null); throw new AcmEmailConfigurationJsonException( String.format("Error while serializing email templates configuration to %s file.", templateConfigurations.getDescription()), null); } os.write(configurationsString.getBytes(StandardCharsets.UTF_8)); if (template != null) { File templateFile = new File(templateFolder, templateData.getTemplateName()); template.transferTo(templateFile); } } catch (IOException e) { log.warn("Error while updating email template configuration for configuration with {} value for templateName.", templateData.getTemplateName(), e); throw new AcmEmailConfigurationIOException( String.format("Error while updating email template configuration for configuration with %s value for templateName.", templateData.getTemplateName()), e); } finally { writeLock.unlock(); } }  @Override List<EmailTemplateConfiguration> getTemplateConfigurations(); void setTemplateConfigurations(Resource templateConfigurations); @Override EmailTemplateValidationResponse validateEmailTemplate(EmailTemplateConfiguration templateData); @Override void updateEmailTemplate(EmailTemplateConfiguration templateData, MultipartFile template); @Override List<EmailTemplateConfiguration> getMatchingTemplates(String email, String objectType, EmailSource source, List<String> actions); @Override String getTemplate(String templateName); @Override void deleteTemplate(String templateName); @Override AcmEmailServiceExceptionMapper<ME> getExceptionMapper(AcmEmailServiceException e); void setTemplateFolderPath(String templateFolderPath); ObjectConverter getObjectConverter(); void setObjectConverter(ObjectConverter objectConverter);  }### Answer:
@Test public void testUpdateEmailTemplate_ExceptionWhileReading() throws Exception { IOException ioException = new IOException(); when(templateConfigurations.getInputStream()).thenThrow(ioException); when(templateConfigurations.getDescription()).thenReturn(ABSOLUTE_PATH_TO_RESOURCE); when(templateConfigurations.contentLength()).thenReturn(10l); exception.expect(AcmEmailConfigurationIOException.class); exception.expectMessage(is( String.format("Error while reading email templates configuration from %s file.", templateConfigurations.getDescription()))); exception.expectCause(is(ioException)); EmailTemplateConfiguration configuration = setupConfiguration(EMAIL_PATTERN, Arrays.asList(CASE_FILE, COMPLAINT), EmailSource.MANUAL, TEMPLATE_NAME, Arrays.asList(SEND_AS_ATTACHMENTS, SEND_AS_LINKS)); MockMultipartFile template = new MockMultipartFile("file", "", MediaType.TEXT_PLAIN_VALUE, "template".getBytes("UTF-8")); service.updateEmailTemplate(configuration, template); }
@Test public void testUpdateEmailTemplate_ExceptionWhileWriting() throws Exception { String fileName = getClass().getClassLoader().getResource("mailTemplatesConfiguration.json").getFile(); when(templateConfigurations.getInputStream()).thenReturn(new FileInputStream(fileName)); IOException ioException = new IOException(); when(templateConfigurations.getFile()).thenThrow(ioException); when(templateConfigurations.getDescription()).thenReturn(ABSOLUTE_PATH_TO_RESOURCE); exception.expect(AcmEmailConfigurationException.class); exception.expectMessage(is(String.format("Error while opening configuration %s file.", ABSOLUTE_PATH_TO_RESOURCE))); exception.expectCause(is(ioException)); EmailTemplateConfiguration configuration = setupConfiguration(EMAIL_PATTERN, Arrays.asList(CASE_FILE, COMPLAINT), EmailSource.MANUAL, TEMPLATE_NAME, Arrays.asList(SEND_AS_ATTACHMENTS, SEND_AS_LINKS)); MockMultipartFile template = new MockMultipartFile("file", "", MediaType.TEXT_PLAIN_VALUE, "template".getBytes("UTF-8")); service.updateEmailTemplate(configuration, template); }