From 3f0d8d64feb64ea47b4ea5658d09c2c14f3baea4 Mon Sep 17 00:00:00 2001 From: Jeroen Ketelaar Date: Wed, 3 Jan 2018 11:05:00 +0100 Subject: [PATCH] [TASK] Added unit tests for the Timer class --- .../parabot/environment/api/utils/Timer.java | 10 +++++++ src/test/java/org/parabot/TimerTest.java | 26 +++++++++++++++++++ 2 files changed, 36 insertions(+) create mode 100644 src/test/java/org/parabot/TimerTest.java diff --git a/src/main/java/org/parabot/environment/api/utils/Timer.java b/src/main/java/org/parabot/environment/api/utils/Timer.java index 4720505..b4ea42a 100644 --- a/src/main/java/org/parabot/environment/api/utils/Timer.java +++ b/src/main/java/org/parabot/environment/api/utils/Timer.java @@ -19,6 +19,16 @@ public class Timer { this.end = System.currentTimeMillis() + end; } + /** + * Timer Constructor + * + * @param end + */ + public Timer(long end, long start) { + this.start = start; + this.end = System.currentTimeMillis() + end; + } + /** * Timer Constructor */ diff --git a/src/test/java/org/parabot/TimerTest.java b/src/test/java/org/parabot/TimerTest.java new file mode 100644 index 0000000..8a98b9c --- /dev/null +++ b/src/test/java/org/parabot/TimerTest.java @@ -0,0 +1,26 @@ +package org.parabot; + +import org.junit.Assert; +import org.junit.Test; +import org.parabot.environment.api.utils.Timer; + +/** + * @author JKetelaar + */ +public class TimerTest { + + @Test + public void test(){ + Timer timer1 = new Timer(0, System.currentTimeMillis() - (1000 * 60 * 60 * 24)); + Assert.assertEquals(timer1.toString(), "1d:00:00:00"); + + Timer timer2 = new Timer(0, System.currentTimeMillis() - (1000 * 60 * 60 * 24 * 5)); + Assert.assertEquals(timer2.toString(), "5d:00:00:00"); + + Timer timer3 = new Timer(0, System.currentTimeMillis() - (1000 * 60 * 60)); + Assert.assertEquals(timer3.toString(), "01:00:00"); + + Timer timer4 = new Timer(0, System.currentTimeMillis() - (1000 * 60 * 60 * 12)); + Assert.assertEquals(timer4.toString(), "12:00:00"); + } +}