@Test void initShouldThrowOnInvalidUnits() { FakeMatcherConfig matcherConfiguration = FakeMatcherConfig.builder() .matcherName("SizeGreaterThan") .condition("1mb") .build(); assertThatThrownBy(() -> matcher.init(matcherConfiguration)) .isInstanceOf(MessagingException.class); }
@Override public void init() throws MessagingException { String amount = getCondition(); if (amount != null) { amount = amount.trim().toLowerCase(Locale.US); } else { throw new MessagingException("Please configure an amount"); } try { if (amount.endsWith("k")) { amount = amount.substring(0, amount.length() - 1); cutoff = Integer.parseInt(amount) * 1024; } else if (amount.endsWith("m")) { amount = amount.substring(0, amount.length() - 1); cutoff = Integer.parseInt(amount) * 1024 * 1024; } else { cutoff = Integer.parseInt(amount); } } catch (NumberFormatException e) { throw new MessagingException("Invalid amount: " + amount); } if (cutoff < 1) { throw new MessagingException("Amount should be strictly superior to 0"); } }
SizeGreaterThan extends GenericMatcher { @Override public void init() throws MessagingException { String amount = getCondition(); if (amount != null) { amount = amount.trim().toLowerCase(Locale.US); } else { throw new MessagingException("Please configure an amount"); } try { if (amount.endsWith("k")) { amount = amount.substring(0, amount.length() - 1); cutoff = Integer.parseInt(amount) * 1024; } else if (amount.endsWith("m")) { amount = amount.substring(0, amount.length() - 1); cutoff = Integer.parseInt(amount) * 1024 * 1024; } else { cutoff = Integer.parseInt(amount); } } catch (NumberFormatException e) { throw new MessagingException("Invalid amount: " + amount); } if (cutoff < 1) { throw new MessagingException("Amount should be strictly superior to 0"); } } }
SizeGreaterThan extends GenericMatcher { @Override public void init() throws MessagingException { String amount = getCondition(); if (amount != null) { amount = amount.trim().toLowerCase(Locale.US); } else { throw new MessagingException("Please configure an amount"); } try { if (amount.endsWith("k")) { amount = amount.substring(0, amount.length() - 1); cutoff = Integer.parseInt(amount) * 1024; } else if (amount.endsWith("m")) { amount = amount.substring(0, amount.length() - 1); cutoff = Integer.parseInt(amount) * 1024 * 1024; } else { cutoff = Integer.parseInt(amount); } } catch (NumberFormatException e) { throw new MessagingException("Invalid amount: " + amount); } if (cutoff < 1) { throw new MessagingException("Amount should be strictly superior to 0"); } }  }
SizeGreaterThan extends GenericMatcher { @Override public void init() throws MessagingException { String amount = getCondition(); if (amount != null) { amount = amount.trim().toLowerCase(Locale.US); } else { throw new MessagingException("Please configure an amount"); } try { if (amount.endsWith("k")) { amount = amount.substring(0, amount.length() - 1); cutoff = Integer.parseInt(amount) * 1024; } else if (amount.endsWith("m")) { amount = amount.substring(0, amount.length() - 1); cutoff = Integer.parseInt(amount) * 1024 * 1024; } else { cutoff = Integer.parseInt(amount); } } catch (NumberFormatException e) { throw new MessagingException("Invalid amount: " + amount); } if (cutoff < 1) { throw new MessagingException("Amount should be strictly superior to 0"); } }  @Override void init(); @Override Collection<MailAddress> match(Mail mail); }
SizeGreaterThan extends GenericMatcher { @Override public void init() throws MessagingException { String amount = getCondition(); if (amount != null) { amount = amount.trim().toLowerCase(Locale.US); } else { throw new MessagingException("Please configure an amount"); } try { if (amount.endsWith("k")) { amount = amount.substring(0, amount.length() - 1); cutoff = Integer.parseInt(amount) * 1024; } else if (amount.endsWith("m")) { amount = amount.substring(0, amount.length() - 1); cutoff = Integer.parseInt(amount) * 1024 * 1024; } else { cutoff = Integer.parseInt(amount); } } catch (NumberFormatException e) { throw new MessagingException("Invalid amount: " + amount); } if (cutoff < 1) { throw new MessagingException("Amount should be strictly superior to 0"); } }  @Override void init(); @Override Collection<MailAddress> match(Mail mail);  }