From 2166447f4d3a2c59c2ba48ee8945b98a4a0a0a80 Mon Sep 17 00:00:00 2001 From: Wu Zengfu Date: Mon, 11 Nov 2024 19:22:58 +0800 Subject: [PATCH] Add test cases for PaginationPanel --- .../seedu/address/ui/PaginationPanelTest.java | 44 +++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 src/test/java/seedu/address/ui/PaginationPanelTest.java diff --git a/src/test/java/seedu/address/ui/PaginationPanelTest.java b/src/test/java/seedu/address/ui/PaginationPanelTest.java new file mode 100644 index 00000000000..2b8887457fe --- /dev/null +++ b/src/test/java/seedu/address/ui/PaginationPanelTest.java @@ -0,0 +1,44 @@ +package seedu.address.ui; + +import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static seedu.address.testutil.Assert.assertThrows; + +import java.util.ArrayList; + +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; + +import javafx.collections.FXCollections; +import javafx.collections.ObservableList; +import javafx.embed.swing.JFXPanel; +import seedu.address.model.contact.Contact; + +public class PaginationPanelTest { + @BeforeAll + public static void initJavaFxPlatform() { + new JFXPanel(); + } + + @Test + public void constructor_null_throwsNullPointerException() { + assertThrows(NullPointerException.class, () -> new PaginationPanel(null)); + } + + @Test + public void constructor_validObservationList_success() { + ObservableList observableList = FXCollections.observableList(new ArrayList<>()); + assertDoesNotThrow(() -> new PaginationPanel(observableList)); + } + + @Test + public void convertItemIndexToDisplayIndex_invalidIndex_throwsAssertionError() { + assertThrows(AssertionError.class, () -> PaginationPanel.convertItemIndexToDisplayIndex(-1)); + } + + @Test + public void convertItemIndexToDisplayIndex_validIndex_success() { + assertEquals(1, PaginationPanel.convertItemIndexToDisplayIndex(0)); + assertEquals(10, PaginationPanel.convertItemIndexToDisplayIndex(9)); + } +}