Skip to content

Commit 0b2d59d

Browse files
committed
Added tests for w (weeks) in duration.
1 parent a251494 commit 0b2d59d

File tree

1 file changed

+19
-6
lines changed

1 file changed

+19
-6
lines changed

src/test/java/org/gitlab4j/api/TestDuration.java

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,13 @@ public class TestDuration {
1010

1111
@Test
1212
public void testParse() {
13-
14-
int seconds = DurationUtils.parse("1d1h1m1s");
13+
14+
int seconds = DurationUtils.parse("1w1d1h1m1s");
15+
assertEquals(60 * 60 * 24 * 7 + 60 * 60 * 24 + 60 * 60 + 60 + 1, seconds);
16+
17+
seconds = DurationUtils.parse("1d1h1m1s");
1518
assertEquals(60 * 60 * 24 + 60 * 60 + 60 + 1, seconds);
16-
19+
1720
seconds = DurationUtils.parse("60m");
1821
assertEquals(60 * 60, seconds);
1922

@@ -51,18 +54,28 @@ public void testBadParse() {
5154
} catch (IllegalArgumentException iae) {
5255
System.out.println("Recieved expected exception: " + iae.getMessage());
5356
}
57+
58+
try {
59+
DurationUtils.parse("1w2w2d2h2m");
60+
fail("Should have received an exception for the bad duration");
61+
} catch (IllegalArgumentException iae) {
62+
System.out.println("Recieved expected exception: " + iae.getMessage());
63+
}
5464
}
5565

5666
@Test
5767
public void testToString() {
58-
68+
5969
String duration = DurationUtils.toString(60 + 1);
6070
assertEquals("1m1s", duration);
61-
71+
6272
duration = DurationUtils.toString(60 * 60 + 60 + 1);
6373
assertEquals("1h1m1s", duration);
64-
74+
6575
duration = DurationUtils.toString(60 * 60 * 24 + 60 * 60 * 2 + 60 * 3 + 4);
6676
assertEquals("1d2h3m4s", duration);
77+
78+
duration = DurationUtils.toString(60 * 60 * 24 * 7 + 60 * 60 * 24 * 2 + 60 * 60 * 3 + 60 * 4 + 5);
79+
assertEquals("1w2d3h4m5s", duration);
6780
}
6881
}

0 commit comments

Comments
 (0)