From 17fbb1212d844522aeadef06a7fea991aa8d9ff2 Mon Sep 17 00:00:00 2001 From: Haoming Yin Date: Tue, 7 Mar 2017 20:30:23 +1300 Subject: [PATCH] Added Event class and junit test - event class contains the time of specific event, related team/boat and even location eg. leg. #implement #story[5] --- src/main/java/seng302/Event.java | 77 ++++++++++++++++++++++++++++ src/test/java/seng302/EventTest.java | 21 ++++++++ 2 files changed, 98 insertions(+) create mode 100644 src/main/java/seng302/Event.java create mode 100644 src/test/java/seng302/EventTest.java diff --git a/src/main/java/seng302/Event.java b/src/main/java/seng302/Event.java new file mode 100644 index 00000000..5a36fad1 --- /dev/null +++ b/src/main/java/seng302/Event.java @@ -0,0 +1,77 @@ +package seng302; + +import java.text.SimpleDateFormat; +import java.util.Date; + +/** + * Event class containing the time of specific event, related team/boat, and + * event location such as leg. + */ +public class Event { + + private long time; + private Boat boat; + private Leg leg; + + public Event(long eventTime, Boat eventBoat, Leg eventLeg) { + this.time = eventTime; + this.boat = eventBoat; + this.leg = eventLeg; + } + + /** + * Sets the time for the event + * @param eventTime the time for event in millisecond + */ + public void setTime(long eventTime) { + this.time = eventTime; + } + + /** + * Gets the time for the event + * @return the time for event in millisecond + */ + public long getTime() { + return this.time; + } + + /** + * Gets the time in a formatted string + * @return the string of time + */ + public String getTimeString() { + return (new SimpleDateFormat("mm:ss:SSS")).format(new Date(time)); + } + + /** + * Sets the involved boat + * @param eventBoat the involved boat + */ + public void setBoat(Boat eventBoat) { + this.boat = eventBoat; + } + + /** + * Gets the involved boat + * @return the boat involved in the event + */ + public Boat getBoat() { + return this.boat; + } + + /** + * Sets the involved location/leg + * @param eventLeg the involved leg + */ + public void setLeg(Leg eventLeg) { + this.leg = eventLeg; + } + + /** + * Gets the involved location/leg + * @return the leg involved in the event + */ + public Leg getLeg() { + return this.leg; + } +} diff --git a/src/test/java/seng302/EventTest.java b/src/test/java/seng302/EventTest.java new file mode 100644 index 00000000..3f66ad52 --- /dev/null +++ b/src/test/java/seng302/EventTest.java @@ -0,0 +1,21 @@ +package seng302; + +import org.junit.Before; +import org.junit.Test; + +import static org.junit.Assert.*; + +/** + * Test for Event class + * Created by Haoming on 7/03/17. + */ +public class EventTest { + + @Test + public void getTimeString() throws Exception { + Leg leg = new Leg(035, 100, "Start"); + Boat boat = new Boat("testBoat"); + Event event = new Event(1231242, boat, leg); + assertEquals("20:31:242", event.getTimeString()); + } +} \ No newline at end of file