Skip to content

Commit

Permalink
Testing for Order
Browse files Browse the repository at this point in the history
  • Loading branch information
guanquann committed Mar 12, 2024
1 parent 9b2cc3d commit e5299e8
Show file tree
Hide file tree
Showing 7 changed files with 73 additions and 4 deletions.
18 changes: 14 additions & 4 deletions src/main/java/seedu/address/storage/JsonAdaptedOrder.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,15 @@
import seedu.address.commons.exceptions.IllegalValueException;
import seedu.address.model.order.Date;
import seedu.address.model.order.Order;
import seedu.address.model.person.Name;

/**
* Jackson-friendly version of {@link Order}.
*/
class JsonAdaptedOrder {

public static final String MISSING_FIELD_MESSAGE_FORMAT = "Order's %s field is missing!";

private final String arrivalDate;
private final String description;
private final String status;
Expand Down Expand Up @@ -43,10 +46,17 @@ public JsonAdaptedOrder(Order source) {
* @throws IllegalValueException if there were any data constraints violated in the adapted order.
*/
public Order toModelType() throws IllegalValueException {
// TODO: Add validation of arrivalDate and description
// if (!Order.isValidTagName(tagName)) {
// throw new IllegalValueException(Tag.MESSAGE_CONSTRAINTS);
// }
if (arrivalDate == null) {
throw new IllegalValueException(String.format(MISSING_FIELD_MESSAGE_FORMAT, "Date"));
}

if (description == null) {
throw new IllegalValueException(String.format(MISSING_FIELD_MESSAGE_FORMAT, "Description"));
}

if (status == null) {
throw new IllegalValueException(String.format(MISSING_FIELD_MESSAGE_FORMAT, "Status"));
}

final Date modelDate = new Date(arrivalDate);

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package seedu.address.logic.commands;

public class AddOrderCommandTest {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package seedu.address.logic.parser;

public class AddOrderCommandParserTest {
}
4 changes: 4 additions & 0 deletions src/test/java/seedu/address/model/order/DateTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package seedu.address.model.order;

public class DateTest {
}
4 changes: 4 additions & 0 deletions src/test/java/seedu/address/model/order/OrderTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package seedu.address.model.order;

public class OrderTest {
}
38 changes: 38 additions & 0 deletions src/test/java/seedu/address/storage/JsonAdaptedOrderTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package seedu.address.storage;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;

import org.junit.jupiter.api.Test;

import seedu.address.commons.exceptions.IllegalValueException;
import seedu.address.model.order.Date;
import seedu.address.model.order.Order;

public class JsonAdaptedOrderTest {
private static final Order ORDER = new Order(new Date("2020-01-01"), "100 chicken wings");

private static final String VALID_DATE_STRING = "2020-01-01";
private static final String VALID_DESCRIPTION = "100 chicken wings";
private static final String VALID_STATUS = "Pending";

@Test
public void toModelType_validOrderDetails_returnsOrder() throws IllegalValueException {
JsonAdaptedOrder jsonAdaptedOrder = new JsonAdaptedOrder(VALID_DATE_STRING, VALID_DESCRIPTION, VALID_STATUS);
Order order = jsonAdaptedOrder.toModelType();
assertEquals(ORDER, order);
}

@Test
public void toModelType_nullDate_throwsIllegalValueException() {
JsonAdaptedOrder jsonAdaptedOrder = new JsonAdaptedOrder(null, VALID_DESCRIPTION, VALID_STATUS);
System.out.println("jsonAdaptedOrder" + jsonAdaptedOrder);
assertThrows(IllegalValueException.class, jsonAdaptedOrder::toModelType);
}

@Test
public void toModelType_nullDescription_throwsIllegalValueException() {
JsonAdaptedOrder jsonAdaptedOrder = new JsonAdaptedOrder(VALID_DATE_STRING, null, VALID_STATUS);
assertThrows(IllegalValueException.class, jsonAdaptedOrder::toModelType);
}
}
5 changes: 5 additions & 0 deletions src/test/java/seedu/address/testutil/TypicalOrders.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package seedu.address.testutil;

public class TypicalOrders {

}

0 comments on commit e5299e8

Please sign in to comment.