|
|
@@ -1,71 +1,74 @@
|
|
|
package org.leumasjaffe.recipe.view;
|
|
|
|
|
|
import static org.junit.jupiter.api.Assertions.*;
|
|
|
-import static org.hamcrest.MatcherAssert.assertThat;
|
|
|
-import static org.hamcrest.collection.IsArrayWithSize.arrayWithSize;
|
|
|
-import static org.hamcrest.number.OrderingComparison.greaterThanOrEqualTo;
|
|
|
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.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.Mock;
|
|
|
+import org.mockito.InjectMocks;
|
|
|
+import org.mockito.Spy;
|
|
|
import org.mockito.junit.jupiter.MockitoExtension;
|
|
|
|
|
|
@ExtendWith(MockitoExtension.class)
|
|
|
-@RunWith(JUnitPlatform.class)
|
|
|
class StepPanelTest extends SwingTestCase {
|
|
|
List<Ingredient> ingredients;
|
|
|
- @Mock Step stuff;
|
|
|
- StepPanel panel;
|
|
|
+ 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"))));
|
|
|
- doReturn(new Duration("30 s")).when(stuff).getDuration();
|
|
|
- doReturn("These are test instructions").when(stuff).getInstruction();
|
|
|
- doReturn(ingredients).when(stuff).getIngredients();
|
|
|
+ stuff = new Step();
|
|
|
+ stuff.setDuration(new Duration("30 s"));
|
|
|
+ stuff.setIngredients(ingredients);
|
|
|
+ stuff.setInstruction("These are test instructions");
|
|
|
|
|
|
- panel = new StepPanel(stuff);
|
|
|
+ panel.setModel(stuff);
|
|
|
}
|
|
|
|
|
|
@Test
|
|
|
void testFilledOutWithContent() {
|
|
|
- assertEquals("Step 1", panel.getLblIndex().getText());
|
|
|
assertEquals("These are test instructions", panel.getTxtpnInstructions().getText());
|
|
|
- assertThat(panel.getPanelIngredients().getComponents(),
|
|
|
- arrayWithSize(greaterThanOrEqualTo(1)));
|
|
|
+ verify(panelIngredients).setModel(same(ingredients), any());
|
|
|
}
|
|
|
|
|
|
- // TODO: Test added ingredients regenerate AutoGrowPanel... ?
|
|
|
+ @Test
|
|
|
+ void testSetListPositionUpdatesIndex() {
|
|
|
+ panel.setListPosition(1);
|
|
|
+ verify(lblIndex).setText("Step 2");
|
|
|
+ }
|
|
|
|
|
|
@Test
|
|
|
void testUpdatesContentOnNotification() {
|
|
|
- doReturn("New instructions").when(stuff).getInstruction();
|
|
|
+ stuff.setInstruction("New instructions");
|
|
|
ObserverDispatch.notifySubscribers(stuff);
|
|
|
|
|
|
assertEquals("New instructions", panel.getTxtpnInstructions().getText());
|
|
|
}
|
|
|
|
|
|
-
|
|
|
@Test
|
|
|
void testViewUpdatesAltersModel() {
|
|
|
panel.getTxtpnInstructions().setText("New instructions");
|
|
|
waitForSwing();
|
|
|
|
|
|
- verify(stuff).setInstruction(eq("New instructions"));
|
|
|
+ assertEquals("New instructions", stuff.getInstruction());
|
|
|
}
|
|
|
|
|
|
@Test
|