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]
This commit is contained in:
Haoming Yin
2017-03-07 20:30:23 +13:00
parent a3c1630e2e
commit 17fbb1212d
2 changed files with 98 additions and 0 deletions
+77
View File
@@ -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;
}
}
+21
View File
@@ -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());
}
}