Commit 0b2d59dd authored by Greg Messner's avatar Greg Messner
Browse files

Added tests for w (weeks) in duration.

parent a2514940
......@@ -10,10 +10,13 @@ public class TestDuration {
@Test
public void testParse() {
int seconds = DurationUtils.parse("1d1h1m1s");
int seconds = DurationUtils.parse("1w1d1h1m1s");
assertEquals(60 * 60 * 24 * 7 + 60 * 60 * 24 + 60 * 60 + 60 + 1, seconds);
seconds = DurationUtils.parse("1d1h1m1s");
assertEquals(60 * 60 * 24 + 60 * 60 + 60 + 1, seconds);
seconds = DurationUtils.parse("60m");
assertEquals(60 * 60, seconds);
......@@ -51,18 +54,28 @@ public class TestDuration {
} catch (IllegalArgumentException iae) {
System.out.println("Recieved expected exception: " + iae.getMessage());
}
try {
DurationUtils.parse("1w2w2d2h2m");
fail("Should have received an exception for the bad duration");
} catch (IllegalArgumentException iae) {
System.out.println("Recieved expected exception: " + iae.getMessage());
}
}
@Test
public void testToString() {
String duration = DurationUtils.toString(60 + 1);
assertEquals("1m1s", duration);
duration = DurationUtils.toString(60 * 60 + 60 + 1);
assertEquals("1h1m1s", duration);
duration = DurationUtils.toString(60 * 60 * 24 + 60 * 60 * 2 + 60 * 3 + 4);
assertEquals("1d2h3m4s", duration);
duration = DurationUtils.toString(60 * 60 * 24 * 7 + 60 * 60 * 24 * 2 + 60 * 60 * 3 + 60 * 4 + 5);
assertEquals("1w2d3h4m5s", duration);
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment