@Test void stringConstructorShouldThrowOnNegativeAttempts() { assertThatThrownBy(() -> Delay.from("-1*36")) .isInstanceOf(MessagingException.class); }
public static Delay from(String initString) throws MessagingException { if (Strings.isNullOrEmpty(initString)) { throw new NumberFormatException("Null or Empty strings are not permitted"); } List<String> parts = Splitter.on('*').trimResults().splitToList(initString); if (parts.size() == 1) { return new Delay(DEFAULT_ATTEMPTS, DurationParser.parse(parts.get(0))); } if (parts.size() == 2) { int attempts = Integer.parseInt(parts.get(0)); if (attempts < 0) { throw new MessagingException("Number of attempts negative in " + initString); } return new Delay(attempts, DurationParser.parse(parts.get(1))); } throw new MessagingException(initString + " contains too much parts"); }
Delay { public static Delay from(String initString) throws MessagingException { if (Strings.isNullOrEmpty(initString)) { throw new NumberFormatException("Null or Empty strings are not permitted"); } List<String> parts = Splitter.on('*').trimResults().splitToList(initString); if (parts.size() == 1) { return new Delay(DEFAULT_ATTEMPTS, DurationParser.parse(parts.get(0))); } if (parts.size() == 2) { int attempts = Integer.parseInt(parts.get(0)); if (attempts < 0) { throw new MessagingException("Number of attempts negative in " + initString); } return new Delay(attempts, DurationParser.parse(parts.get(1))); } throw new MessagingException(initString + " contains too much parts"); } }
Delay { public static Delay from(String initString) throws MessagingException { if (Strings.isNullOrEmpty(initString)) { throw new NumberFormatException("Null or Empty strings are not permitted"); } List<String> parts = Splitter.on('*').trimResults().splitToList(initString); if (parts.size() == 1) { return new Delay(DEFAULT_ATTEMPTS, DurationParser.parse(parts.get(0))); } if (parts.size() == 2) { int attempts = Integer.parseInt(parts.get(0)); if (attempts < 0) { throw new MessagingException("Number of attempts negative in " + initString); } return new Delay(attempts, DurationParser.parse(parts.get(1))); } throw new MessagingException(initString + " contains too much parts"); } Delay(); @VisibleForTesting  Delay(int attempts, Duration delayTime); }
Delay { public static Delay from(String initString) throws MessagingException { if (Strings.isNullOrEmpty(initString)) { throw new NumberFormatException("Null or Empty strings are not permitted"); } List<String> parts = Splitter.on('*').trimResults().splitToList(initString); if (parts.size() == 1) { return new Delay(DEFAULT_ATTEMPTS, DurationParser.parse(parts.get(0))); } if (parts.size() == 2) { int attempts = Integer.parseInt(parts.get(0)); if (attempts < 0) { throw new MessagingException("Number of attempts negative in " + initString); } return new Delay(attempts, DurationParser.parse(parts.get(1))); } throw new MessagingException(initString + " contains too much parts"); } Delay(); @VisibleForTesting  Delay(int attempts, Duration delayTime); static Delay from(String initString); Duration getDelayTime(); int getAttempts(); List<Duration> getExpendendDelays(); @Override String toString(); @Override boolean equals(Object o); @Override int hashCode(); }
Delay { public static Delay from(String initString) throws MessagingException { if (Strings.isNullOrEmpty(initString)) { throw new NumberFormatException("Null or Empty strings are not permitted"); } List<String> parts = Splitter.on('*').trimResults().splitToList(initString); if (parts.size() == 1) { return new Delay(DEFAULT_ATTEMPTS, DurationParser.parse(parts.get(0))); } if (parts.size() == 2) { int attempts = Integer.parseInt(parts.get(0)); if (attempts < 0) { throw new MessagingException("Number of attempts negative in " + initString); } return new Delay(attempts, DurationParser.parse(parts.get(1))); } throw new MessagingException(initString + " contains too much parts"); } Delay(); @VisibleForTesting  Delay(int attempts, Duration delayTime); static Delay from(String initString); Duration getDelayTime(); int getAttempts(); List<Duration> getExpendendDelays(); @Override String toString(); @Override boolean equals(Object o); @Override int hashCode(); static final Duration DEFAULT_DELAY_TIME; static final int DEFAULT_ATTEMPTS; }