Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JMockit Mocks Are Not Being Created #247

Open
opticyclic opened this issue Feb 25, 2020 · 0 comments
Open

JMockit Mocks Are Not Being Created #247

opticyclic opened this issue Feb 25, 2020 · 0 comments

Comments

@opticyclic
Copy link

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant