From 701380b5a908d96c8aa151be566070b2ae0f53a4 Mon Sep 17 00:00:00 2001 From: samuelory Date: Wed, 20 Mar 2024 18:29:53 +0800 Subject: [PATCH] Added more JUnit Tests --- .../java/florizz/command/AddBouquetTest.java | 29 +++++++++++++++++ .../florizz/command/DeleteBouquetTest.java | 31 +++++++++++++++++++ .../{objects => command}/ExitTest.java | 3 +- .../{objects => command}/HelpTest.java | 3 +- 4 files changed, 64 insertions(+), 2 deletions(-) create mode 100644 src/test/java/florizz/command/AddBouquetTest.java create mode 100644 src/test/java/florizz/command/DeleteBouquetTest.java rename src/test/java/florizz/{objects => command}/ExitTest.java (90%) rename src/test/java/florizz/{objects => command}/HelpTest.java (90%) diff --git a/src/test/java/florizz/command/AddBouquetTest.java b/src/test/java/florizz/command/AddBouquetTest.java new file mode 100644 index 0000000000..9315aa93d1 --- /dev/null +++ b/src/test/java/florizz/command/AddBouquetTest.java @@ -0,0 +1,29 @@ +package florizz.command; + +import florizz.core.FlorizzException; +import florizz.core.Ui; +import florizz.objects.Bouquet; +import org.junit.jupiter.api.Test; + +import java.util.ArrayList; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +public class AddBouquetTest { + @Test + void testAddCommandExecute(){ + Bouquet testBouquet = new Bouquet("for testing"); + Ui ui = new Ui(); + ArrayList controlList = new ArrayList<>(); + ArrayList testList = new ArrayList<>(); + controlList.add(testBouquet); + Command testAddBouquetCommand = new AddBouquetCommand(testBouquet); + try { + testAddBouquetCommand.execute(testList, ui); + } + catch(FlorizzException error){ + ui.printError(error); + } + assertEquals(controlList, testList); + } +} diff --git a/src/test/java/florizz/command/DeleteBouquetTest.java b/src/test/java/florizz/command/DeleteBouquetTest.java new file mode 100644 index 0000000000..82329b3946 --- /dev/null +++ b/src/test/java/florizz/command/DeleteBouquetTest.java @@ -0,0 +1,31 @@ +package florizz.command; + +import florizz.core.FlorizzException; +import florizz.core.Ui; +import florizz.objects.Bouquet; +import org.junit.jupiter.api.Test; + +import java.util.ArrayList; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +public class DeleteBouquetTest { + @Test + void testAddCommandExecute(){ + Bouquet testBouquet = new Bouquet("for testing"); + Ui ui = new Ui(); + ArrayList controlList = new ArrayList<>(); + ArrayList testList = new ArrayList<>(); + controlList.add(testBouquet); + testList.add(testBouquet); + Command testDeleteBouquetCommand = new DeleteBouquetCommand(testBouquet); + controlList.remove(testBouquet); + try { + testDeleteBouquetCommand.execute(testList, ui); + } + catch(FlorizzException error){ + ui.printError(error); + } + assertEquals(controlList, testList); + } +} diff --git a/src/test/java/florizz/objects/ExitTest.java b/src/test/java/florizz/command/ExitTest.java similarity index 90% rename from src/test/java/florizz/objects/ExitTest.java rename to src/test/java/florizz/command/ExitTest.java index 43dadebefa..36599ea50d 100644 --- a/src/test/java/florizz/objects/ExitTest.java +++ b/src/test/java/florizz/command/ExitTest.java @@ -1,7 +1,8 @@ -package florizz.objects; +package florizz.command; import florizz.command.ExitCommand; import florizz.core.Ui; +import florizz.objects.Bouquet; import org.junit.jupiter.api.Test; import java.util.ArrayList; diff --git a/src/test/java/florizz/objects/HelpTest.java b/src/test/java/florizz/command/HelpTest.java similarity index 90% rename from src/test/java/florizz/objects/HelpTest.java rename to src/test/java/florizz/command/HelpTest.java index 5b8d092e85..b022489329 100644 --- a/src/test/java/florizz/objects/HelpTest.java +++ b/src/test/java/florizz/command/HelpTest.java @@ -1,7 +1,8 @@ -package florizz.objects; +package florizz.command; import florizz.command.HelpCommand; import florizz.core.Ui; +import florizz.objects.Bouquet; import org.junit.jupiter.api.Test; import java.util.ArrayList;