|
|
@@ -0,0 +1,92 @@
|
|
|
+package org.leumasjaffe.recipe.view;
|
|
|
+
|
|
|
+import static org.mockito.Mockito.*;
|
|
|
+
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.Arrays;
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
+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.Duration;
|
|
|
+import org.leumasjaffe.recipe.model.Ingredient;
|
|
|
+import org.leumasjaffe.recipe.model.Step;
|
|
|
+import org.mockito.Spy;
|
|
|
+import org.mockito.junit.jupiter.MockitoExtension;
|
|
|
+
|
|
|
+@ExtendWith(MockitoExtension.class)
|
|
|
+@RunWith(JUnitPlatform.class)
|
|
|
+class StepPanelIT extends SwingTestCase {
|
|
|
+ @Spy MockObserverListener listener;
|
|
|
+ List<Ingredient> ingredients;
|
|
|
+ @Spy Step stuff;
|
|
|
+ StepPanel panel;
|
|
|
+
|
|
|
+ @BeforeEach
|
|
|
+ void setUp() {
|
|
|
+ Duration dur = new Duration(Duration.Display.SECONDS, 0, 30);
|
|
|
+ ingredients = new ArrayList<>(Arrays.asList(new Ingredient("Onion", "Sliced", new Amount("100 g"))));
|
|
|
+ doReturn(dur).when(stuff).getDuration();
|
|
|
+ doReturn("These are test instructions").when(stuff).getInstruction();
|
|
|
+ doReturn(ingredients).when(stuff).getIngredients();
|
|
|
+
|
|
|
+ panel = new StepPanel(0, stuff);
|
|
|
+ listener.setObserved(stuff);
|
|
|
+ // setObserved invokes our callback.
|
|
|
+ clearInvocations(listener);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test
|
|
|
+ void testRecievesSignalWhenNewElementAdded() {
|
|
|
+ final IngredientPanel newIngredient =
|
|
|
+ (IngredientPanel) panel.getPanelIngredients().getComponent(1);
|
|
|
+
|
|
|
+ newIngredient.getTxtName().setText("Bacon");
|
|
|
+ waitForSwing();
|
|
|
+
|
|
|
+ verify(listener, times(1)).updateWasSignalled();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test
|
|
|
+ void testNewItemCanProduceUpdate() {
|
|
|
+ final IngredientPanel newIngredient =
|
|
|
+ (IngredientPanel) panel.getPanelIngredients().getComponent(1);
|
|
|
+ newIngredient.getTxtName().setText("Bacon");
|
|
|
+ waitForSwing();
|
|
|
+
|
|
|
+ ObserverDispatch.notifySubscribers(ingredients.get(1));
|
|
|
+
|
|
|
+ verify(listener, times(2)).updateWasSignalled();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test
|
|
|
+ void testReceivesSignalWhenElementRemoved() {
|
|
|
+ final IngredientPanel oldIngredient =
|
|
|
+ (IngredientPanel) panel.getPanelIngredients().getComponent(0);
|
|
|
+ oldIngredient.getTxtName().setText("");
|
|
|
+ waitForSwing();
|
|
|
+
|
|
|
+ verify(listener, times(1)).updateWasSignalled();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test
|
|
|
+ void testIgnoresOldItemUpdates() {
|
|
|
+ final Ingredient ing = ingredients.get(0);
|
|
|
+ final IngredientPanel oldIngredient =
|
|
|
+ (IngredientPanel) panel.getPanelIngredients().getComponent(0);
|
|
|
+ oldIngredient.getTxtName().setText("");
|
|
|
+
|
|
|
+ waitForSwing();
|
|
|
+ clearInvocations(listener);
|
|
|
+
|
|
|
+ ObserverDispatch.notifySubscribers(ing);
|
|
|
+ verify(listener, never()).updateWasSignalled();
|
|
|
+ }
|
|
|
+
|
|
|
+}
|