Showing lean windows makes them tiny
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 48/100
Research direction
Run the supplied RobotTest regression case first, then read org.assertj.swing.monitor.WindowStatus#makeLargeEnoughToReceiveEvents and its shouldResize() logic. Done means showWindow leaves a packed window taller than its title-bar inset instead of shrinking it to MINIMUM_WINDOW_SIZE, and the regression test passes.
Written by the indexing model from the issue text.
Description
If a Window has little content, AssertJ makes the window even smaller.
Here's a failing test:
import org.assertj.swing.core.BasicRobot;
import org.assertj.swing.core.Robot;
import org.assertj.swing.edt.GuiActionRunner;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockito.ArgumentCaptor;
import javax.swing.JComponent;
import javax.swing.JFrame;
import javax.swing.JTextField;
import java.awt.Dimension;
import java.util.List;
import static org.assertj.core.api.Assertions.within;
import static org.assertj.core.api.AssertionsForClassTypes.assertThat;
import static org.assertj.core.api.Assumptions.assumeThat;
import static org.mockito.BDDMockito.then;
import static org.mockito.Mockito.atLeastOnce;
import static org.mockito.Mockito.spy;
class RobotTest {
private Robot robot;
@BeforeEach
void setUp() {
robot = BasicRobot.robotWithCurrentAwtHierarchy();
}
@AfterEach
void tearDown() {
robot.cleanUp();
}
@Test
void showWindow_ifPreferredWindowHeightExceedsTitleBarHeight_doesNotShrinkWindowToTitleBarHeight() {
JTextField field = new JTextField();
field.setColumns(10);
JFrame frame = spy(createFrame(field));
int titleBarInset = frame.getInsets().top;
assumeThat(titleBarInset).isCloseTo(30, within(1));
assumeThat(frame.getPreferredSize().height).isGreaterThan(titleBarInset);
robot.showWindow(frame);
ArgumentCaptor<Dimension> captor = ArgumentCaptor.forClass(Dimension.class);
then(frame).should(atLeastOnce()).setSize(captor.capture());
List<Dimension> setSizes = captor.getAllValues();
Dimension lastSetDimension = setSizes.get(setSizes.size() - 1);
assertThat(lastSetDimension.height).isGreaterThan(titleBarInset);
}
private JFrame createFrame(JComponent component) {
return GuiActionRunner.execute(() -> {
JFrame frame = new JFrame();
frame.add(component);
frame.pack(); // packed
return frame;
});
}
}
It's all because of the shouldResize() method (see org.assertj.swing.monitor.WindowStatus#makeLargeEnoughToReceiveEvents). If the window's preferred size (which doesn't include insets) minus ≈30 pixels of the title bar top inset is lower than 30 pixels, the window is guaranteed to be shrunk to MINIMUM_WINDOW_SIZE (50,30). You also get ugly jittering of the pointer for several seconds.
// org.assertj.swing.monitor.WindowStatus#makeLargeEnoughToReceiveEvents
@RunsInCurrentThread
private void makeLargeEnoughToReceiveEvents(@Nonnull Window window) {
if (!shouldResize(window)) {
return;
}
window.setSize(MINIMUM_WINDOW_SIZE);
}
Java 8.
- Dominant language
- Java
- Stars
- 121
- Forks
- 52
- PR merge metrics
- No merged PRs in 30d
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from assertj/assertj-swing
-
Difficulty 5/5 Over a week Newbie friendliness 25/100
assertj/assertj-swing#279 ·
-
Difficulty 4/5 3-5 days Newbie friendliness 30/100
assertj/assertj-swing#276 · 1 comment ·
-
Update unit test to avoid deprecated `ExpectedException.none()` by using `Assert.assertThrows()` Open
Difficulty 4/5 3-5 days Newbie friendliness 35/100
assertj/assertj-swing#275 ·
-
Difficulty 3/5 1-2 days Newbie friendliness 35/100
assertj/assertj-swing#277 · 1 comment ·
-
Difficulty 4/5 3-5 days Newbie friendliness 35/100
assertj/assertj-swing#274 · 2 comments ·
All issues in assertj/assertj-swing
Similar issues
-
documentation
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
inu-appcenter/memorIN-backend#288 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
-
frontend maui-pilot pilot-ask question
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
-
area/plugin
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
kestra-io/plugin-kestra#190 ·