From 9093a0b5fa5a8299ae3dbf27b0b66c802ef1115e Mon Sep 17 00:00:00 2001 From: Tan Wen Xuan <> Date: Thu, 7 Nov 2024 17:13:53 +0800 Subject: [PATCH] Place the final touches to the code coverage --- .../java/seedu/address/logic/Messages.java | 4 ++- .../EditListingCommandTest.java | 29 +++++++++++++++++++ .../address/model/appointment/DateTest.java | 5 ++++ .../address/model/appointment/FromTest.java | 6 ++++ .../address/model/appointment/ToTest.java | 6 ++++ .../seedu/address/ui/CommandBoxUiTest.java | 1 - .../seedu/address/ui/MainWindowUiTest.java | 11 +++++++ 7 files changed, 60 insertions(+), 2 deletions(-) diff --git a/src/main/java/seedu/address/logic/Messages.java b/src/main/java/seedu/address/logic/Messages.java index b084831f748..785f1bfe544 100644 --- a/src/main/java/seedu/address/logic/Messages.java +++ b/src/main/java/seedu/address/logic/Messages.java @@ -77,7 +77,9 @@ public static String format(Listing listing) { .append("; Seller: ") .append(listing.getSeller()); listing.getBuyers().forEach(builder::append); - return builder.toString(); + return String.format("%1s.\nAddress: %2s", + listing.getName(), listing.getAddress()); + //return builder.toString(); } } diff --git a/src/test/java/seedu/address/logic/commands/listingcommands/EditListingCommandTest.java b/src/test/java/seedu/address/logic/commands/listingcommands/EditListingCommandTest.java index 4080ca58c9c..bac5774c0a6 100644 --- a/src/test/java/seedu/address/logic/commands/listingcommands/EditListingCommandTest.java +++ b/src/test/java/seedu/address/logic/commands/listingcommands/EditListingCommandTest.java @@ -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.assertThrows; import static org.junit.jupiter.api.Assertions.assertTrue; import static seedu.address.logic.commands.CommandTestUtil.assertCommandFailure; import static seedu.address.logic.commands.CommandTestUtil.assertCommandSuccess; @@ -18,15 +19,18 @@ import seedu.address.logic.Messages; import seedu.address.logic.commands.ClearCommand; +import seedu.address.logic.commands.exceptions.CommandException; import seedu.address.logic.commands.listingcommands.EditListingCommand.EditListingDescriptor; import seedu.address.model.Listings; import seedu.address.model.Model; import seedu.address.model.ModelManager; import seedu.address.model.UserPrefs; import seedu.address.model.listing.Listing; +import seedu.address.model.person.Name; import seedu.address.model.person.Person; import seedu.address.testutil.EditListingDescriptorBuilder; import seedu.address.testutil.ListingBuilder; +import seedu.address.testutil.PersonBuilder; public class EditListingCommandTest { private Model model = new ModelManager(getTypicalAddressBook(), new UserPrefs(), getTypicalListings()); @@ -177,4 +181,29 @@ public void toStringMethod() { + ", editListingDescriptor=" + editListingDescriptor + "}"; assertEquals(expected, editListingCommand.toString()); } + @Test + public void execute_nonSellerSpecified_throwsCommandException() { + Model model = new ModelManager(); + Person nonSellerPerson = new PersonBuilder().withName("NonSeller").buildSeller(); + model.addPerson(nonSellerPerson); + + EditListingCommand.EditListingDescriptor descriptor = new EditListingDescriptorBuilder() + .withName("NonSeller").build(); + EditListingCommand command = new EditListingCommand(new Name("SampleListing"), descriptor); + + assertThrows(CommandException.class, () -> command.execute(model), + "The specified person is not a seller."); + } + + @Test + public void execute_sellerNotFound_throwsCommandException() { + Model model = new ModelManager(); + + EditListingCommand.EditListingDescriptor descriptor = new EditListingDescriptorBuilder() + .withName("MissingSeller").build(); + EditListingCommand command = new EditListingCommand(new Name("SampleListing"), descriptor); + + assertThrows(CommandException.class, () -> command.execute(model), + "Seller not found in the system."); + } } diff --git a/src/test/java/seedu/address/model/appointment/DateTest.java b/src/test/java/seedu/address/model/appointment/DateTest.java index 160f274966b..760e63b0b8a 100644 --- a/src/test/java/seedu/address/model/appointment/DateTest.java +++ b/src/test/java/seedu/address/model/appointment/DateTest.java @@ -40,5 +40,10 @@ public void equals() { otherDate = new Date("131224"); assertFalse(date.equals(otherDate)); } + @Test + public void parseDate_invalidFormat_throwsIllegalArgumentException() { + String invalidDate = "32-12-24"; + assertThrows(IllegalArgumentException.class, () -> new Date(invalidDate)); + } } diff --git a/src/test/java/seedu/address/model/appointment/FromTest.java b/src/test/java/seedu/address/model/appointment/FromTest.java index e0adba2221b..afb2da42379 100644 --- a/src/test/java/seedu/address/model/appointment/FromTest.java +++ b/src/test/java/seedu/address/model/appointment/FromTest.java @@ -39,4 +39,10 @@ public void equals() { otherDate = new From("0900"); assertFalse(from.equals(otherDate)); } + @Test + public void parseTime_invalidFormat_throwsIllegalArgumentException() { + String invalidTime = "25:00"; + + assertThrows(IllegalArgumentException.class, () -> new From(invalidTime)); + } } diff --git a/src/test/java/seedu/address/model/appointment/ToTest.java b/src/test/java/seedu/address/model/appointment/ToTest.java index 08eaae983ab..3ec9639c653 100644 --- a/src/test/java/seedu/address/model/appointment/ToTest.java +++ b/src/test/java/seedu/address/model/appointment/ToTest.java @@ -38,4 +38,10 @@ public void equals() { otherDate = new To("0900"); assertFalse(to.equals(otherDate)); } + @Test + public void parseTime_invalidFormat_throwsIllegalArgumentException() { + String invalidTime = "10:64"; + + assertThrows(IllegalArgumentException.class, () -> new To(invalidTime)); + } } diff --git a/src/test/java/seedu/address/ui/CommandBoxUiTest.java b/src/test/java/seedu/address/ui/CommandBoxUiTest.java index c6fc631c7e9..d2273ff767a 100644 --- a/src/test/java/seedu/address/ui/CommandBoxUiTest.java +++ b/src/test/java/seedu/address/ui/CommandBoxUiTest.java @@ -43,7 +43,6 @@ public void setUp() throws Exception { FxToolkit.showStage(); WaitForAsyncUtils.waitForFxEvents(20); } - @AfterEach public void tearDown() throws TimeoutException { FxToolkit.cleanupStages(); diff --git a/src/test/java/seedu/address/ui/MainWindowUiTest.java b/src/test/java/seedu/address/ui/MainWindowUiTest.java index 7f294a60122..551e5183d3d 100644 --- a/src/test/java/seedu/address/ui/MainWindowUiTest.java +++ b/src/test/java/seedu/address/ui/MainWindowUiTest.java @@ -9,6 +9,7 @@ import org.testfx.framework.junit5.ApplicationTest; import org.testfx.util.WaitForAsyncUtils; +import javafx.scene.control.TextArea; import javafx.scene.input.KeyCode; import seedu.address.MainApp; @@ -31,4 +32,14 @@ void handleHelp_handlesHelpCommandCorrectly() { robot.type(KeyCode.ENTER); assertTrue(robot.lookup("#helpMessage").query().isVisible()); } + @Test + void handleHelp_handlesListingsCommandCorrectly() { + FxRobot robot = new FxRobot(); + robot.clickOn("#commandTextField"); + robot.write("showlistings"); + robot.type(KeyCode.ENTER); + TextArea resultDisplay = robot.lookup("#resultDisplay").query(); + assertTrue(resultDisplay.getText().contains("Here are your listings!") + || resultDisplay.getText().contains("You have no listings available.")); + } }