@Test public void testConvertAttachmentKeyIntoContentTypeAndFilename() throws Exception { final CacheManager cacheManager = mockery.mock(CacheManager.class); final Cache cache = mockery.mock(Cache.class); mockery.checking(new Expectations() {{ allowing(cacheManager).getCache("contentService-templateSupport"); will(returnValue(cache)); allowing(cache).get("<% \n %>${name} is awesome!"); will(returnValue(null)); allowing(cache).put(with(equal("<% \n %>${name} is awesome!")), with(any(Object.class))); }}); final TemplateProcessor templates = new MailComposerTemplateSupportGroovyImpl(new GroovyGStringTemplateSupportImpl(cacheManager)); final MailComposerImpl composer = new MailComposerImpl(null, templates); Pair<String, String> ctaf; ctaf = composer.convertAttachmentKeyIntoContentTypeAndFilename(null); assertNull(ctaf); ctaf = composer.convertAttachmentKeyIntoContentTypeAndFilename("random"); assertNull(ctaf); ctaf = composer.convertAttachmentKeyIntoContentTypeAndFilename("not attach"); assertNull(ctaf); ctaf = composer.convertAttachmentKeyIntoContentTypeAndFilename("attachment:"); assertNull(ctaf); ctaf = composer.convertAttachmentKeyIntoContentTypeAndFilename("attachment:image/jpeg"); assertNull(ctaf); ctaf = composer.convertAttachmentKeyIntoContentTypeAndFilename("attachment:application/pdf;myfile.pdf"); assertNotNull(ctaf); assertEquals("application/pdf", ctaf.getFirst()); assertEquals("myfile.pdf", ctaf.getSecond()); mockery.assertIsSatisfied(); }
Pair<String, String> convertAttachmentKeyIntoContentTypeAndFilename(final String key) { try { final String[] contentTypeAndFile = key.substring(ATTACHMENT_PREFIX.length()).split(ATTACHMENT_SUFFIX); return new Pair<>(contentTypeAndFile[0], contentTypeAndFile[1]); } catch (Exception exp) { LOG.error("Invalid attachment key {} ... attachment is skipped", key); return null; } }
MailComposerImpl implements MailComposer { Pair<String, String> convertAttachmentKeyIntoContentTypeAndFilename(final String key) { try { final String[] contentTypeAndFile = key.substring(ATTACHMENT_PREFIX.length()).split(ATTACHMENT_SUFFIX); return new Pair<>(contentTypeAndFile[0], contentTypeAndFile[1]); } catch (Exception exp) { LOG.error("Invalid attachment key {} ... attachment is skipped", key); return null; } } }
MailComposerImpl implements MailComposer { Pair<String, String> convertAttachmentKeyIntoContentTypeAndFilename(final String key) { try { final String[] contentTypeAndFile = key.substring(ATTACHMENT_PREFIX.length()).split(ATTACHMENT_SUFFIX); return new Pair<>(contentTypeAndFile[0], contentTypeAndFile[1]); } catch (Exception exp) { LOG.error("Invalid attachment key {} ... attachment is skipped", key); return null; } } MailComposerImpl(final MailTemplateResourcesProvider mailTemplateResourcesProvider,
                            final TemplateProcessor templateSupport); }
MailComposerImpl implements MailComposer { Pair<String, String> convertAttachmentKeyIntoContentTypeAndFilename(final String key) { try { final String[] contentTypeAndFile = key.substring(ATTACHMENT_PREFIX.length()).split(ATTACHMENT_SUFFIX); return new Pair<>(contentTypeAndFile[0], contentTypeAndFile[1]); } catch (Exception exp) { LOG.error("Invalid attachment key {} ... attachment is skipped", key); return null; } } MailComposerImpl(final MailTemplateResourcesProvider mailTemplateResourcesProvider,
                            final TemplateProcessor templateSupport); String getResourceExpression(); void setResourceExpression(final String resourceExpression); @Override void composeMessage(final Mail mail,
                               final String shopCode,
                               final String locale,
                               final List<String> mailTemplateChain,
                               final String templateName,
                               final String from,
                               final String toEmail,
                               final String ccEmail,
                               final String bccEmail,
                               final Map<String, Object> model); @Override void convertMessage(final Mail mail, final MimeMessage mimeMessage); @Override String convertMessageToTXT(final Mail mail); @Override String convertMessageToHTML(final Mail mail); }
MailComposerImpl implements MailComposer { Pair<String, String> convertAttachmentKeyIntoContentTypeAndFilename(final String key) { try { final String[] contentTypeAndFile = key.substring(ATTACHMENT_PREFIX.length()).split(ATTACHMENT_SUFFIX); return new Pair<>(contentTypeAndFile[0], contentTypeAndFile[1]); } catch (Exception exp) { LOG.error("Invalid attachment key {} ... attachment is skipped", key); return null; } } MailComposerImpl(final MailTemplateResourcesProvider mailTemplateResourcesProvider,
                            final TemplateProcessor templateSupport); String getResourceExpression(); void setResourceExpression(final String resourceExpression); @Override void composeMessage(final Mail mail,
                               final String shopCode,
                               final String locale,
                               final List<String> mailTemplateChain,
                               final String templateName,
                               final String from,
                               final String toEmail,
                               final String ccEmail,
                               final String bccEmail,
                               final Map<String, Object> model); @Override void convertMessage(final Mail mail, final MimeMessage mimeMessage); @Override String convertMessageToTXT(final Mail mail); @Override String convertMessageToHTML(final Mail mail);  }