Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
nixonwidjaja committed Oct 12, 2023
1 parent 771696d commit 9d8c0b3
Show file tree
Hide file tree
Showing 7 changed files with 81 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
"salary": "100000",
"claimBudget": "1",
"department": "Finance",
"dob": "2002-02-27"
"dob": "2002-02-27",
"leave": "111101010101"
},
{
"name": "Alice Pauline",
Expand All @@ -18,7 +19,8 @@
"salary": "100000",
"claimBudget": "1",
"department": "Finance",
"dob": "2002-02-27"
"dob": "2002-02-27",
"leave": "111101010101"
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
"salary": "10000",
"claimBudget": "5000",
"department": "Engineering",
"dob": "2000-01-01"
"dob": "2000-01-01",
"leave": "111101010101"
},
{
"name": "Benson Meier",
Expand All @@ -19,7 +20,8 @@
"salary": "100",
"claimBudget": "5",
"department": "Sales",
"dob": "1997-05-05"
"dob": "1997-05-05",
"leave": "010101010101"
},
{
"name": "Carl Kurz",
Expand All @@ -29,7 +31,8 @@
"salary": "1000000000000",
"claimBudget": "500000",
"department": "Executive",
"dob": "1991-12-31"
"dob": "1991-12-31",
"leave": "000101010001"
},
{
"name": "Daniel Meier",
Expand All @@ -39,7 +42,8 @@
"salary": "23232323232",
"claimBudget": "19191919",
"department": "Marketing",
"dob": "1969-07-27"
"dob": "1969-07-27",
"leave": "111111111111"
},
{
"name": "Elle Meyer",
Expand All @@ -49,7 +53,8 @@
"salary": "3000",
"claimBudget": "200",
"department": "HR",
"dob": "1999-06-17"
"dob": "1999-06-17",
"leave": "000000000001"
},
{
"name": "Fiona Kunz",
Expand All @@ -59,7 +64,8 @@
"salary": "100000",
"claimBudget": "1",
"department": "Finance",
"dob": "2002-02-27"
"dob": "2002-02-27",
"leave": "000000100000"
},
{
"name": "George Best",
Expand All @@ -69,7 +75,8 @@
"salary": "10000",
"claimBudget": "5000",
"department": "Engineering",
"dob": "2005-09-30"
"dob": "2005-09-30",
"leave": "111111000000"
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ public class CommandTestUtil {
public static final String VALID_BUDGET = "2500";
public static final String VALID_DEPARTMENT = "Engineering";
public static final String VALID_DOB = "2000-01-01";
public static final String VALID_LEAVE = "101010101010";
public static final String VALID_TAG_HUSBAND = "husband";
public static final String VALID_TAG_FRIEND = "friend";

Expand Down
2 changes: 1 addition & 1 deletion src/test/java/seedu/address/model/person/PersonTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public void toStringMethod() {
String expected = Person.class.getCanonicalName() + "{name=" + ALICE.getName() + ", phone=" + ALICE.getPhone()
+ ", email=" + ALICE.getEmail() + ", address=" + ALICE.getAddress() + ", salary=" + ALICE.getSalary()
+ ", claimBudget=" + ALICE.getClaimBudget() + ", department=" + ALICE.getDepartment()
+ ", dob=" + ALICE.getDob() + "}";
+ ", dob=" + ALICE.getDob() + ", leave=" + ALICE.getLeave() + "}";
assertEquals(expected, ALICE.toString());
}
}
52 changes: 36 additions & 16 deletions src/test/java/seedu/address/storage/JsonAdaptedPersonTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import seedu.address.model.person.Birthday;
import seedu.address.model.person.Department;
import seedu.address.model.person.Email;
import seedu.address.model.person.Leave;
import seedu.address.model.person.Money;
import seedu.address.model.person.Name;
import seedu.address.model.person.Phone;
Expand All @@ -25,6 +26,7 @@ public class JsonAdaptedPersonTest {
private static final String INVALID_BUDGET = "1000000000000000";
private static final String INVALID_DEPARTMENT = " ";
private static final String INVALID_DOB = "1";
private static final String INVALID_LEAVE = "1+";

private static final String VALID_NAME = BENSON.getName().toString();
private static final String VALID_PHONE = BENSON.getPhone().toString();
Expand All @@ -34,6 +36,7 @@ public class JsonAdaptedPersonTest {
private static final String VALID_BUDGET = BENSON.getClaimBudget().amount;
private static final String VALID_DEPARTMENT = BENSON.getDepartment().department;
private static final String VALID_DOB = BENSON.getDob().dob;
private static final String VALID_LEAVE = BENSON.getLeave().leave;

@Test
public void toModelType_validPersonDetails_returnsPerson() throws Exception {
Expand All @@ -45,15 +48,15 @@ public void toModelType_validPersonDetails_returnsPerson() throws Exception {
public void toModelType_invalidName_throwsIllegalValueException() {
JsonAdaptedPerson person =
new JsonAdaptedPerson(INVALID_NAME, VALID_PHONE, VALID_EMAIL, VALID_ADDRESS,
VALID_SALARY, VALID_BUDGET, VALID_DEPARTMENT, VALID_DOB);
VALID_SALARY, VALID_BUDGET, VALID_DEPARTMENT, VALID_DOB, VALID_LEAVE);
String expectedMessage = Name.MESSAGE_CONSTRAINTS;
assertThrows(IllegalValueException.class, expectedMessage, person::toModelType);
}

@Test
public void toModelType_nullName_throwsIllegalValueException() {
JsonAdaptedPerson person = new JsonAdaptedPerson(null, VALID_PHONE, VALID_EMAIL, VALID_ADDRESS,
VALID_SALARY, VALID_BUDGET, VALID_DEPARTMENT, VALID_DOB);
VALID_SALARY, VALID_BUDGET, VALID_DEPARTMENT, VALID_DOB, VALID_LEAVE);
String expectedMessage = String.format(MISSING_FIELD_MESSAGE_FORMAT, Name.class.getSimpleName());
assertThrows(IllegalValueException.class, expectedMessage, person::toModelType);
}
Expand All @@ -62,15 +65,15 @@ public void toModelType_nullName_throwsIllegalValueException() {
public void toModelType_invalidPhone_throwsIllegalValueException() {
JsonAdaptedPerson person =
new JsonAdaptedPerson(VALID_NAME, INVALID_PHONE, VALID_EMAIL, VALID_ADDRESS,
VALID_SALARY, VALID_BUDGET, VALID_DEPARTMENT, VALID_DOB);
VALID_SALARY, VALID_BUDGET, VALID_DEPARTMENT, VALID_DOB, VALID_LEAVE);
String expectedMessage = Phone.MESSAGE_CONSTRAINTS;
assertThrows(IllegalValueException.class, expectedMessage, person::toModelType);
}

@Test
public void toModelType_nullPhone_throwsIllegalValueException() {
JsonAdaptedPerson person = new JsonAdaptedPerson(VALID_NAME, null, VALID_EMAIL, VALID_ADDRESS,
VALID_SALARY, VALID_BUDGET, VALID_DEPARTMENT, VALID_DOB);
VALID_SALARY, VALID_BUDGET, VALID_DEPARTMENT, VALID_DOB, VALID_LEAVE);
String expectedMessage = String.format(MISSING_FIELD_MESSAGE_FORMAT, Phone.class.getSimpleName());
assertThrows(IllegalValueException.class, expectedMessage, person::toModelType);
}
Expand All @@ -79,15 +82,15 @@ public void toModelType_nullPhone_throwsIllegalValueException() {
public void toModelType_invalidEmail_throwsIllegalValueException() {
JsonAdaptedPerson person =
new JsonAdaptedPerson(VALID_NAME, VALID_PHONE, INVALID_EMAIL, VALID_ADDRESS,
VALID_SALARY, VALID_BUDGET, VALID_DEPARTMENT, VALID_DOB);
VALID_SALARY, VALID_BUDGET, VALID_DEPARTMENT, VALID_DOB, VALID_LEAVE);
String expectedMessage = Email.MESSAGE_CONSTRAINTS;
assertThrows(IllegalValueException.class, expectedMessage, person::toModelType);
}

@Test
public void toModelType_nullEmail_throwsIllegalValueException() {
JsonAdaptedPerson person = new JsonAdaptedPerson(VALID_NAME, VALID_PHONE, null, VALID_ADDRESS,
VALID_SALARY, VALID_BUDGET, VALID_DEPARTMENT, VALID_DOB);
VALID_SALARY, VALID_BUDGET, VALID_DEPARTMENT, VALID_DOB, VALID_LEAVE);
String expectedMessage = String.format(MISSING_FIELD_MESSAGE_FORMAT, Email.class.getSimpleName());
assertThrows(IllegalValueException.class, expectedMessage, person::toModelType);
}
Expand All @@ -96,15 +99,15 @@ public void toModelType_nullEmail_throwsIllegalValueException() {
public void toModelType_invalidAddress_throwsIllegalValueException() {
JsonAdaptedPerson person =
new JsonAdaptedPerson(VALID_NAME, VALID_PHONE, VALID_EMAIL, INVALID_ADDRESS,
VALID_SALARY, VALID_BUDGET, VALID_DEPARTMENT, VALID_DOB);
VALID_SALARY, VALID_BUDGET, VALID_DEPARTMENT, VALID_DOB, VALID_LEAVE);
String expectedMessage = Address.MESSAGE_CONSTRAINTS;
assertThrows(IllegalValueException.class, expectedMessage, person::toModelType);
}

@Test
public void toModelType_nullAddress_throwsIllegalValueException() {
JsonAdaptedPerson person = new JsonAdaptedPerson(VALID_NAME, VALID_PHONE, VALID_EMAIL, null,
VALID_SALARY, VALID_BUDGET, VALID_DEPARTMENT, VALID_DOB);
VALID_SALARY, VALID_BUDGET, VALID_DEPARTMENT, VALID_DOB, VALID_LEAVE);
String expectedMessage = String.format(MISSING_FIELD_MESSAGE_FORMAT, Address.class.getSimpleName());
assertThrows(IllegalValueException.class, expectedMessage, person::toModelType);
}
Expand All @@ -113,15 +116,15 @@ public void toModelType_nullAddress_throwsIllegalValueException() {
public void toModelType_invalidSalary_throwsIllegalValueException() {
JsonAdaptedPerson person =
new JsonAdaptedPerson(VALID_NAME, VALID_PHONE, VALID_EMAIL, VALID_ADDRESS,
INVALID_SALARY, VALID_BUDGET, VALID_DEPARTMENT, VALID_DOB);
INVALID_SALARY, VALID_BUDGET, VALID_DEPARTMENT, VALID_DOB, VALID_LEAVE);
String expectedMessage = Money.MESSAGE_CONSTRAINTS;
assertThrows(IllegalValueException.class, expectedMessage, person::toModelType);
}

@Test
public void toModelType_nullSalary_throwsIllegalValueException() {
JsonAdaptedPerson person = new JsonAdaptedPerson(VALID_NAME, VALID_PHONE, VALID_EMAIL, VALID_ADDRESS,
null, VALID_BUDGET, VALID_DEPARTMENT, VALID_DOB);
null, VALID_BUDGET, VALID_DEPARTMENT, VALID_DOB, VALID_LEAVE);
String expectedMessage = String.format(MISSING_FIELD_MESSAGE_FORMAT, Money.class.getSimpleName());
assertThrows(IllegalValueException.class, expectedMessage, person::toModelType);
}
Expand All @@ -130,15 +133,15 @@ public void toModelType_nullSalary_throwsIllegalValueException() {
public void toModelType_invalidBudget_throwsIllegalValueException() {
JsonAdaptedPerson person =
new JsonAdaptedPerson(VALID_NAME, VALID_PHONE, VALID_EMAIL, VALID_ADDRESS,
VALID_SALARY, INVALID_BUDGET, VALID_DEPARTMENT, VALID_DOB);
VALID_SALARY, INVALID_BUDGET, VALID_DEPARTMENT, VALID_DOB, VALID_LEAVE);
String expectedMessage = Money.MESSAGE_CONSTRAINTS;
assertThrows(IllegalValueException.class, expectedMessage, person::toModelType);
}

@Test
public void toModelType_nullBudget_throwsIllegalValueException() {
JsonAdaptedPerson person = new JsonAdaptedPerson(VALID_NAME, VALID_PHONE, VALID_EMAIL, VALID_ADDRESS,
VALID_SALARY, null, VALID_DEPARTMENT, VALID_DOB);
VALID_SALARY, null, VALID_DEPARTMENT, VALID_DOB, VALID_LEAVE);
String expectedMessage = String.format(MISSING_FIELD_MESSAGE_FORMAT, Money.class.getSimpleName());
assertThrows(IllegalValueException.class, expectedMessage, person::toModelType);
}
Expand All @@ -147,15 +150,15 @@ public void toModelType_nullBudget_throwsIllegalValueException() {
public void toModelType_invalidDepartment_throwsIllegalValueException() throws Exception {
JsonAdaptedPerson person =
new JsonAdaptedPerson(VALID_NAME, VALID_PHONE, VALID_EMAIL, VALID_ADDRESS,
VALID_SALARY, VALID_BUDGET, INVALID_DEPARTMENT, VALID_DOB);
VALID_SALARY, VALID_BUDGET, INVALID_DEPARTMENT, VALID_DOB, VALID_LEAVE);
String expectedMessage = Department.MESSAGE_CONSTRAINTS;
assertThrows(IllegalValueException.class, expectedMessage, person::toModelType);
}

@Test
public void toModelType_nullDepartment_throwsIllegalValueException() {
JsonAdaptedPerson person = new JsonAdaptedPerson(VALID_NAME, VALID_PHONE, VALID_EMAIL, VALID_ADDRESS,
VALID_SALARY, VALID_BUDGET, null, VALID_DOB);
VALID_SALARY, VALID_BUDGET, null, VALID_DOB, VALID_LEAVE);
String expectedMessage = String.format(MISSING_FIELD_MESSAGE_FORMAT, Department.class.getSimpleName());
assertThrows(IllegalValueException.class, expectedMessage, person::toModelType);
}
Expand All @@ -164,17 +167,34 @@ public void toModelType_nullDepartment_throwsIllegalValueException() {
public void toModelType_invalidDob_throwsIllegalValueException() {
JsonAdaptedPerson person =
new JsonAdaptedPerson(VALID_NAME, VALID_PHONE, VALID_EMAIL, VALID_ADDRESS,
VALID_SALARY, VALID_BUDGET, VALID_DEPARTMENT, INVALID_DOB);
VALID_SALARY, VALID_BUDGET, VALID_DEPARTMENT, INVALID_DOB, VALID_LEAVE);
String expectedMessage = Birthday.MESSAGE_CONSTRAINTS;
assertThrows(IllegalValueException.class, expectedMessage, person::toModelType);
}

@Test
public void toModelType_nullDob_throwsIllegalValueException() {
JsonAdaptedPerson person = new JsonAdaptedPerson(VALID_NAME, VALID_PHONE, VALID_EMAIL, VALID_ADDRESS,
VALID_SALARY, VALID_BUDGET, VALID_DEPARTMENT, null);
VALID_SALARY, VALID_BUDGET, VALID_DEPARTMENT, null, VALID_LEAVE);
String expectedMessage = String.format(MISSING_FIELD_MESSAGE_FORMAT, Birthday.class.getSimpleName());
assertThrows(IllegalValueException.class, expectedMessage, person::toModelType);
}

@Test
public void toModelType_invalidLeave_throwsIllegalValueException() {
JsonAdaptedPerson person =
new JsonAdaptedPerson(VALID_NAME, VALID_PHONE, VALID_EMAIL, VALID_ADDRESS,
VALID_SALARY, VALID_BUDGET, VALID_DEPARTMENT, VALID_DOB, INVALID_LEAVE);
String expectedMessage = Leave.MESSAGE_CONSTRAINTS;
assertThrows(IllegalValueException.class, expectedMessage, person::toModelType);
}

@Test
public void toModelType_nullLeave_throwsIllegalValueException() {
JsonAdaptedPerson person = new JsonAdaptedPerson(VALID_NAME, VALID_PHONE, VALID_EMAIL, VALID_ADDRESS,
VALID_SALARY, VALID_BUDGET, VALID_DEPARTMENT, VALID_DOB, null);
String expectedMessage = String.format(MISSING_FIELD_MESSAGE_FORMAT, Leave.class.getSimpleName());
assertThrows(IllegalValueException.class, expectedMessage, person::toModelType);
}

}
13 changes: 13 additions & 0 deletions src/test/java/seedu/address/testutil/PersonBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import seedu.address.model.person.Birthday;
import seedu.address.model.person.Department;
import seedu.address.model.person.Email;
import seedu.address.model.person.Leave;
import seedu.address.model.person.Money;
import seedu.address.model.person.Name;
import seedu.address.model.person.Person;
Expand All @@ -22,6 +23,7 @@ public class PersonBuilder {
public static final String DEFAULT_BUDGET = "2500";
public static final String DEFAULT_DEPARTMENT = "Engineering";
public static final String DEFAULT_DOB = "2000-01-01";
public static final String DEFAULT_LEAVE = "000000000000";

private Name name;
private Phone phone;
Expand All @@ -31,6 +33,7 @@ public class PersonBuilder {
private Money claimBudget;
private Department department;
private Birthday dob;
private Leave leave;

/**
* Creates a {@code PersonBuilder} with the default details.
Expand All @@ -44,6 +47,7 @@ public PersonBuilder() {
claimBudget = new Money(DEFAULT_BUDGET);
department = new Department(DEFAULT_DEPARTMENT);
dob = new Birthday(DEFAULT_DOB);
leave = new Leave(DEFAULT_LEAVE);
}

/**
Expand All @@ -58,6 +62,7 @@ public PersonBuilder(Person personToCopy) {
claimBudget = personToCopy.getClaimBudget();
department = personToCopy.getDepartment();
dob = personToCopy.getDob();
leave = personToCopy.getLeave();
}

/**
Expand Down Expand Up @@ -131,6 +136,14 @@ public PersonBuilder withDob(String dob) {
return this;
}

/**
* Sets the {@code Leave} of the {@code Person} that we are building.
*/
public PersonBuilder withLeave(String leave) {
this.leave = new Leave(leave);
return this;
}

public Person build() {
return new Person(name, phone, email, address, salary, claimBudget, department, dob);
}
Expand Down
Loading

0 comments on commit 9d8c0b3

Please sign in to comment.