Skip to content

Commit

Permalink
updated tests for taskcreator
Browse files Browse the repository at this point in the history
  • Loading branch information
TehZiHuai committed Oct 29, 2019
1 parent f2147c4 commit c4918f5
Show file tree
Hide file tree
Showing 3 changed files with 121 additions and 1 deletion.
1 change: 0 additions & 1 deletion src/test/java/AssignmentTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,5 +53,4 @@ void getAssignee() {
void getRecurrenceSchedule() {
assertEquals(assignment.getRecurrenceSchedule(), RecurrenceScheduleType.none);
}

}
7 changes: 7 additions & 0 deletions src/test/java/MeetingTest.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import Enums.Priority;
import Enums.RecurrenceScheduleType;
import Enums.TimeUnit;
import Model_Classes.Meeting;
import org.junit.jupiter.api.Test;
Expand Down Expand Up @@ -64,4 +65,10 @@ void getTimeUnit() {
void getDuration() {
assertEquals(meeting2.getDuration(), "2");
}

@Test
void getRecurrenceSchedule() {
assertEquals(meeting1.getRecurrenceSchedule(), RecurrenceScheduleType.none);
assertEquals(meeting2.getRecurrenceSchedule(), RecurrenceScheduleType.none);
}
}
114 changes: 114 additions & 0 deletions src/test/java/TaskCreatorTest.java
Original file line number Diff line number Diff line change
@@ -1,2 +1,116 @@
import CustomExceptions.RoomShareException;
import Enums.Priority;
import Enums.RecurrenceScheduleType;
import Enums.TimeUnit;
import Operations.TaskCreator;
import javafx.util.Pair;
import org.junit.jupiter.api.Test;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;

import static org.junit.jupiter.api.Assertions.*;

public class TaskCreatorTest {
private static TaskCreator taskCreator = new TaskCreator();
private static String input1 = "add #meeting# (description) &22/12/2019 18:00& *high* %week% " +
"@john@ ^2 hours^ !R!";
private static String input2 = "add #meeting# (description) &23/12/2019 18:00&";
private static String input3 = "add #leave# (description) &24/12/2019 18:00&25/12/2019 18:00&";
@Test
void extractDescription() {
try {
assertEquals(taskCreator.extractDescription(input1), "description");
} catch (RoomShareException e) {
e.printStackTrace();
}
}

@Test
void extractDate() {
SimpleDateFormat format = new SimpleDateFormat("dd/MM/yyyy HH:mm");
Date date1 = new Date();
Date date2 = new Date();
Date date3 = new Date();
try {
date1 = format.parse("22/12/2019 18:00");
date2 = format.parse("24/12/2019 18:00");
date3 = format.parse("25/12/2019 18:00");
} catch (ParseException e) {
e.printStackTrace();
}
ArrayList<Date> dates = new ArrayList<>();
ArrayList<Date> dates2 = new ArrayList<>();
dates2.add(date2);
dates2.add(date3);
dates.add(date1);
try {
assertEquals(taskCreator.extractDate(input1), dates);
} catch (RoomShareException e) {
e.printStackTrace();
}
try {
assertEquals(taskCreator.extractDate(input3), dates2);
} catch (RoomShareException e) {
e.printStackTrace();
}
}

@Test
void extractType() {
try {
assertEquals(taskCreator.extractType(input1), "meeting");
} catch (RoomShareException e) {
e.printStackTrace();
}
try {
assertEquals(taskCreator.extractType(input2), "meeting");
} catch (RoomShareException e) {
e.printStackTrace();
}
try {
assertEquals(taskCreator.extractType(input3), "leave");
} catch (RoomShareException e) {
e.printStackTrace();
}
}

@Test
void extractPriority() {
assertEquals(taskCreator.extractPriority(input1), Priority.high);
assertEquals(taskCreator.extractPriority(input2), Priority.low);
}

@Test
void extractAssignee() {
assertEquals(taskCreator.extractAssignee(input1), "john");
assertEquals(taskCreator.extractAssignee(input2), "everyone");
}

@Test
void extractRecurrence() {
assertEquals(taskCreator.extractRecurrence(input1), RecurrenceScheduleType.week);
assertEquals(taskCreator.extractRecurrence(input2), RecurrenceScheduleType.none);
}

@Test
void extractDuration() {
Pair<Integer, TimeUnit> pair = new Pair<>(2, TimeUnit.hours);
Pair<Integer, TimeUnit> pair2 = new Pair<>(0, TimeUnit.unDefined);
assertEquals(taskCreator.extractDuration(input1), pair);
assertEquals(taskCreator.extractDuration(input2), pair2);
}

@Test
void extractReminder() {
assertTrue(taskCreator.extractReminder(input1));
assertFalse(taskCreator.extractReminder(input2));
}

@Test
void create() {

}
}

0 comments on commit c4918f5

Please sign in to comment.