Hacktoberfest 2026: the issues maintainers tagged for October, open and beginner-friendly. Browse Hacktoberfest issues

JMockit Mocks Are Not Being Created

Open
#247 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
45/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Stale
Tech stack
java
Domain
desktop, testing

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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from assertj/assertj-swing

All issues in assertj/assertj-swing

Similar issues

More Java issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.