JMockit Mocks Are Not Being Created
Nobody has claimed this yet.
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 45/100
Research direction
Start with src/test/java/com/github/opticyclic/demo/assertj/SimpleFormTest.java and the GuiActionRunner.execute call in the linked reproduction project. Compare the mocked behavior outside and inside executeInEDT, then run the test to confirm the button receives "Mock Button Text" rather than "Not Mocked".
Written by the indexing model from the issue text.
Description
I took the code example from here https://stackoverflow.com/questions/14375854/jmockit-and-fest-ui-testing and put it in a gradle project here https://github.com/opticyclic/assertj-swing-mocks
The test code inside the GuiActionRunner doesn't seem to get mocked even though the code outside it does.
@Override
protected void onSetUp() {
//Mock the Service
new Expectations() {{
service.getValue();
result = mockText;
}};
//Demonstrate that the mocking is working here
SimpleService simpleService = new SimpleService();
Assert.assertEquals(simpleService.getValue(), mockText);
JFrame frame = GuiActionRunner.execute(new GuiQuery<JFrame>() {
@Override
protected JFrame executeInEDT() {
SimpleController controller = new SimpleController();
JFrame frame = new JFrame("Simple Frame");
frame.add(controller.getPanel());
frame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
frame.pack();
return frame;
}
});
The test fails with:
java.lang.AssertionError: [javax.swing.JButton[name='testButton', text='Not Mocked', enabled=true, visible=true, showing=true] - property:'text']
Expecting:
"Not Mocked"
to match pattern:
"Mock Button Text"
Why are the mocks not being created?
- 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 2/5 1-3 hours Newbie friendliness 48/100
assertj/assertj-swing#278 · 1 comment ·
-
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 ·
All issues in assertj/assertj-swing
Similar issues
-
certification
Difficulty 1/5 Under an hour Newbie friendliness 80/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
-
[BUG] ECR GetAuthorizationToken returns a proxyEndpoint for the default region, not the request's Openbug ecr
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
-
Needs: Triage Type: Feature request
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
AntennaPod/AntennaPod#8794 ·
-
agentic-workflows
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
github/copilot-sdk#2760 ·