Skip to content

Commit

Permalink
Add JUnit tests
Browse files Browse the repository at this point in the history
Added JUnit test for
AddListingCommandTest.
  • Loading branch information
wang-h-z committed Nov 6, 2024
1 parent 90fd648 commit 38ece50
Showing 1 changed file with 25 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -340,4 +340,29 @@ public Person getPersonByName(Name name) {
.orElse(null);
}
}

@Test
public void execute_buyerNotInList_throwsCommandException() {
AddListingCommand addListingCommand = new AddListingCommand(PASIR_RIS.getName(), PASIR_RIS.getPrice(),
PASIR_RIS.getArea(), PASIR_RIS.getAddress(), PASIR_RIS.getRegion(), ALICE.getName(),
new HashSet<>(List.of(DANIEL.getName())));
ModelStub modelStub = new ModelStubAcceptingListingAdded();
modelStub.addPerson(ALICE);
assertThrows(CommandException.class,
Messages.MESSAGE_INVALID_PERSON_INPUT, () -> addListingCommand.execute(modelStub));
}

@Test
public void execute_buyerNotOfTypeBuyer_throwsCommandException() {
AddListingCommand addListingCommand = new AddListingCommand(PASIR_RIS.getName(), PASIR_RIS.getPrice(),
PASIR_RIS.getArea(), PASIR_RIS.getAddress(), PASIR_RIS.getRegion(), ALICE.getName(),
new HashSet<>(List.of(BENSON.getName())));
ModelStub modelStub = new ModelStubAcceptingListingAdded();
modelStub.addPerson(ALICE);
modelStub.addPerson(BENSON);

assertThrows(CommandException.class,
AddListingCommand.MESSAGE_NOT_BUYER, () -> addListingCommand.execute(modelStub));
}

}

0 comments on commit 38ece50

Please sign in to comment.