|
|
@@ -1,58 +1,57 @@
|
|
|
package org.leumasjaffe.recipe.view;
|
|
|
|
|
|
-import static org.hamcrest.MatcherAssert.assertThat;
|
|
|
-import static org.hamcrest.collection.IsArrayWithSize.arrayWithSize;
|
|
|
import static org.mockito.Mockito.*;
|
|
|
|
|
|
-import java.util.Arrays;
|
|
|
-
|
|
|
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.observer.ObserverDispatch;
|
|
|
-import org.leumasjaffe.recipe.model.Amount;
|
|
|
+import org.leumasjaffe.recipe.controller.ReplaceChildrenController;
|
|
|
import org.leumasjaffe.recipe.model.Duration;
|
|
|
import org.leumasjaffe.recipe.model.Ingredient;
|
|
|
import org.leumasjaffe.recipe.model.Preparation;
|
|
|
-import org.mockito.Spy;
|
|
|
+import org.mockito.InjectMocks;
|
|
|
+import org.mockito.Mock;
|
|
|
import org.mockito.junit.jupiter.MockitoExtension;
|
|
|
|
|
|
@ExtendWith(MockitoExtension.class)
|
|
|
-@RunWith(JUnitPlatform.class)
|
|
|
class PreparationPanelTest extends SwingTestCase {
|
|
|
|
|
|
- @Spy Preparation stuff;
|
|
|
- PreparationPanel panel;
|
|
|
+ @Mock DurationPanel panelDuration;
|
|
|
+ @Mock ReplaceChildrenController<Preparation, Ingredient> controller;
|
|
|
+ Preparation stuff;
|
|
|
+ @InjectMocks PreparationPanel panel = new PreparationPanel();
|
|
|
|
|
|
@BeforeEach
|
|
|
void setUp() {
|
|
|
+ stuff = mock(Preparation.class);
|
|
|
Duration dur = new Duration(Duration.Display.SECONDS, 0, 30);
|
|
|
doReturn(dur).when(stuff).getDuration();
|
|
|
- doReturn(Arrays.asList(
|
|
|
- new Ingredient("Butter", "", new Amount("10 g")),
|
|
|
- new Ingredient("Salt", "", new Amount("0.25 tsp"))
|
|
|
- )).when(stuff).getIngredients();
|
|
|
-
|
|
|
- panel = new PreparationPanel(stuff);
|
|
|
+
|
|
|
+ panel.setModel(stuff);
|
|
|
}
|
|
|
|
|
|
@Test
|
|
|
void testHasContent() {
|
|
|
- assertThat(panel.getPanelIngredients().getComponents(),
|
|
|
- arrayWithSize(2));
|
|
|
+ verify(panelDuration).setModel(any());
|
|
|
+ verify(controller, times(1)).accept(any(), same(stuff));
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test
|
|
|
+ void testDoesNotUpdateDurationWhenNotified() {
|
|
|
+ clearInvocations(panelDuration);
|
|
|
+
|
|
|
+ ObserverDispatch.notifySubscribers(stuff);
|
|
|
+
|
|
|
+ verify(panelDuration, never()).setModel(any());
|
|
|
}
|
|
|
|
|
|
@Test
|
|
|
void testUpdatesNumberOfChildrenWhenNotified() {
|
|
|
- doReturn(Arrays.asList(
|
|
|
- new Ingredient("Salt", "", new Amount("0.25 tsp"))
|
|
|
- )).when(stuff).getIngredients();
|
|
|
+ clearInvocations((Object) controller);
|
|
|
|
|
|
- ObserverDispatch.notifySubscribers(stuff);
|
|
|
-
|
|
|
- assertThat(panel.getPanelIngredients().getComponents(),
|
|
|
- arrayWithSize(1));
|
|
|
+ ObserverDispatch.notifySubscribers(stuff);
|
|
|
+
|
|
|
+ verify(controller, times(1)).accept(any(), same(stuff));
|
|
|
}
|
|
|
}
|