|
|
@@ -3,6 +3,7 @@ package org.leumasjaffe.recipe.view;
|
|
|
import static org.hamcrest.MatcherAssert.assertThat;
|
|
|
import static org.hamcrest.collection.IsArrayWithSize.arrayWithSize;
|
|
|
import static org.mockito.Mockito.*;
|
|
|
+import static org.leumasjaffe.mock.ListenerInjector.*;
|
|
|
|
|
|
import java.awt.event.FocusListener;
|
|
|
import java.util.ArrayList;
|
|
|
@@ -151,27 +152,29 @@ class AutoGrowPanelTest extends SwingTestCase {
|
|
|
}
|
|
|
|
|
|
@Test
|
|
|
- void testEmptyingContentClearsPanel() {
|
|
|
+ void testLosingFocusWithoutContentClearsPanel() {
|
|
|
final MockComponent mock = spy(new MockComponent("A"));
|
|
|
|
|
|
AutoGrowPanel<MockComponent, MockComponent> panel = create(mock);
|
|
|
getTestFrame().add(panel);
|
|
|
mock.setText("");
|
|
|
-
|
|
|
+ injectFocusLost(mock, "ShrinkOnEmpty");
|
|
|
+
|
|
|
assertThat(panel.getComponents(), arrayWithSize(1));
|
|
|
verify(shared, times(1)).remove(0);
|
|
|
}
|
|
|
|
|
|
|
|
|
@Test
|
|
|
- void testEmptyingContentAdjustsAllPositions() {
|
|
|
+ void testLosingFocusWithoutContentAdjustsAllPositions() {
|
|
|
final MockComponent mock = spy(new MockComponent("A"));
|
|
|
|
|
|
@SuppressWarnings("unused")
|
|
|
AutoGrowPanel<MockComponent, MockComponent> panel = create(mock);
|
|
|
|
|
|
mock.setText("");
|
|
|
-
|
|
|
+ injectFocusLost(mock, "ShrinkOnEmpty");
|
|
|
+
|
|
|
verify(internal.get(0), times(2)).setListPosition(0);
|
|
|
}
|
|
|
|
|
|
@@ -193,7 +196,7 @@ class AutoGrowPanelTest extends SwingTestCase {
|
|
|
|
|
|
AutoGrowPanel<MockComponent, MockComponent> panel = create(mock);
|
|
|
getTestFrame().add(panel);
|
|
|
- mock.getDocument().insertString(0, "B", null);
|
|
|
+ mock.setText("B");
|
|
|
|
|
|
assertThat(panel.getComponents(), arrayWithSize(2));
|
|
|
verify(shared, never()).remove(anyInt());
|
|
|
@@ -210,6 +213,7 @@ class AutoGrowPanelTest extends SwingTestCase {
|
|
|
verify(callback).accept(true);
|
|
|
|
|
|
internal.get(0).setText("");
|
|
|
+ injectFocusLost(internal.get(0), "ShrinkOnEmpty");
|
|
|
verify(callback).accept(false);
|
|
|
}
|
|
|
|