Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The problem is in the test code, which happens to call <code>SimpleServable#getValue()</code> during window construction, <em>before</em> the expectation for this method call is recorded in the test.</p> <p>To fix this, simply move the <code>new Expectation() {{ ... }}</code> block to the <code>onSetUp()</code> method, putting it before the call to <code>GuiActionRunner.execute(GuiQuery)</code>.</p> <p>The following simplified version of the code demonstrates it:</p> <pre><code>public final class SimpleForm { final JPanel testPanel; final JButton testButton; public SimpleForm() { testPanel = new JPanel(); testPanel.setName("testPanel"); testButton = new JButton(); testButton.setName("testButton"); testPanel.add(testButton); } } public final class SimpleService { public String getValue() { return null; } } public final class SimpleController { private final SimpleForm form; public SimpleController() { form = new SimpleForm(); SimpleService service = new SimpleService(); form.testButton.setText(service.getValue()); } public JPanel getPanel() { return form.testPanel; } } public final class SimpleTest extends FestSwingJUnitTestCase { FrameFixture window; @NonStrict SimpleService service; @Override protected void onSetUp() { FailOnThreadViolationRepaintManager.install(); // Record expectations *before* they are replayed: new Expectations() {{ service.getValue(); result = "TEST"; }}; JFrame frameUi = GuiActionRunner.execute(new GuiQuery&lt;JFrame&gt;() { @Override protected JFrame executeInEDT() { SimpleController controller = new SimpleController(); JFrame frame = new JFrame("TEST"); frame.add(controller.getPanel()); frame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); frame.pack(); return frame; } }); robot().settings().delayBetweenEvents(1000); window = new FrameFixture(robot(), frameUi); window.show(); } @Test public void test() { // This works provided "service.getValue()" gets called *after* // expectations are recorded. With the call happening during the // creation of the window, it must be recorded at the beginning // of the "onSetUp" method. window.panel("testPanel").button("testButton").requireText("TEST"); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload