@Test public void initShouldThrowWhenPriorityIsEmpty() { MailetConfig mockedMailetConfig = FakeMailetConfig.builder() .mailetContext(FakeMailContext.defaultContext()) .setProperty("priority", "") .build(); assertThatThrownBy(() -> mailet.init(mockedMailetConfig)) .isInstanceOf(NumberFormatException.class); }
@Override public void init() throws MessagingException { Integer priorityRaw = Optional.ofNullable(getInitParameter("priority", null)) .map(Integer::valueOf) .orElseThrow(() -> new IllegalArgumentException("'priority' init parameter is compulsory")); if (priorityRaw < 0 || priorityRaw > 9) { throw new IllegalArgumentException("Invalid priority: Priority should be from 0 to 9"); } priority = new Attribute(MailPrioritySupport.MAIL_PRIORITY, AttributeValue.of(priorityRaw)); }
WithPriority extends GenericMailet { @Override public void init() throws MessagingException { Integer priorityRaw = Optional.ofNullable(getInitParameter("priority", null)) .map(Integer::valueOf) .orElseThrow(() -> new IllegalArgumentException("'priority' init parameter is compulsory")); if (priorityRaw < 0 || priorityRaw > 9) { throw new IllegalArgumentException("Invalid priority: Priority should be from 0 to 9"); } priority = new Attribute(MailPrioritySupport.MAIL_PRIORITY, AttributeValue.of(priorityRaw)); } }
WithPriority extends GenericMailet { @Override public void init() throws MessagingException { Integer priorityRaw = Optional.ofNullable(getInitParameter("priority", null)) .map(Integer::valueOf) .orElseThrow(() -> new IllegalArgumentException("'priority' init parameter is compulsory")); if (priorityRaw < 0 || priorityRaw > 9) { throw new IllegalArgumentException("Invalid priority: Priority should be from 0 to 9"); } priority = new Attribute(MailPrioritySupport.MAIL_PRIORITY, AttributeValue.of(priorityRaw)); }  }
WithPriority extends GenericMailet { @Override public void init() throws MessagingException { Integer priorityRaw = Optional.ofNullable(getInitParameter("priority", null)) .map(Integer::valueOf) .orElseThrow(() -> new IllegalArgumentException("'priority' init parameter is compulsory")); if (priorityRaw < 0 || priorityRaw > 9) { throw new IllegalArgumentException("Invalid priority: Priority should be from 0 to 9"); } priority = new Attribute(MailPrioritySupport.MAIL_PRIORITY, AttributeValue.of(priorityRaw)); }  @Override String getMailetInfo(); @Override void init(); @Override void service(Mail mail); }
WithPriority extends GenericMailet { @Override public void init() throws MessagingException { Integer priorityRaw = Optional.ofNullable(getInitParameter("priority", null)) .map(Integer::valueOf) .orElseThrow(() -> new IllegalArgumentException("'priority' init parameter is compulsory")); if (priorityRaw < 0 || priorityRaw > 9) { throw new IllegalArgumentException("Invalid priority: Priority should be from 0 to 9"); } priority = new Attribute(MailPrioritySupport.MAIL_PRIORITY, AttributeValue.of(priorityRaw)); }  @Override String getMailetInfo(); @Override void init(); @Override void service(Mail mail);  }