|
@@ -6,7 +6,9 @@ import static org.hamcrest.collection.IsArrayWithSize.arrayWithSize;
|
|
|
import static org.hamcrest.number.OrderingComparison.greaterThanOrEqualTo;
|
|
import static org.hamcrest.number.OrderingComparison.greaterThanOrEqualTo;
|
|
|
import static org.mockito.Mockito.*;
|
|
import static org.mockito.Mockito.*;
|
|
|
|
|
|
|
|
|
|
+import java.util.ArrayList;
|
|
|
import java.util.Arrays;
|
|
import java.util.Arrays;
|
|
|
|
|
+import java.util.List;
|
|
|
|
|
|
|
|
import org.junit.jupiter.api.BeforeEach;
|
|
import org.junit.jupiter.api.BeforeEach;
|
|
|
import org.junit.jupiter.api.Test;
|
|
import org.junit.jupiter.api.Test;
|
|
@@ -14,34 +16,30 @@ import org.junit.jupiter.api.extension.ExtendWith;
|
|
|
import org.junit.platform.runner.JUnitPlatform;
|
|
import org.junit.platform.runner.JUnitPlatform;
|
|
|
import org.junit.runner.RunWith;
|
|
import org.junit.runner.RunWith;
|
|
|
import org.leumasjaffe.mock.MockObserverListener;
|
|
import org.leumasjaffe.mock.MockObserverListener;
|
|
|
|
|
+import org.leumasjaffe.observer.ObserverDispatch;
|
|
|
import org.leumasjaffe.recipe.model.Amount;
|
|
import org.leumasjaffe.recipe.model.Amount;
|
|
|
import org.leumasjaffe.recipe.model.Duration;
|
|
import org.leumasjaffe.recipe.model.Duration;
|
|
|
import org.leumasjaffe.recipe.model.Ingredient;
|
|
import org.leumasjaffe.recipe.model.Ingredient;
|
|
|
import org.leumasjaffe.recipe.model.Step;
|
|
import org.leumasjaffe.recipe.model.Step;
|
|
|
import org.mockito.Mock;
|
|
import org.mockito.Mock;
|
|
|
-import org.mockito.Spy;
|
|
|
|
|
import org.mockito.junit.jupiter.MockitoExtension;
|
|
import org.mockito.junit.jupiter.MockitoExtension;
|
|
|
|
|
|
|
|
@ExtendWith(MockitoExtension.class)
|
|
@ExtendWith(MockitoExtension.class)
|
|
|
@RunWith(JUnitPlatform.class)
|
|
@RunWith(JUnitPlatform.class)
|
|
|
class StepPanelTest extends SwingTestCase {
|
|
class StepPanelTest extends SwingTestCase {
|
|
|
- @Spy MockObserverListener listener;
|
|
|
|
|
- Duration dur;
|
|
|
|
|
|
|
+ List<Ingredient> ingredients;
|
|
|
@Mock Step stuff;
|
|
@Mock Step stuff;
|
|
|
StepPanel panel;
|
|
StepPanel panel;
|
|
|
|
|
|
|
|
@BeforeEach
|
|
@BeforeEach
|
|
|
void setUp() {
|
|
void setUp() {
|
|
|
- dur = new Duration(Duration.Display.SECONDS, 0, 30);
|
|
|
|
|
|
|
+ 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(dur).when(stuff).getDuration();
|
|
|
doReturn("These are test instructions").when(stuff).getInstruction();
|
|
doReturn("These are test instructions").when(stuff).getInstruction();
|
|
|
- doReturn(Arrays.asList(new Ingredient("Onion", "Sliced", new Amount("100 g"))))
|
|
|
|
|
- .when(stuff).getIngredients();
|
|
|
|
|
|
|
+ doReturn(ingredients).when(stuff).getIngredients();
|
|
|
|
|
|
|
|
panel = new StepPanel(0, stuff);
|
|
panel = new StepPanel(0, stuff);
|
|
|
- listener.setObserved(stuff);
|
|
|
|
|
- // setObserved invokes our callback.
|
|
|
|
|
- clearInvocations(listener);
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
@Test
|
|
@@ -52,4 +50,15 @@ class StepPanelTest extends SwingTestCase {
|
|
|
arrayWithSize(greaterThanOrEqualTo(1)));
|
|
arrayWithSize(greaterThanOrEqualTo(1)));
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ @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();
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|