Skip to content

Commit

Permalink
More user testing =
Browse files Browse the repository at this point in the history
  • Loading branch information
guanquann committed Mar 13, 2024
1 parent 1505831 commit 3239db7
Show file tree
Hide file tree
Showing 7 changed files with 111 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package seedu.address.logic.commands;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static seedu.address.logic.commands.CommandTestUtil.assertCommandSuccess;
import static seedu.address.testutil.Assert.assertThrows;
import static seedu.address.testutil.TypicalIndexes.INDEX_FIRST_PERSON;
Expand Down Expand Up @@ -84,4 +85,12 @@ public void equals() {
assert (!addOrderCommand.equals(differentOrderCommand));
}

@Test
public void toStringMethod() {
AddOrderCommand addOrderCommand = new AddOrderCommand(INDEX_FIRST_PERSON, DATE_STUB, DESCRIPTION_STUB);
String expected = AddOrderCommand.class.getCanonicalName() + "{index=" + INDEX_FIRST_PERSON
+ ", arrivalDate=" + DATE_STUB + ", description=" + DESCRIPTION_STUB + "}";
assertEquals(expected, addOrderCommand.toString());
}

}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package seedu.address.logic.parser;

import static seedu.address.logic.Messages.MESSAGE_INVALID_COMMAND_FORMAT;
import static seedu.address.logic.commands.CommandTestUtil.NAME_DESC_AMY;
import static seedu.address.logic.parser.CliSyntax.PREFIX_DATE;
import static seedu.address.logic.parser.CliSyntax.PREFIX_DESCRIPTION;
import static seedu.address.logic.parser.CommandParserTestUtil.assertParseFailure;
Expand All @@ -15,6 +16,8 @@
public class AddOrderCommandParserTest {
private static final String NON_EMPTY_DATE = "2020-01-01";
private static final String NON_EMPTY_DESCRIPTION = "100 chicken wings";
private static final String MESSAGE_INVALID_FORMAT =
String.format(MESSAGE_INVALID_COMMAND_FORMAT, AddOrderCommand.MESSAGE_USAGE);

private AddOrderCommandParser parser = new AddOrderCommandParser();

Expand All @@ -29,14 +32,39 @@ public void parse_indexSpecified_success() {
}

@Test
public void parse_missingDateField_failure() {
String expectedMessage = String.format(MESSAGE_INVALID_COMMAND_FORMAT, AddOrderCommand.MESSAGE_USAGE);
public void parse_missingParts_failure() {
// no index specified
String userInput = PREFIX_DATE + NON_EMPTY_DATE + " " + PREFIX_DESCRIPTION + NON_EMPTY_DESCRIPTION;
assertParseFailure(parser, userInput, MESSAGE_INVALID_FORMAT);

// no field specified
assertParseFailure(parser, "1", MESSAGE_INVALID_FORMAT);

// no index and no field specified
assertParseFailure(parser, "", MESSAGE_INVALID_FORMAT);
}

@Test
public void parse_invalidPreamble_failure() {
// negative index
assertParseFailure(parser, "-5" + NAME_DESC_AMY, MESSAGE_INVALID_FORMAT);

// zero index
assertParseFailure(parser, "0" + NAME_DESC_AMY, MESSAGE_INVALID_FORMAT);

// invalid arguments being parsed as preamble
assertParseFailure(parser, "1 some random string", MESSAGE_INVALID_FORMAT);

// invalid prefix being parsed as preamble
assertParseFailure(parser, "1 i/ string", MESSAGE_INVALID_FORMAT);
}
@Test
public void parse_missingDateField_failure() {
// no parameters
assertParseFailure(parser, AddOrderCommand.COMMAND_WORD, expectedMessage);
assertParseFailure(parser, AddOrderCommand.COMMAND_WORD, MESSAGE_INVALID_FORMAT);

// no index
assertParseFailure(parser, AddOrderCommand.COMMAND_WORD + " " + PREFIX_DATE + NON_EMPTY_DATE,
expectedMessage);
MESSAGE_INVALID_FORMAT);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import org.junit.jupiter.api.Test;

import seedu.address.logic.commands.AddCommand;
import seedu.address.logic.commands.AddOrderCommand;
import seedu.address.logic.commands.ClearCommand;
import seedu.address.logic.commands.DeleteCommand;
import seedu.address.logic.commands.EditCommand;
Expand All @@ -23,6 +24,7 @@
import seedu.address.logic.commands.HelpCommand;
import seedu.address.logic.commands.ListCommand;
import seedu.address.logic.parser.exceptions.ParseException;
import seedu.address.model.order.Date;
import seedu.address.model.person.NameContainsKeywordsPredicate;
import seedu.address.model.person.Person;
import seedu.address.testutil.EditPersonDescriptorBuilder;
Expand Down Expand Up @@ -62,6 +64,13 @@ public void parseCommand_edit() throws Exception {
assertEquals(new EditCommand(INDEX_FIRST_PERSON, descriptor), command);
}

@Test
public void parseCommand_addOrder() throws Exception {
AddOrderCommand command = (AddOrderCommand) parser.parseCommand(AddOrderCommand.COMMAND_WORD + " "
+ INDEX_FIRST_PERSON.getOneBased() + " d/2020-01-01 r/100 chicken wings");
assertEquals(new AddOrderCommand(INDEX_FIRST_PERSON, new Date("2020-01-01"), "100 chicken wings"), command);
}

@Test
public void parseCommand_exit() throws Exception {
assertTrue(parser.parseCommand(ExitCommand.COMMAND_WORD) instanceof ExitCommand);
Expand Down
13 changes: 13 additions & 0 deletions src/test/java/seedu/address/model/order/DateTest.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package seedu.address.model.order;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;

Expand Down Expand Up @@ -40,4 +42,15 @@ public void equals() {
Date differentDate = new Date("2020-01-02");
assertFalse(date.equals(differentDate));
}

@Test
public void hashcode() {
Date date = new Date("2020-01-01");

// same date -> returns same hashcode
assertEquals(date.hashCode(), new Date("2020-01-01").hashCode());

// different date -> returns different hashcode
assertNotEquals(date.hashCode(), new Date("2020-05-01").hashCode());
}
}
31 changes: 30 additions & 1 deletion src/test/java/seedu/address/model/order/OrderTest.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package seedu.address.model.order;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static seedu.address.testutil.Assert.assertThrows;

Expand All @@ -22,6 +24,19 @@ public void constructor_invalidDate_throwsIllegalArgumentException() {
assertThrows(IllegalArgumentException.class, () -> new Order(new Date(INVALID_DATE), VALID_DESCRIPTION));
}

@Test
public void constructor_order_success() {
Order order = new Order(new Date(VALID_DATE), VALID_DESCRIPTION);
assertEquals(VALID_DATE, order.getDate().toString());
assertEquals(VALID_DESCRIPTION, order.getDescription());
assertEquals("Pending", order.getStatus());

Order orderWithStatus = new Order(new Date(VALID_DATE), VALID_DESCRIPTION, "Delivered");
assertEquals(VALID_DATE, orderWithStatus.getDate().toString());
assertEquals(VALID_DESCRIPTION, orderWithStatus.getDescription());
assertEquals("Delivered", orderWithStatus.getStatus());
}

@Test
public void equals() {
Order order = new Order(new Date(VALID_DATE), VALID_DESCRIPTION);
Expand All @@ -30,7 +45,7 @@ public void equals() {
assertTrue(order.equals(order));

// same values -> returns true
Order orderCopy = new Order(order.getDate(), order.getDescription());
Order orderCopy = new Order(order.getDate(), order.getDescription(), order.getStatus());
assertTrue(order.equals(orderCopy));

// different types -> returns false
Expand All @@ -43,4 +58,18 @@ public void equals() {
Order differentOrder = new Order(order.getDate(), "200 chicken wings");
assertFalse(order.equals(differentOrder));
}

@Test
public void hashcode() {
Order order = new Order(new Date(VALID_DATE), VALID_DESCRIPTION);

// same order -> returns same hashcode
assertEquals(order.hashCode(), new Order(new Date(VALID_DATE), VALID_DESCRIPTION).hashCode());

// different date -> returns different hashcode
assertNotEquals(order.hashCode(), new Order(new Date("2022-01-01"), VALID_DESCRIPTION).hashCode());

// different description -> returns different hashcode
assertNotEquals(order.hashCode(), new Order(new Date(VALID_DATE), "20 chicken wings").hashCode());
}
}
12 changes: 12 additions & 0 deletions src/test/java/seedu/address/model/person/PersonTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static seedu.address.logic.commands.CommandTestUtil.VALID_ADDRESS_BOB;
import static seedu.address.logic.commands.CommandTestUtil.VALID_EMAIL_BOB;
Expand Down Expand Up @@ -97,4 +98,15 @@ public void toStringMethod() {
+ ", orders=" + ALICE.getOrderList() + "}";
assertEquals(expected, ALICE.toString());
}

@Test
public void hashcode() {
Person person = new PersonBuilder(ALICE).build();

// same person -> returns same hashcode
assertEquals(person.hashCode(), new PersonBuilder(ALICE).build().hashCode());

// different person -> returns different hashcode
assertNotEquals(person.hashCode(), new PersonBuilder(BOB).build().hashCode());
}
}
6 changes: 6 additions & 0 deletions src/test/java/seedu/address/storage/JsonAdaptedOrderTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,10 @@ public void toModelType_nullDescription_throwsIllegalValueException() {
JsonAdaptedOrder jsonAdaptedOrder = new JsonAdaptedOrder(VALID_DATE_STRING, null, VALID_STATUS);
assertThrows(IllegalValueException.class, jsonAdaptedOrder::toModelType);
}

@Test
public void toModelType_nullStatus_throwsIllegalValueException() {
JsonAdaptedOrder jsonAdaptedOrder = new JsonAdaptedOrder(VALID_DATE_STRING, VALID_DESCRIPTION, null);
assertThrows(IllegalValueException.class, jsonAdaptedOrder::toModelType);
}
}

0 comments on commit 3239db7

Please sign in to comment.