diff --git a/src/test/java/use_case/nav_bar/NavbarInteractorTests.java b/src/test/java/use_case/nav_bar/NavbarInteractorTests.java new file mode 100644 index 0000000..ceb87e5 --- /dev/null +++ b/src/test/java/use_case/nav_bar/NavbarInteractorTests.java @@ -0,0 +1,174 @@ +package use_case.nav_bar; + +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.*; + +/** + * Test class for NavbarInteractor. + * It verifies that the interactor correctly delegates navigation requests + * to the presenter for all available views. + */ +public class NavbarInteractorTests { + /** + * Tests that switchToLogin correctly calls the presenter's switchToLogin method. + */ + @Test + void testSwitchToLogin() { + final NavbarMockPresenter presenter = new NavbarMockPresenter(); + final NavbarInteractor interactor = new NavbarInteractor(presenter); + + interactor.switchToLogin(); + + assertEquals("login", presenter.getLastViewSwitched(), + "Presenter should switch to login view."); + } + + /** + * Tests that switchToSignUp correctly calls the presenter's switchToSignUp method. + */ + @Test + void testSwitchToSignUp() { + final NavbarMockPresenter presenter = new NavbarMockPresenter(); + final NavbarInteractor interactor = new NavbarInteractor(presenter); + + interactor.switchToSignUp(); + + assertEquals("signup", presenter.getLastViewSwitched(), + "Presenter should switch to signup view."); + } + + /** + * Tests that switchToCommunity correctly calls the presenter's switchToCommunity method. + */ + @Test + void testSwitchToCommunity() { + final NavbarMockPresenter presenter = new NavbarMockPresenter(); + final NavbarInteractor interactor = new NavbarInteractor(presenter); + + interactor.switchToCommunity(); + + assertEquals("community", presenter.getLastViewSwitched(), + "Presenter should switch to community view."); + } + + /** + * Tests that switchToGenerateRecipe correctly calls the presenter's switchToGenerateRecipe method. + */ + @Test + void testSwitchToGenerateRecipe() { + final NavbarMockPresenter presenter = new NavbarMockPresenter(); + final NavbarInteractor interactor = new NavbarInteractor(presenter); + + interactor.switchToGenerateRecipe(); + + assertEquals("generateRecipe", presenter.getLastViewSwitched(), + "Presenter should switch to generate recipe view."); + } + + /** + * Tests that switchToApproveRecipe correctly calls the presenter's switchToApproveRecipe method. + */ + @Test + void testSwitchToApproveRecipe() { + final NavbarMockPresenter presenter = new NavbarMockPresenter(); + final NavbarInteractor interactor = new NavbarInteractor(presenter); + + interactor.switchToApproveRecipe(); + + assertEquals("approveRecipe", presenter.getLastViewSwitched(), + "Presenter should switch to approve recipe view."); + } + + /** + * Tests that switchToProfile correctly calls the presenter's switchToProfile method. + */ + @Test + void testSwitchToProfile() { + final NavbarMockPresenter presenter = new NavbarMockPresenter(); + final NavbarInteractor interactor = new NavbarInteractor(presenter); + + interactor.switchToProfile(); + + assertEquals("profile", presenter.getLastViewSwitched(), + "Presenter should switch to profile view."); + } + + /** + * Tests that switchToGroceryList correctly calls the presenter's switchToGroceryList method. + */ + @Test + void testSwitchToGroceryList() { + final NavbarMockPresenter presenter = new NavbarMockPresenter(); + final NavbarInteractor interactor = new NavbarInteractor(presenter); + + interactor.switchToGroceryList(); + + assertEquals("groceryList", presenter.getLastViewSwitched(), + "Presenter should switch to grocery list view."); + } + + /** + * Tests that switchToMealPlan correctly calls the presenter's switchToMealPlan method. + */ + @Test + void testSwitchToMealPlan() { + final NavbarMockPresenter presenter = new NavbarMockPresenter(); + final NavbarInteractor interactor = new NavbarInteractor(presenter); + + interactor.switchToMealPlan(); + + assertEquals("mealPlan", presenter.getLastViewSwitched(), + "Presenter should switch to meal plan view."); + } + + /** + * Tests that switchToSearchByIngredients correctly calls the presenter's switchToSearchByIngredients method. + */ + @Test + void testSwitchToSearchByIngredients() { + final NavbarMockPresenter presenter = new NavbarMockPresenter(); + final NavbarInteractor interactor = new NavbarInteractor(presenter); + + interactor.switchToSearchByIngredients(); + + assertEquals("searchByIngredients", presenter.getLastViewSwitched(), + "Presenter should switch to search by ingredients view."); + } + + /** + * Tests that switchToLikedRecipeList correctly calls the presenter's switchToLikedRecipeList method. + */ + @Test + void testSwitchToLikedRecipeList() { + final NavbarMockPresenter presenter = new NavbarMockPresenter(); + final NavbarInteractor interactor = new NavbarInteractor(presenter); + + interactor.switchToLikedRecipeList(); + + assertEquals("likedRecipeList", presenter.getLastViewSwitched(), + "Presenter should switch to liked recipe list view."); + } + + /** + * Tests that multiple sequential switch calls work correctly. + * Verifies that the presenter tracks the most recent view switch. + */ + @Test + void testMultipleSwitchCallsInSequence() { + final NavbarMockPresenter presenter = new NavbarMockPresenter(); + final NavbarInteractor interactor = new NavbarInteractor(presenter); + + interactor.switchToLogin(); + assertEquals("login", presenter.getLastViewSwitched(), + "First switch should be to login view."); + + interactor.switchToProfile(); + assertEquals("profile", presenter.getLastViewSwitched(), + "Second switch should be to profile view."); + + interactor.switchToCommunity(); + assertEquals("community", presenter.getLastViewSwitched(), + "Third switch should be to community view."); + } +} diff --git a/src/test/java/use_case/nav_bar/NavbarMockPresenter.java b/src/test/java/use_case/nav_bar/NavbarMockPresenter.java new file mode 100644 index 0000000..1006eac --- /dev/null +++ b/src/test/java/use_case/nav_bar/NavbarMockPresenter.java @@ -0,0 +1,70 @@ +package use_case.nav_bar; + +import use_case.nav_bar.NavbarOutputBoundary; + +/** + * Mock implementation of NavbarOutputBoundary for testing purposes. + * Tracks which view was last switched to, allowing tests to verify + * that the interactor correctly delegates to the presenter. + */ +public class NavbarMockPresenter implements NavbarOutputBoundary { + private String lastViewSwitched = null; + + @Override + public void switchToLogin() { + this.lastViewSwitched = "login"; + } + + @Override + public void switchToSignUp() { + this.lastViewSwitched = "signup"; + } + + @Override + public void switchToCommunity() { + this.lastViewSwitched = "community"; + } + + @Override + public void switchToGenerateRecipe() { + this.lastViewSwitched = "generateRecipe"; + } + + @Override + public void switchToApproveRecipe() { + this.lastViewSwitched = "approveRecipe"; + } + + @Override + public void switchToProfile() { + this.lastViewSwitched = "profile"; + } + + @Override + public void switchToGroceryList() { + this.lastViewSwitched = "groceryList"; + } + + @Override + public void switchToMealPlan() { + this.lastViewSwitched = "mealPlan"; + } + + @Override + public void switchToSearchByIngredients() { + this.lastViewSwitched = "searchByIngredients"; + } + + @Override + public void switchToLikedRecipeList() { + this.lastViewSwitched = "likedRecipeList"; + } + + /** + * Gets the last view that was switched to. + * @return the name of the last view switched to, or null if no switch has occurred + */ + public String getLastViewSwitched() { + return lastViewSwitched; + } +}