File tree 2 files changed +8
-2
lines changed
2 files changed +8
-2
lines changed Original file line number Diff line number Diff line change 13
13
14
14
package io .nats .client ;
15
15
16
+ import io .nats .client .support .Validator ;
17
+
16
18
public class MessageTtl {
17
19
private final String messageTtl ;
18
20
@@ -35,7 +37,7 @@ public String toString() {
35
37
* @return The Builder
36
38
*/
37
39
public static MessageTtl seconds (int msgTtlSeconds ) {
38
- if (msgTtlSeconds < 0 ) {
40
+ if (msgTtlSeconds < 1 ) {
39
41
throw new IllegalArgumentException ("msgTtlSeconds must be at least 1 second." );
40
42
}
41
43
return new MessageTtl (msgTtlSeconds + "s" );
@@ -48,7 +50,7 @@ public static MessageTtl seconds(int msgTtlSeconds) {
48
50
* @return The Builder
49
51
*/
50
52
public static MessageTtl custom (String messageTtlCustom ) {
51
- if (messageTtlCustom == null ) {
53
+ if (Validator . nullOrEmpty ( messageTtlCustom ) ) {
52
54
throw new IllegalArgumentException ("messageTtlCustom required." );
53
55
}
54
56
return new MessageTtl (messageTtlCustom );
Original file line number Diff line number Diff line change @@ -115,6 +115,10 @@ public void testMessageTtl() {
115
115
.build ();
116
116
assertEquals ("never" , po .getMessageTtl ());
117
117
118
+ assertThrows (IllegalArgumentException .class , () -> MessageTtl .seconds (0 ));
119
+ assertThrows (IllegalArgumentException .class , () -> MessageTtl .seconds (-1 ));
120
+ assertThrows (IllegalArgumentException .class , () -> MessageTtl .custom (null ));
121
+ assertThrows (IllegalArgumentException .class , () -> MessageTtl .custom ("" ));
118
122
assertTrue (MessageTtl .seconds (3 ).toString ().contains ("3s" )); // COVERAGE
119
123
}
120
124
}
You can’t perform that action at this time.
0 commit comments