From a47792cf89a217dee810b8f236f3206538b40523 Mon Sep 17 00:00:00 2001 From: bnjm2000 Date: Tue, 14 Nov 2023 02:28:43 +0800 Subject: [PATCH] Fix EventDelete --- .../commands/events/EventDeleteCommand.java | 1 + .../commands/events/EventDeleteCommandTest.java | 16 +++++++++++++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/main/java/seedu/commands/events/EventDeleteCommand.java b/src/main/java/seedu/commands/events/EventDeleteCommand.java index d3bd5e04c4..e1bb5a2f97 100644 --- a/src/main/java/seedu/commands/events/EventDeleteCommand.java +++ b/src/main/java/seedu/commands/events/EventDeleteCommand.java @@ -51,6 +51,7 @@ public CommandResult execute(String statement, GenericList cont throws IllegalArgumentException, IllegalStateException, SysLibException { feedbackToUser = ""; String[] values = parseArgument(statement); + validateStatement(statement, values); int index = parseCalendarInt(values[0], container); System.out.println("This event is removed:"); System.out.println(container.getEventsList().get(index).toString()); diff --git a/src/test/java/seedu/commands/events/EventDeleteCommandTest.java b/src/test/java/seedu/commands/events/EventDeleteCommandTest.java index b195cc9c6e..e2c1f088f7 100644 --- a/src/test/java/seedu/commands/events/EventDeleteCommandTest.java +++ b/src/test/java/seedu/commands/events/EventDeleteCommandTest.java @@ -47,7 +47,21 @@ public void eventDeleteCommandOutOfBounds() throws SysLibException { } @Test - public void eventDeleteCommandEmpty() throws SysLibException{ + public void eventDeleteCommandEmpty(){ assertThrows(SysLibException.class, ()->eventDeleteCommand.execute("/id 0", parser.container)); } + + @Test + public void eventDeleteDuplicateID() throws SysLibException{ + eventAddCommand.execute("/t test1 /date 1 dec 2001 /desc testing 123", parser.container); + eventAddCommand.execute("/t test2 /date 2 dec 2001 /desc testing 456", parser.container); + assertThrows(IllegalArgumentException.class, ()->eventDeleteCommand.execute("/id 0 /id 1", parser.container)); + } + + @Test + public void eventDeleteInvalidArgument() throws SysLibException{ + eventAddCommand.execute("/t test1 /date 1 dec 2001 /desc testing 123", parser.container); + eventAddCommand.execute("/t test2 /date 2 dec 2001 /desc testing 456", parser.container); + assertThrows(IllegalArgumentException.class, ()->eventDeleteCommand.execute("not /id 0", parser.container)); + } }