Skip to content

Commit

Permalink
Merge pull request #42 from CS2103JAN2017-W15-B4/pass-junit
Browse files Browse the repository at this point in the history
Modify JUnit tests for the refactored Task
  • Loading branch information
yirui94 authored Mar 8, 2017
2 parents 9aa72d5 + 94f823e commit c092148
Show file tree
Hide file tree
Showing 15 changed files with 144 additions and 161 deletions.
6 changes: 3 additions & 3 deletions src/main/java/seedu/geekeep/model/task/EndDateTime.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ public EndDateTime(String dateTimeString) throws IllegalValueException {
@Override
public boolean equals(Object other) {
return other == this // short circuit if same object
|| (other instanceof StartDateTime // instanceof handles nulls
&& this.dateTime.equals(((StartDateTime) other).dateTime)); // state check
|| (other instanceof EndDateTime // instanceof handles nulls
&& this.value.equals(((EndDateTime) other).value)); // state check
}

@Override
Expand All @@ -46,7 +46,7 @@ public int hashCode() {

@Override
public String toString() {
return dateTime.toString();
return value;
}

}
4 changes: 2 additions & 2 deletions src/main/java/seedu/geekeep/model/task/StartDateTime.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public StartDateTime(String dateTimeString) throws IllegalValueException {
public boolean equals(Object other) {
return other == this // short circuit if same object
|| (other instanceof StartDateTime // instanceof handles nulls
&& this.dateTime.equals(((StartDateTime) other).dateTime)); // state check
&& this.value.equals(((StartDateTime) other).value)); // state check
}

@Override
Expand All @@ -46,7 +46,7 @@ public int hashCode() {

@Override
public String toString() {
return dateTime.toString();
return value;
}

}
50 changes: 25 additions & 25 deletions src/main/java/seedu/geekeep/model/util/SampleDataUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,31 +15,31 @@ public class SampleDataUtil {
public static Task[] getSampleTasks() {
try {
return new Task[] {
new Task(new Title("Meeting 1"), new StartDateTime("2017-04-01T10:15:30"),
new EndDateTime("2017-04-01T10:16:30"),
new Location("Blk 30 Geylang Street 29, #06-40"),
new UniqueTagList("friends")),
new Task(new Title("Meeting 2"), new StartDateTime("2017-04-02T10:15:30"),
new EndDateTime("2017-04-02T10:16:30"),
new Location("Blk 30 Lorong 3 Serangoon Gardens, #07-18"),
new UniqueTagList("colleagues", "friends")),
new Task(new Title("Meeting 3"), new StartDateTime("2017-04-03T10:15:30"),
new EndDateTime("2017-04-03T10:16:30"),
new Location("Blk 11 Ang Mo Kio Street 74, #11-04"),
new UniqueTagList("neighbours")),
new Task(new Title("Meeting 4"), new StartDateTime("2017-04-04T10:15:30"),
new EndDateTime("2017-04-04T10:16:30"),
new Location("Blk 436 Serangoon Gardens Street 26, #16-43"),
new UniqueTagList("family")),
new Task(new Title("Meeting 5"), new StartDateTime("2017-04-05T10:15:30"),
new EndDateTime("2017-04-05T10:16:30"),
new Location("Blk 47 Tampines Street 20, #17-35"),
new UniqueTagList("classmates")),
new Task(new Title("Meeting 6"), new StartDateTime("2017-04-06T10:15:30"),
new EndDateTime("2017-04-06T10:16:30"),
new Location("Blk 45 Aljunied Street 85, #11-31"),
new UniqueTagList("colleagues"))
};
new Task(new Title("Alex Yeoh"), new StartDateTime("2017-04-01T10:16:30"),
new EndDateTime("2017-04-01T10:16:30"),
new Location("Blk 30 Geylang Street 29, #06-40"),
new UniqueTagList("friends")),
new Task(new Title("Bernice Yu"), new StartDateTime("2017-04-01T10:16:30"),
new EndDateTime("2017-04-01T10:16:30"),
new Location("Blk 30 Lorong 3 Serangoon Gardens, #07-18"),
new UniqueTagList("colleagues", "friends")),
new Task(new Title("Charlotte Oliveiro"), new StartDateTime("2017-04-01T10:16:30"),
new EndDateTime("2017-04-01T10:16:30"),
new Location("Blk 11 Ang Mo Kio Street 74, #11-04"),
new UniqueTagList("neighbours")),
new Task(new Title("David Li"), new StartDateTime("2017-04-01T10:16:30"),
new EndDateTime("2017-04-01T10:16:30"),
new Location("Blk 436 Serangoon Gardens Street 26, #16-43"),
new UniqueTagList("family")),
new Task(new Title("Irfan Ibrahim"), new StartDateTime("2017-04-01T10:16:30"),
new EndDateTime("2017-04-01T10:16:30"),
new Location("Blk 47 Tampines Street 20, #17-35"),
new UniqueTagList("classmates")),
new Task(new Title("Roy Balakrishnan"), new StartDateTime("2017-04-01T10:16:30"),
new EndDateTime("2017-04-01T10:16:30"),
new Location("Blk 45 Aljunied Street 85, #11-31"),
new UniqueTagList("colleagues"))
};
} catch (IllegalValueException e) {
throw new AssertionError("sample data cannot be invalid", e);
}
Expand Down
20 changes: 12 additions & 8 deletions src/test/java/guitests/EditCommandTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,15 @@ public class EditCommandTest extends AddressBookGuiTest {

@Test
public void edit_allFieldsSpecified_success() throws Exception {
String detailsToEdit = "Bobby p/91234567 e/[email protected] a/Block 123, Bobby Street 3 t/husband";
String detailsToEdit
= "Bobby s/2017-04-01T10:16:30 e/2017-04-01T10:16:30 l/Block 123, Bobby Street 3 t/husband";
int addressBookIndex = 1;

TestPerson editedPerson = new PersonBuilder().withName("Bobby").withPhone("91234567")
.withEmail("[email protected]").withAddress("Block 123, Bobby Street 3").withTags("husband").build();
TestPerson editedPerson = new PersonBuilder().withName("Bobby")
.withEndDateTime("2017-04-01T10:16:30")
.withStartDateTime("2017-04-01T10:16:30")
.withLocation("Block 123, Bobby Street 3")
.withTags("husband").build();

assertEditSuccess(addressBookIndex, addressBookIndex, detailsToEdit, editedPerson);
}
Expand Down Expand Up @@ -93,13 +97,13 @@ public void edit_invalidValues_failure() {
commandBox.runCommand("edit 1 *&");
assertResultMessage(Title.MESSAGE_TITLE_CONSTRAINTS);

commandBox.runCommand("edit 1 p/abcd");
commandBox.runCommand("edit 1 e/abcd");
assertResultMessage(EndDateTime.MESSAGE_DATETIME_CONSTRAINTS);

commandBox.runCommand("edit 1 e/yahoo!!!");
commandBox.runCommand("edit 1 s/yahoo!!!");
assertResultMessage(StartDateTime.MESSAGE_DATETIME_CONSTRAINTS);

commandBox.runCommand("edit 1 a/");
commandBox.runCommand("edit 1 l/");
assertResultMessage(Location.MESSAGE_LOCATION_CONSTRAINTS);

commandBox.runCommand("edit 1 t/*&");
Expand All @@ -108,8 +112,8 @@ public void edit_invalidValues_failure() {

@Test
public void edit_duplicatePerson_failure() {
commandBox.runCommand("edit 3 Alice Pauline p/85355255 e/[email protected] "
+ "a/123, Jurong West Ave 6, #08-111 t/friends");
commandBox.runCommand("edit 3 Alice Pauline s/2017-04-01T10:16:30 e/2017-04-01T10:16:30 "
+ "l/123, Jurong West Ave 6, #08-111 t/friends");
assertResultMessage(EditCommand.MESSAGE_DUPLICATE_PERSON);
}

Expand Down
39 changes: 22 additions & 17 deletions src/test/java/seedu/geekeep/logic/LogicManagerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -188,21 +188,26 @@ public void execute_clear() throws Exception {
@Test
public void execute_add_invalidArgsFormat() {
String expectedMessage = String.format(MESSAGE_INVALID_COMMAND_FORMAT, AddCommand.MESSAGE_USAGE);
assertCommandFailure("add wrong args wrong args", expectedMessage);
assertCommandFailure("add Valid Name 12345 e/[email protected] a/valid,address", expectedMessage);
assertCommandFailure("add Valid Name p/12345 [email protected] a/valid, address", expectedMessage);
assertCommandFailure("add Valid Name p/12345 e/[email protected] valid, address", expectedMessage);
assertCommandFailure("add wrong args wrong args",
expectedMessage);
assertCommandFailure("add Valid Name 2017-04-01T10:16:30 e/2017-04-01T10:16:30 l/valid,address",
expectedMessage);
assertCommandFailure("add Valid Name s/2017-04-01T10:16:30 2017-04-01T10:16:30 l/valid, address",
expectedMessage);
assertCommandFailure("add Valid Name s/2017-04-01T10:16:30 e/2017-04-01T10:16:30 valid, address",
expectedMessage);
}

@Test
public void execute_add_invalidPersonData() {
assertCommandFailure("add []\\[;] p/12345 e/[email protected] a/valid, address",
assertCommandFailure("add []\\[;] s/2017-04-01T10:16:30 e/2017-04-01T10:16:30 l/valid, address",
Title.MESSAGE_TITLE_CONSTRAINTS);
assertCommandFailure("add Valid Name p/not_numbers e/[email protected] a/valid, address",
assertCommandFailure("add Valid Name s/not_numbers e/2017-04-01T10:16:30 l/valid, address",
EndDateTime.MESSAGE_DATETIME_CONSTRAINTS);
assertCommandFailure("add Valid Name p/12345 e/notAnEmail a/valid, address",
assertCommandFailure("add Valid Name s/2017-04-01T10:16:30 e/notAnEmail l/valid, address",
StartDateTime.MESSAGE_DATETIME_CONSTRAINTS);
assertCommandFailure("add Valid Name p/12345 e/[email protected] a/valid, address t/invalid_-[.tag",
assertCommandFailure(
"add Valid Name s/2017-04-01T10:16:30 e/2017-04-01T10:16:30 l/valid, address t/invalid_-[.tag",
Tag.MESSAGE_TAG_CONSTRAINTS);

}
Expand Down Expand Up @@ -416,8 +421,8 @@ class TestDataHelper {

Task adam() throws Exception {
Title title = new Title("Adam Brown");
EndDateTime privateEndDateTime = new EndDateTime("111111");
StartDateTime startDateTime = new StartDateTime("[email protected]");
EndDateTime privateEndDateTime = new EndDateTime("2017-04-01T10:16:30");
StartDateTime startDateTime = new StartDateTime("2017-04-01T10:16:30");
Location privateLocation = new Location("111, alpha street");
Tag tag1 = new Tag("tag1");
Tag tag2 = new Tag("longertag2");
Expand All @@ -435,8 +440,8 @@ Task adam() throws Exception {
Task generateTask(int seed) throws Exception {
return new Task(
new Title("Person " + seed),
new StartDateTime(seed + "@email"),
new EndDateTime("" + Math.abs(seed)),
new StartDateTime("2017-04-01T10:16:30"),
new EndDateTime("2017-04-01T10:16:30"),
new Location("House of " + seed),
new UniqueTagList(new Tag("tag" + Math.abs(seed)), new Tag("tag" + Math.abs(seed + 1)))
);
Expand All @@ -449,9 +454,9 @@ String generateAddCommand(Task p) {
cmd.append("add ");

cmd.append(p.getTitle().toString());
cmd.append(" e/").append(p.getStartDateTime());
cmd.append(" p/").append(p.getEndDateTime());
cmd.append(" a/").append(p.getLocation());
cmd.append(" s/").append(p.getStartDateTime());
cmd.append(" e/").append(p.getEndDateTime());
cmd.append(" l/").append(p.getLocation());

UniqueTagList tags = p.getTags();
for (Tag t: tags) {
Expand Down Expand Up @@ -534,8 +539,8 @@ List<Task> generateTaskList(Task... persons) {
Task generateTaskWithName(String name) throws Exception {
return new Task(
new Title(name),
new StartDateTime("1@email"),
new EndDateTime("1"),
new StartDateTime("2017-04-01T10:16:30"),
new EndDateTime("2017-04-01T10:16:30"),
new Location("House of 1"),
new UniqueTagList(new Tag("tag"))
);
Expand Down
42 changes: 0 additions & 42 deletions src/test/java/seedu/geekeep/model/person/EmailTest.java

This file was deleted.

21 changes: 21 additions & 0 deletions src/test/java/seedu/geekeep/model/person/EndDateTimeTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package seedu.geekeep.model.person;

import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;

import org.junit.Test;

import seedu.geekeep.model.task.EndDateTime;

public class EndDateTimeTest {

@Test
public void isValidEndDateTime() {
// invalid end date time
assertFalse(EndDateTime.isValidDateTime("")); // empty string
assertFalse(EndDateTime.isValidDateTime(" ")); // spaces only

// valid end date time
assertTrue(EndDateTime.isValidDateTime("2017-04-01T10:16:30"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@

import seedu.geekeep.model.task.Location;

public class AddressTest {
public class LocationTest {

@Test
public void isValidAddress() {
// invalid addresses
public void isValidLocation() {
// invalid locations
assertFalse(Location.isValidLocation("")); // empty string
assertFalse(Location.isValidLocation(" ")); // spaces only

// valid addresses
// valid locations
assertTrue(Location.isValidLocation("Blk 456, Den Road, #01-355"));
assertTrue(Location.isValidLocation("-")); // one character
assertTrue(Location.isValidLocation("Leng Inc; 1234 Market St; San Francisco CA 2349879; USA")); // long address
Expand Down
26 changes: 0 additions & 26 deletions src/test/java/seedu/geekeep/model/person/PhoneTest.java

This file was deleted.

21 changes: 21 additions & 0 deletions src/test/java/seedu/geekeep/model/person/StartDateTimeTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package seedu.geekeep.model.person;

import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;

import org.junit.Test;

import seedu.geekeep.model.task.StartDateTime;

public class StartDateTimeTest {

@Test
public void isValidStartDateTime() {
// invalid start date time
assertFalse(StartDateTime.isValidDateTime("")); // empty string
assertFalse(StartDateTime.isValidDateTime(" ")); // spaces only

// valid start date time
assertTrue(StartDateTime.isValidDateTime("2017-04-01T10:16:30"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import seedu.geekeep.model.task.Title;

public class NameTest {
public class TitleTest {

@Test
public void isValidName() {
Expand Down
6 changes: 3 additions & 3 deletions src/test/java/seedu/geekeep/testutil/PersonBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,17 +39,17 @@ public PersonBuilder withTags(String ... tags) throws IllegalValueException {
return this;
}

public PersonBuilder withAddress(String address) throws IllegalValueException {
public PersonBuilder withLocation(String address) throws IllegalValueException {
this.person.setLocation(new Location(address));
return this;
}

public PersonBuilder withPhone(String phone) throws IllegalValueException {
public PersonBuilder withEndDateTime(String phone) throws IllegalValueException {
this.person.setEndDateTime(new EndDateTime(phone));
return this;
}

public PersonBuilder withEmail(String email) throws IllegalValueException {
public PersonBuilder withStartDateTime(String email) throws IllegalValueException {
this.person.setStartDateTime(new StartDateTime(email));
return this;
}
Expand Down
6 changes: 3 additions & 3 deletions src/test/java/seedu/geekeep/testutil/TestPerson.java
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,9 @@ public String toString() {
public String getAddCommand() {
StringBuilder sb = new StringBuilder();
sb.append("add " + this.getTitle().fullTitle + " ");
sb.append("a/" + this.getLocation().value + " ");
sb.append("p/" + this.getEndDateTime().value + " ");
sb.append("e/" + this.getStartDateTime().value + " ");
sb.append("l/" + this.getLocation().value + " ");
sb.append("e/" + this.getEndDateTime().value + " ");
sb.append("s/" + this.getStartDateTime().value + " ");
this.getTags().asObservableList().stream().forEach(s -> sb.append("t/" + s.tagName + " "));
return sb.toString();
}
Expand Down
Loading

0 comments on commit c092148

Please sign in to comment.