Skip to content

Commit 4b4cc53

Browse files
authored
Merge pull request #50 from gerhean/add-storage-tests
Add storage tests
2 parents a1a4b2b + 8c04d3f commit 4b4cc53

27 files changed

+421
-677
lines changed

src/main/java/seedu/address/logic/commands/EditCommand.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
import static seedu.address.logic.parser.CliSyntax.PREFIX_STATUS;
1212
import static seedu.address.model.Model.PREDICATE_SHOW_ALL_INTERNSHIPS;
1313

14-
import java.util.Date;
14+
import java.time.LocalDate;
1515
import java.util.List;
1616
import java.util.Optional;
1717

@@ -108,7 +108,7 @@ private static InternshipApplication createEditedInternship(InternshipApplicatio
108108
Address updatedAddress = editInternshipDescriptor.getAddress().orElse(internshipToEdit.getAddress());
109109
Phone updatedPhone = editInternshipDescriptor.getPhone().orElse(internshipToEdit.getPhone());
110110
Email updatedEmail = editInternshipDescriptor.getEmail().orElse(internshipToEdit.getEmail());
111-
Date updatedDate = editInternshipDescriptor.getDate().orElse(internshipToEdit.getApplicationDate());
111+
LocalDate updatedDate = editInternshipDescriptor.getDate().orElse(internshipToEdit.getApplicationDate());
112112
Priority updatedPriority = editInternshipDescriptor.getPriority().orElse(internshipToEdit.getPriority());
113113
Status updatedStatus = editInternshipDescriptor.getStatus().orElse(internshipToEdit.getStatus());
114114

@@ -144,7 +144,7 @@ public static class EditInternshipDescriptor {
144144
private Address address;
145145
private Phone phone;
146146
private Email email;
147-
private Date date;
147+
private LocalDate date;
148148
private Priority priority;
149149
private Status status;
150150

@@ -212,11 +212,11 @@ public Optional<Email> getEmail() {
212212
return Optional.ofNullable(email);
213213
}
214214

215-
public void setDate(Date date) {
215+
public void setDate(LocalDate date) {
216216
this.date = date;
217217
}
218218

219-
public Optional<Date> getDate() {
219+
public Optional<LocalDate> getDate() {
220220
return Optional.ofNullable(date);
221221
}
222222

src/main/java/seedu/address/logic/parser/AddCommandParser.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
import static seedu.address.logic.parser.CliSyntax.PREFIX_ROLE;
1111
import static seedu.address.logic.parser.CliSyntax.PREFIX_STATUS;
1212

13-
import java.util.Date;
13+
import java.time.LocalDate;
1414
import java.util.stream.Stream;
1515

1616
import seedu.address.logic.commands.AddCommand;
@@ -50,7 +50,7 @@ public AddCommand parse(String args) throws ParseException {
5050
Address address = ParserUtil.parseAddress(argMultimap.getValue(PREFIX_ADDRESS).get());
5151
Phone phone = ParserUtil.parsePhone(argMultimap.getValue(PREFIX_PHONE).get());
5252
Email email = ParserUtil.parseEmail(argMultimap.getValue(PREFIX_EMAIL).get());
53-
Date date = ParserUtil.parseDate(argMultimap.getValue(PREFIX_DATE).get());
53+
LocalDate date = ParserUtil.parseDate(argMultimap.getValue(PREFIX_DATE).get());
5454
Priority priority = ParserUtil.parsePriority(argMultimap.getValue(PREFIX_PRIORITY).get());
5555
Status status = ParserUtil.parseStatus(argMultimap.getValue(PREFIX_STATUS).get());
5656

src/main/java/seedu/address/logic/parser/ParserUtil.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@
22

33
import static java.util.Objects.requireNonNull;
44

5-
import java.text.SimpleDateFormat;
6-
import java.util.Date;
5+
import java.time.LocalDate;
6+
import java.time.format.DateTimeFormatter;
7+
import java.time.format.DateTimeParseException;
78

89
import seedu.address.commons.core.index.Index;
910
import seedu.address.commons.util.StringUtil;
@@ -117,12 +118,12 @@ public static Role parseRole(String role) throws ParseException {
117118
*
118119
* @throws ParseException if the given {@code date} is invalid.
119120
*/
120-
public static Date parseDate(String date) throws ParseException {
121+
public static LocalDate parseDate(String date) throws ParseException {
121122
requireNonNull(date);
122123
String trimmedDate = date.trim();
123124
try {
124-
return new SimpleDateFormat("dd MM yyyy").parse(trimmedDate);
125-
} catch (java.text.ParseException e) {
125+
return LocalDate.parse(trimmedDate, DateTimeFormatter.ofPattern("dd MM yyyy"));
126+
} catch (DateTimeParseException e) {
126127
throw new ParseException("Date should be in the form: DD MM YYYY");
127128
}
128129
}

src/main/java/seedu/address/model/internship/InternshipApplication.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import static seedu.address.commons.util.CollectionUtil.requireAllNonNull;
44

5-
import java.util.Date;
5+
import java.time.LocalDate;
66
import java.util.Objects;
77

88
import seedu.address.model.status.Status;
@@ -18,15 +18,15 @@ public class InternshipApplication {
1818
private final Address address;
1919
private final Phone phone;
2020
private final Email email;
21-
private final Date applicationDate;
21+
private final LocalDate applicationDate;
2222
private final Priority priority;
2323
private final Status status;
2424

2525
/**
2626
* Every field must be present and not null.
2727
*/
2828
public InternshipApplication(Company company, Role role, Address address, Phone phone, Email email,
29-
Date applicationDate, Priority priority, Status status) {
29+
LocalDate applicationDate, Priority priority, Status status) {
3030
requireAllNonNull(company, phone, email, address, status);
3131
this.company = company;
3232
this.role = role;
@@ -58,7 +58,7 @@ public seedu.address.model.internship.Email getEmail() {
5858
return email;
5959
}
6060

61-
public Date getApplicationDate() {
61+
public LocalDate getApplicationDate() {
6262
return applicationDate;
6363
}
6464

src/main/java/seedu/address/storage/AddressBookStorage.java

Lines changed: 0 additions & 45 deletions
This file was deleted.

src/main/java/seedu/address/storage/JsonAdaptedInternship.java

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
package seedu.address.storage;
22

3-
import java.text.ParseException;
4-
import java.text.SimpleDateFormat;
5-
import java.util.Date;
3+
import java.time.LocalDate;
4+
import java.time.format.DateTimeFormatter;
5+
import java.time.format.DateTimeParseException;
66

77
import com.fasterxml.jackson.annotation.JsonCreator;
88
import com.fasterxml.jackson.annotation.JsonProperty;
@@ -23,7 +23,7 @@
2323
class JsonAdaptedInternship {
2424

2525
public static final String MISSING_FIELD_MESSAGE_FORMAT = "Internship's %s field is missing!";
26-
private static final String DATE_TIME_PATTERN = "dd/MM/yyyy";
26+
public static final String DATE_TIME_PATTERN = "dd/MM/yyyy";
2727
private static final String ERROR_MESSAGE_PLACEHOLDER = "Error message.";
2828

2929
private final String company;
@@ -35,9 +35,6 @@ class JsonAdaptedInternship {
3535
private final String priority;
3636
private final String status;
3737

38-
// Company company, Role role, Address address, Phone phone, Email email,
39-
// Date applicationDate, Priority priority, Status status
40-
4138
/**
4239
* Constructs a {@code JsonAdaptedInternship} with the given person details.
4340
*/
@@ -65,7 +62,7 @@ public JsonAdaptedInternship(InternshipApplication source) {
6562
address = source.getAddress().value;
6663
phone = source.getPhone().value;
6764
email = source.getEmail().value;
68-
applicationDate = (new SimpleDateFormat(DATE_TIME_PATTERN)).format(source.getApplicationDate());
65+
applicationDate = source.getApplicationDate().format(DateTimeFormatter.ofPattern(DATE_TIME_PATTERN));
6966
priority = Integer.toString(source.getPriority().fullPriority);
7067
status = source.getStatus().name();
7168
}
@@ -116,18 +113,20 @@ public InternshipApplication toModelType() throws IllegalValueException {
116113
}
117114
final Address modelAddress = new Address(address);
118115

119-
Date modelDate = null;
116+
LocalDate modelDate = null;
120117
if (applicationDate == null) {
121-
throw new IllegalValueException(String.format(MISSING_FIELD_MESSAGE_FORMAT, Date.class.getSimpleName()));
118+
throw new IllegalValueException(String.format(MISSING_FIELD_MESSAGE_FORMAT,
119+
LocalDate.class.getSimpleName()));
122120
}
123-
SimpleDateFormat dateFormat = new SimpleDateFormat(DATE_TIME_PATTERN);
121+
DateTimeFormatter dateFormat = DateTimeFormatter.ofPattern(DATE_TIME_PATTERN);
124122
try {
125-
modelDate = dateFormat.parse(applicationDate);
126-
} catch (ParseException e) {
123+
modelDate = LocalDate.parse(applicationDate, dateFormat);
124+
} catch (DateTimeParseException e) {
127125
throw new IllegalValueException(ERROR_MESSAGE_PLACEHOLDER);
128126
}
129127
if (modelDate == null) {
130-
throw new IllegalValueException(String.format(MISSING_FIELD_MESSAGE_FORMAT, Date.class.getSimpleName()));
128+
throw new IllegalValueException(String.format(MISSING_FIELD_MESSAGE_FORMAT,
129+
LocalDate.class.getSimpleName()));
131130
}
132131

133132
if (priority == null) {
@@ -149,7 +148,7 @@ public InternshipApplication toModelType() throws IllegalValueException {
149148
try {
150149
Status.valueOf(status);
151150
} catch (IllegalArgumentException e) {
152-
throw new IllegalValueException(ERROR_MESSAGE_PLACEHOLDER);
151+
throw new IllegalValueException(Status.MESSAGE_CONSTRAINTS);
153152
}
154153
final Status modelStatus = Status.valueOf(status);
155154

src/main/java/seedu/address/storage/JsonAdaptedPerson.java

Lines changed: 0 additions & 109 deletions
This file was deleted.

0 commit comments

Comments
 (0)