| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485 |
- package org.leumasjaffe.recipe.view;
- import static org.junit.jupiter.api.Assertions.*;
- import static org.mockito.Mockito.*;
- import java.util.ArrayList;
- import java.util.Arrays;
- import java.util.List;
- import javax.swing.JLabel;
- import org.junit.jupiter.api.BeforeEach;
- import org.junit.jupiter.api.Test;
- import org.junit.jupiter.api.extension.ExtendWith;
- import org.leumasjaffe.mock.MockObserverListener;
- import org.leumasjaffe.observer.ObserverDispatch;
- import org.leumasjaffe.recipe.model.Amount;
- import org.leumasjaffe.recipe.model.Duration;
- import org.leumasjaffe.recipe.model.Ingredient;
- import org.leumasjaffe.recipe.model.Step;
- import org.mockito.InjectMocks;
- import org.mockito.Spy;
- import org.mockito.junit.jupiter.MockitoExtension;
- @ExtendWith(MockitoExtension.class)
- class StepPanelTest extends SwingTestCase {
- List<Ingredient> ingredients;
- Step stuff;
-
- @Spy JLabel lblIndex;
- @Spy AutoGrowPanel<IngredientPanel, Ingredient> panelIngredients =
- new AutoGrowPanel<>(Ingredient::new, IngredientPanel::new);
- @InjectMocks StepPanel panel = new StepPanel();
- @BeforeEach
- void setUp() {
- ingredients = new ArrayList<>(Arrays.asList(new Ingredient("Onion", "Sliced", new Amount("100 g"))));
- stuff = new Step();
- stuff.setDuration(new Duration("30 s"));
- stuff.setIngredients(ingredients);
- stuff.setInstruction("These are test instructions");
-
- panel.setModel(stuff);
- }
- @Test
- void testFilledOutWithContent() {
- assertEquals("These are test instructions", panel.getTxtpnInstructions().getText());
- verify(panelIngredients).setModel(same(ingredients), any());
- }
-
- @Test
- void testSetListPositionUpdatesIndex() {
- panel.setListPosition(1);
- verify(lblIndex).setText("Step 2");
- }
-
- @Test
- void testUpdatesContentOnNotification() {
- stuff.setInstruction("New instructions");
- ObserverDispatch.notifySubscribers(stuff);
-
- assertEquals("New instructions", panel.getTxtpnInstructions().getText());
- }
-
- @Test
- void testViewUpdatesAltersModel() {
- panel.getTxtpnInstructions().setText("New instructions");
- waitForSwing();
-
- assertEquals("New instructions", stuff.getInstruction());
- }
- @Test
- void testPropogatesNotifications() {
- final MockObserverListener listener = spy(MockObserverListener.class);
- listener.setObserved(stuff);
- // setObserved invokes our callback.
- clearInvocations(listener);
-
- ObserverDispatch.notifySubscribers(ingredients.get(0));
-
- verify(listener, atLeast(1)).updateWasSignalled();
- }
- }
|