Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add JUnit tests for ViewCommandParser and ViewCommand #145

Merged
merged 60 commits into from
Apr 1, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
60 commits
Select commit Hold shift + click to select a range
92cb2cd
Planner: Initialize weekType for each Day
dingheng4448 Mar 7, 2019
1a98449
Planner: Fix Codacy issue
dingheng4448 Mar 7, 2019
45f7915
Planner: Update code for initialisation of semester
dingheng4448 Mar 8, 2019
2c631df
Planner: Fix Codacy and checkstyle issues
dingheng4448 Mar 9, 2019
20b4abb
Merge branch 'master' into develop
dingheng4448 Mar 9, 2019
5ac6ca9
Planner: Fix build error
dingheng4448 Mar 9, 2019
7e5b58c
Planner: Dynamic generation of semester from date
dingheng4448 Mar 16, 2019
60d1cda
PlannerTest: Add JUnit test for generateSemester
dingheng4448 Mar 16, 2019
93b40ed
Merge remote-tracking branch 'origin/develop' into develop
dingheng4448 Mar 16, 2019
a8d57fe
Merge branch 'master' of https://github.com/CS2113-AY1819S2-T08-3/mai…
dingheng4448 Mar 17, 2019
a002fdc
Merge branch 'master' of https://github.com/CS2113-AY1819S2-T08-3/mai…
dingheng4448 Mar 17, 2019
dbcf1fd
Update documentation for view command
dingheng4448 Mar 17, 2019
f3ce309
Merge branch 'master' of https://github.com/CS2113-AY1819S2-T08-3/mai…
dingheng4448 Mar 17, 2019
8d35cfb
Merge branch 'master' of https://github.com/CS2113-AY1819S2-T08-3/mai…
dingheng4448 Mar 17, 2019
aa42b48
Merge branch 'master' of https://github.com/CS2113-AY1819S2-T08-3/mai…
dingheng4448 Mar 17, 2019
f0d916b
Add view command for monthly calendar view
dingheng4448 Mar 18, 2019
132bb01
Merge branch 'master' of https://github.com/CS2113-AY1819S2-T08-3/mai…
dingheng4448 Mar 18, 2019
1eded38
Fix Codacy issue
dingheng4448 Mar 18, 2019
db15e14
Merge branch 'master' of https://github.com/CS2113-AY1819S2-T08-3/mai…
dingheng4448 Mar 19, 2019
bfac078
UserGuide: Update user guide documentation
dingheng4448 Mar 19, 2019
936a880
UserGuide: Update user guide documentation
dingheng4448 Mar 19, 2019
6c679a2
UserGuide: Update user guide documentation
dingheng4448 Mar 20, 2019
a2c34fa
UserGuide: Update user guide documentation
dingheng4448 Mar 21, 2019
732c15e
Merge remote-tracking branch 'origin/develop' into develop
dingheng4448 Mar 21, 2019
e14f476
UserGuide: Update user guide documentation
dingheng4448 Mar 21, 2019
4b1781b
Merge branch 'master' of https://github.com/CS2113-AY1819S2-T08-3/mai…
dingheng4448 Mar 21, 2019
d7cb580
UserGuide: Update user guide documentation
dingheng4448 Mar 21, 2019
24ac7d5
Merge branch 'master' of https://github.com/CS2113-AY1819S2-T08-3/mai…
dingheng4448 Mar 21, 2019
9967d8d
Merge branch 'master' of https://github.com/CS2113-AY1819S2-T08-3/mai…
dingheng4448 Mar 23, 2019
17f1e8d
Moved Semester generation code
dingheng4448 Mar 24, 2019
48db5f1
Planner: remove unused imports
dingheng4448 Mar 24, 2019
fe1f0e4
Semester: undo minor change
dingheng4448 Mar 24, 2019
abcb88b
Merge branch 'master' of https://github.com/CS2113-AY1819S2-T08-3/mai…
dingheng4448 Mar 24, 2019
7a60cb4
DeveloperGuide: Update documentation on initialization of Semester
dingheng4448 Mar 24, 2019
eb4f062
Merge branch 'master' into develop
dingheng4448 Mar 24, 2019
997c9da
Merge branch 'master' of https://github.com/CS2113-AY1819S2-T08-3/mai…
dingheng4448 Mar 29, 2019
33b0875
Merge remote-tracking branch 'origin/develop' into develop
dingheng4448 Mar 29, 2019
dcc4a84
Merge commit
dingheng4448 Mar 29, 2019
f3d3b3a
Update view command for calendar day view
dingheng4448 Mar 30, 2019
0006b62
Update view command for calendar week view
dingheng4448 Mar 30, 2019
873fcb9
Merge branch 'master' of https://github.com/CS2113-AY1819S2-T08-3/mai…
dingheng4448 Mar 30, 2019
602a0dd
Update view command for calendar week view
dingheng4448 Mar 31, 2019
82634b3
Update JUnit test for Planner
dingheng4448 Mar 31, 2019
0096e94
Merge branch 'master' of https://github.com/CS2113-AY1819S2-T08-3/mai…
dingheng4448 Mar 31, 2019
19f0c79
Update User Guide for view command
dingheng4448 Mar 31, 2019
018551b
Update User Guide for view command
dingheng4448 Mar 31, 2019
a75c293
Fix Codacy issue
dingheng4448 Mar 31, 2019
65fba29
Merge branch 'master' of https://github.com/CS2113-AY1819S2-T08-3/mai…
dingheng4448 Mar 31, 2019
a48253d
DeveloperGuide: Update view feature documentation
dingheng4448 Mar 31, 2019
3011d76
DeveloperGuide: Update view feature documentation
dingheng4448 Mar 31, 2019
8c98521
DeveloperGuide: Update view feature documentation formatting
dingheng4448 Mar 31, 2019
2c7bdcf
DeveloperGuide: Update introduction
dingheng4448 Apr 1, 2019
bfa4b63
Update ViewCommand and ViewCommandParser
dingheng4448 Apr 1, 2019
3427b3b
Merge branch 'master' into develop
dingheng4448 Apr 1, 2019
a0d8e6e
Merge branch 'master' of https://github.com/CS2113-AY1819S2-T08-3/mai…
dingheng4448 Apr 1, 2019
274e8e2
Merge remote-tracking branch 'origin/develop' into develop
dingheng4448 Apr 1, 2019
1eb6df0
Update view command to fix minor bug
dingheng4448 Apr 1, 2019
19ebab3
Fix Junit test for PlannerTest
dingheng4448 Apr 1, 2019
365ea65
Add JUnit tests for ViewCommandParser and ViewCommand
dingheng4448 Apr 1, 2019
efcf174
Merge branch 'master' of https://github.com/CS2113-AY1819S2-T08-3/mai…
dingheng4448 Apr 1, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/planmysem/logic/commands/ViewCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import java.time.format.DateTimeFormatter;
import java.time.temporal.WeekFields;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
Expand Down Expand Up @@ -459,4 +460,11 @@ public int compare(final Slot o1, final Slot o2) {

return sb.toString();
}

@Override
public boolean equals(Object other) {
return other == this // short circuit if same object
|| (other instanceof ViewCommand // instanceof handles nulls
&& Arrays.equals(viewArgs, ((ViewCommand) other).viewArgs));
}
}
7 changes: 1 addition & 6 deletions src/planmysem/logic/parser/ViewCommandParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,9 @@
import static planmysem.common.Messages.MESSAGE_ILLEGAL_WEEK_VALUE;
import static planmysem.common.Messages.MESSAGE_INVALID_COMMAND_FORMAT;
import static planmysem.common.Messages.MESSAGE_INVALID_DATE;
import static planmysem.common.Utils.getNearestDayOfWeek;

import java.time.LocalDate;

import planmysem.common.Clock;
import planmysem.common.Utils;
import planmysem.logic.commands.ViewCommand;
import planmysem.logic.parser.exceptions.ParseException;
Expand Down Expand Up @@ -55,7 +53,7 @@ public ViewCommand parse(String args) throws ParseException {
}
return new ViewCommand(viewArgs);

} else if (viewArgs.length == 3 ) {
} else if (viewArgs.length == 3) {
viewArgs[1] = viewArgs[1].substring(0, 1).toUpperCase() + viewArgs[1].substring(1).toLowerCase();
viewArgs[2] = viewArgs[2].substring(0, 1).toUpperCase() + viewArgs[2].substring(1).toLowerCase();
if ("Exam".equals(viewArgs[1])) {
Expand Down Expand Up @@ -94,9 +92,6 @@ public ViewCommand parse(String args) throws ParseException {
if (day == -1 && date == null) {
throw new ParseException(String.format(MESSAGE_INVALID_DATE, ViewCommand.MESSAGE_USAGE));
}
if (day != -1) {
date = getNearestDayOfWeek(LocalDate.now(Clock.get()), day);
}

return new ViewCommand(viewArgs);
}
Expand Down
228 changes: 228 additions & 0 deletions test/java/planmysem/logic/Commands/ViewCommandTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,228 @@
package planmysem.logic.Commands;

import static junit.framework.TestCase.assertEquals;

import java.time.DayOfWeek;
import java.time.LocalDate;
import java.util.Map;
import java.util.TreeMap;

import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;

import javafx.util.Pair;
import planmysem.common.Clock;
import planmysem.logic.CommandHistory;
import planmysem.logic.commands.CommandResult;
import planmysem.logic.commands.ViewCommand;
import planmysem.model.Model;
import planmysem.model.ModelManager;
import planmysem.model.semester.Day;
import planmysem.model.semester.ReadOnlyDay;
import planmysem.model.slot.ReadOnlySlot;
import planmysem.testutil.SlotBuilder;

public class ViewCommandTest {
private Model model;
private Model expectedModel;
private Pair<LocalDate, Pair<ReadOnlyDay, ReadOnlySlot>> pair1;
private Pair<LocalDate, Pair<ReadOnlyDay, ReadOnlySlot>> pair2;
private Pair<LocalDate, Pair<ReadOnlyDay, ReadOnlySlot>> pair3;
private Pair<LocalDate, Pair<ReadOnlyDay, ReadOnlySlot>> pair4;
private CommandHistory commandHistory = new CommandHistory();

private SlotBuilder slotBuilder = new SlotBuilder();

@Rule
public ExpectedException thrown = ExpectedException.none();

@Before
public void setup() throws Exception {
Clock.set("2019-01-14T10:00:00Z");

// Create typical planner
model = new ModelManager();
pair1 = new Pair<>(
LocalDate.of(2019, 02, 01),
new Pair<>(
new Day(
DayOfWeek.FRIDAY,
"Week 3"
),
slotBuilder.slotOne()
)
);
pair2 = new Pair<>(
LocalDate.of(2019, 02, 02),
new Pair<>(
new Day(
DayOfWeek.SATURDAY,
"Week 3"
),
slotBuilder.slotOne()
)
);
pair3 = new Pair<>(
LocalDate.of(2019, 02, 03),
new Pair<>(
new Day(
DayOfWeek.SUNDAY,
"Week 3"
),
slotBuilder.slotOne()
)
);
pair4 = new Pair<>(
LocalDate.of(2019, 02, 04),
new Pair<>(
new Day(
DayOfWeek.MONDAY,
"Week 4"
),
slotBuilder.slotOne()
)
);
model.addSlot(LocalDate.of(2019, 02, 01), slotBuilder.slotOne());
model.addSlot(LocalDate.of(2019, 02, 02), slotBuilder.slotOne());
model.addSlot(LocalDate.of(2019, 02, 02), slotBuilder.slotOne());
model.addSlot(LocalDate.of(2019, 02, 03), slotBuilder.slotOne());
model.addSlot(LocalDate.of(2019, 02, 04), slotBuilder.slotOne());

Map<LocalDate, Pair<ReadOnlyDay, ReadOnlySlot>> list = new TreeMap<>();
list.put(pair4.getKey(), pair4.getValue());
list.put(pair3.getKey(), pair3.getValue());
list.put(pair2.getKey(), pair2.getValue());
list.put(pair2.getKey(), pair2.getValue());
list.put(pair1.getKey(), pair1.getValue());
model.setLastShownList(list);

expectedModel = new ModelManager();
expectedModel.addSlot(LocalDate.of(2019, 02, 01), slotBuilder.slotOne());
expectedModel.addSlot(LocalDate.of(2019, 02, 02), slotBuilder.slotOne());
expectedModel.addSlot(LocalDate.of(2019, 02, 02), slotBuilder.slotOne());
expectedModel.addSlot(LocalDate.of(2019, 02, 03), slotBuilder.slotOne());
expectedModel.addSlot(LocalDate.of(2019, 02, 04), slotBuilder.slotOne());
expectedModel.setLastShownList(model.getLastShownList());
}

@Test
public void execute_displayMonthView_success() {
ViewCommand expectedCommand = new ViewCommand(new String[]{"month"});
CommandResult expectedCommandResult = expectedCommand.execute(expectedModel, commandHistory);

ViewCommand actualCommand = new ViewCommand(new String[]{"month"});
CommandResult actualCommandResult = actualCommand.execute(model, commandHistory);

assertEquals(expectedCommandResult.getFeedbackToUser(), actualCommandResult.getFeedbackToUser());
}

@Test
public void execute_displayWeekView_success() {
ViewCommand expectedCommand = new ViewCommand(new String[]{"week"});
CommandResult expectedCommandResult = expectedCommand.execute(expectedModel, commandHistory);

ViewCommand actualCommand = new ViewCommand(new String[]{"week"});
CommandResult actualCommandResult = actualCommand.execute(model, commandHistory);

assertEquals(expectedCommandResult.getFeedbackToUser(), actualCommandResult.getFeedbackToUser());

expectedCommand = new ViewCommand(new String[]{"week", "Examination"});
expectedCommandResult = expectedCommand.execute(expectedModel, commandHistory);

actualCommand = new ViewCommand(new String[]{"week", "Examination"});
actualCommandResult = actualCommand.execute(model, commandHistory);

assertEquals(expectedCommandResult.getFeedbackToUser(), actualCommandResult.getFeedbackToUser());

expectedCommand = new ViewCommand(new String[]{"week", "3"});
expectedCommandResult = expectedCommand.execute(expectedModel, commandHistory);

actualCommand = new ViewCommand(new String[]{"week", "3"});
actualCommandResult = actualCommand.execute(model, commandHistory);

assertEquals(expectedCommandResult.getFeedbackToUser(), actualCommandResult.getFeedbackToUser());
}

@Test
public void execute_displayDetailedWeekView_success() {
ViewCommand expectedCommand = new ViewCommand(new String[]{"week", "Details"});
CommandResult expectedCommandResult = expectedCommand.execute(expectedModel, commandHistory);

ViewCommand actualCommand = new ViewCommand(new String[]{"week", "Details"});
CommandResult actualCommandResult = actualCommand.execute(model, commandHistory);

assertEquals(expectedCommandResult.getFeedbackToUser(), actualCommandResult.getFeedbackToUser());

expectedCommand = new ViewCommand(new String[]{"week", "Examination", "Details"});
expectedCommandResult = expectedCommand.execute(expectedModel, commandHistory);

actualCommand = new ViewCommand(new String[]{"week", "Examination", "Details"});
actualCommandResult = actualCommand.execute(model, commandHistory);

assertEquals(expectedCommandResult.getFeedbackToUser(), actualCommandResult.getFeedbackToUser());

expectedCommand = new ViewCommand(new String[]{"week", "3", "Details"});
expectedCommandResult = expectedCommand.execute(expectedModel, commandHistory);

actualCommand = new ViewCommand(new String[]{"week", "3", "Details"});
actualCommandResult = actualCommand.execute(model, commandHistory);

assertEquals(expectedCommandResult.getFeedbackToUser(), actualCommandResult.getFeedbackToUser());
}

@Test
public void execute_displayDayView_success() {
ViewCommand expectedCommand = new ViewCommand(new String[]{"day"});
CommandResult expectedCommandResult = expectedCommand.execute(expectedModel, commandHistory);

ViewCommand actualCommand = new ViewCommand(new String[]{"day"});
CommandResult actualCommandResult = actualCommand.execute(model, commandHistory);

assertEquals(expectedCommandResult.getFeedbackToUser(), actualCommandResult.getFeedbackToUser());

expectedCommand = new ViewCommand(new String[]{"day", "1"});
expectedCommandResult = expectedCommand.execute(expectedModel, commandHistory);

actualCommand = new ViewCommand(new String[]{"day", "1"});
actualCommandResult = actualCommand.execute(model, commandHistory);

assertEquals(expectedCommandResult.getFeedbackToUser(), actualCommandResult.getFeedbackToUser());

expectedCommand = new ViewCommand(new String[]{"day", "02-02"});
expectedCommandResult = expectedCommand.execute(expectedModel, commandHistory);

actualCommand = new ViewCommand(new String[]{"day", "02-02"});
actualCommandResult = actualCommand.execute(model, commandHistory);

assertEquals(expectedCommandResult.getFeedbackToUser(), actualCommandResult.getFeedbackToUser());
}

@Test
public void execute_displayDayView_failure() {
ViewCommand expectedCommand = new ViewCommand(new String[]{"day", "29-02"});
CommandResult expectedCommandResult = expectedCommand.execute(expectedModel, commandHistory);

ViewCommand actualCommand = new ViewCommand(new String[]{"day", "29-02"});
CommandResult actualCommandResult = actualCommand.execute(model, commandHistory);

assertEquals(expectedCommandResult.getFeedbackToUser(), actualCommandResult.getFeedbackToUser());

expectedCommand = new ViewCommand(new String[]{"day", "01-01"});
expectedCommandResult = expectedCommand.execute(expectedModel, commandHistory);

actualCommand = new ViewCommand(new String[]{"day", "01-01"});
actualCommandResult = actualCommand.execute(model, commandHistory);

assertEquals(expectedCommandResult.getFeedbackToUser(), actualCommandResult.getFeedbackToUser());

expectedCommand = new ViewCommand(new String[]{"day", "0"});
expectedCommandResult = expectedCommand.execute(expectedModel, commandHistory);

actualCommand = new ViewCommand(new String[]{"day", "0"});
actualCommandResult = actualCommand.execute(model, commandHistory);

assertEquals(expectedCommandResult.getFeedbackToUser(), actualCommandResult.getFeedbackToUser());
}
}
3 changes: 1 addition & 2 deletions test/java/planmysem/logic/parser/AddCommandParserTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,7 @@ public void parse_minimalFields_success() {
LocalTime.of(8, 0),
LocalTime.of(9, 0),
null
)
, new Recurrence(
), new Recurrence(
null,
1
)));
Expand Down
Loading