package org.leumasjaffe.recipe.view; import static org.junit.jupiter.api.Assertions.*; import static org.mockito.Mockito.*; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.junit.platform.runner.JUnitPlatform; import org.junit.runner.RunWith; import org.leumasjaffe.mock.MockObserverListener; import org.leumasjaffe.observer.ObserverDispatch; import org.leumasjaffe.recipe.model.Amount; import org.leumasjaffe.recipe.model.Ingredient; import org.mockito.Spy; import org.mockito.junit.jupiter.MockitoExtension; @ExtendWith(MockitoExtension.class) @RunWith(JUnitPlatform.class) class IngredientPanelTest extends SwingTestCase { @Spy MockObserverListener listener; Ingredient stuff; IngredientPanel panel; @BeforeEach void setUp() { stuff = new Ingredient("Onions", "Sliced", new Amount("100 g")); panel = new IngredientPanel(stuff); listener.setObserved(stuff); // setObserved invokes our callback. clearInvocations(listener); } @Test void testFilledOutWithContent() { assertEquals("Onions", panel.getTxtName().getText()); assertEquals("Sliced", panel.getTxtPreparation().getText()); assertEquals("100", panel.getTxtAmount().getText()); assertEquals("g", panel.getTxtUnit().getText()); } @Test void testContentIsEditable() { assertTrue(panel.getTxtName().isEditable()); assertTrue(panel.getTxtPreparation().isEditable()); assertTrue(panel.getTxtAmount().isEditable()); assertTrue(panel.getTxtUnit().isEditable()); } @Test void testIsSubscribedToUpdates() { stuff.setName("Bacon"); assertEquals("Onions", panel.getTxtName().getText()); ObserverDispatch.notifySubscribers(stuff); assertEquals("Bacon", panel.getTxtName().getText()); // TODO: I need to add hook-ups for the rest of the fields, too } // TODO: I need to add hook-ups for the rest of the fields, too @Test void testViewUpdateAltersModel() { panel.getTxtName().setText("Bacon"); waitForSwing(); assertEquals("Bacon", stuff.getName()); } // TODO: I need to add hook-ups for the rest of the fields, too @Test void testViewUpdateSendsNotify() { panel.getTxtName().setText("Bacon"); waitForSwing(); verify(listener).updateWasSignalled(); } }