From 208a7049f687f31b397a2c8031e010efa5ecb842 Mon Sep 17 00:00:00 2001 From: Jeffinson Darmawan Date: Mon, 15 Apr 2024 04:43:51 +0800 Subject: [PATCH] Compare Command Test --- docs/team/jeffinsondarmawan.md | 5 ++- .../florizz/command/CompareCommandTest.java | 42 +++++++++++++++++++ 2 files changed, 45 insertions(+), 2 deletions(-) create mode 100644 src/test/java/florizz/command/CompareCommandTest.java diff --git a/docs/team/jeffinsondarmawan.md b/docs/team/jeffinsondarmawan.md index 8ddebf4289..172e6d7dd4 100644 --- a/docs/team/jeffinsondarmawan.md +++ b/docs/team/jeffinsondarmawan.md @@ -79,8 +79,9 @@ Code Contribution: [Jeffinson Darmawan RepoSense Report](https://nus-cs2113-ay23 3. Improving Parser class by applying FuzzyLogic.detectItem() (Pull Request [#71](https://github.com/AY2324S2-CS2113-T11-3/tp/pull/71)) 4. Wrote JUnit tests for `AddFlowerCommandTest`, `HelpTest`, `InfoCommandTest`, `ListOccasionCommandTest`, - `RemoveFlowerCommandTest`, `FuzzyLogicTest`, `ParserTest`, and wrote additional JUnit tests for `AddBouquetTest`, - `DeleteBouquetTest` which increases classes coverage from 54% to 61% and lines coverage from 29% to 50%. + `RemoveFlowerCommandTest`, `FuzzyLogicTest`, `ParserTest`, `CompareCommandTest` + and wrote additional JUnit tests for `AddBouquetTest`, + `DeleteBouquetTest` which increases classes coverage from 54% to 63% and lines coverage from 29% to 51%. **Documentation** 1. Developer Guide diff --git a/src/test/java/florizz/command/CompareCommandTest.java b/src/test/java/florizz/command/CompareCommandTest.java new file mode 100644 index 0000000000..79129595fb --- /dev/null +++ b/src/test/java/florizz/command/CompareCommandTest.java @@ -0,0 +1,42 @@ +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.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; + +class CompareCommandTest { + + @Test + void testCompareExecute() { // Comparing two different flowers + CompareCommand testCompareCommand = new CompareCommand("Rose", "Lily"); + ArrayList testList = new ArrayList<>(); + Ui ui = new Ui(); + try { + assertTrue(testCompareCommand.execute(testList, ui)); + } catch (FlorizzException error) { + ui.printError(error); + } + } + + @Test + void testCompareException1() { // Comparing the same flower + ArrayList testList = new ArrayList<>(); + Ui ui = new Ui(); + CompareCommand testCompareCommand2 = new CompareCommand("Rose", "Rose"); + assertThrows(FlorizzException.class, () -> testCompareCommand2.execute(testList, ui)); + } + + @Test + void testCompareException2() { // Comparing a flower that does not exist + ArrayList testList = new ArrayList<>(); + Ui ui = new Ui(); + CompareCommand testCompareCommand3 = new CompareCommand("Rose", "Tulip"); + assertThrows(FlorizzException.class, () -> testCompareCommand3.execute(testList, ui)); + } +}