title: Why does JPanelFixture.comboBox().pressAndReleaseKeys() work with FEST, but not with AssertJ?
body: <p>When trying to simulate input using AssertJ's pressAndReleaseKeys() for unit testing a JComboBox in a Java Swing program, I am not seeing the expected behavior. The program will most often hang on the pressAndReleaseKeys line and then fail, or occasionally will delete all the text currently in the JComboBox being tested, causing later assertions to fail (i.e. requireSelection()). The stack trace I receive for the provided example program (see below) when it hangs is as follows:</p>
  <blockquote>
  <p>Focus change to javax.swing.JComboBox[name='combob', selectedItem='Bean', contents=[&quot;Pork&quot;, &quot;Beans&quot;, &quot;Rice&quot;], editable=true, enabled=true, visible=true, showing=true] failed focus owner:  javax.swing.plaf.metal.MetalComboBoxEditor$1(javax.swing.JTextField)[name=null, text='Bean', enabled=true, visible=true, showing=true]</p>
  <p>org.assertj.swing.exception.ActionFailedException<br />
  at org.assertj.swing.exception.ActionFailedException.actionFailure(ActionFailedException.java:33)<br />
  at org.assertj.swing.core.BasicRobot.focus(BasicRobot.java:301)<br />
  at org.assertj.swing.core.BasicRobot.focusAndWaitForFocusGain(BasicRobot.java:270)<br />
  at org.assertj.swing.driver.ComponentDriver.focusAndWaitForFocusGain(ComponentDriver.java:419)<br />
  at org.assertj.swing.driver.ComponentDriver.pressAndReleaseKeys(ComponentDriver.java:315)<br />
  at org.assertj.swing.fixture.AbstractComponentFixture.pressAndReleaseKeys(AbstractComponentFixture.java:293)<br />
  at javapractice.ComboBoxSampleTest.testMain(ComboBoxSampleTest.java:59)</p>
  </blockquote>
  <p>I have been using FEST and am hoping to migrate my tests to AssertJ since it is being actively maintained, whereas FEST hasn't been updated for years. I used Joel Costigliola's <a href="http://joel-costigliola.github.io/assertj/assertj-swing-migrating.html" rel="nofollow noreferrer">migration from Fest to AssertJ</a> guide, but am having trouble when simulating keyboard input by using pressAndReleaseKeys(). I am able to simulate input when using a JTextComponentFixture i.e.</p>
  <pre><code>window.textBox(&quot;textB&quot;).pressAndReleaseKeys(KeyEvent.VK_LEFT);
  </code></pre>
  <p>(where window is a FrameFixture, a container in both AssertJ and FEST), but I am unable to simulate input when using a JComboBoxFixture i.e.</p>
  <pre><code>window.comboBox(&quot;comboB&quot;).pressAndReleaseKeys(KeyEvent.VK_LEFT);
  </code></pre>
  <p>This obstacle can usually be avoided, since most &quot;key presses&quot; can be simulated by using enterText i.e.</p>
  <pre><code>window.comboBox(&quot;comboB&quot;).enterText(&quot;\n&quot;); //to press the enter key
  window.comboBox(&quot;comboB&quot;).enterText(&quot;\b&quot;); //to press the backspace key
  </code></pre>
  <p>but I would like to be able to use the arrow keys, control key, and other keys where I can't simulate the key press using enterText(). Is this failure due to an issue with my environment*, an issue with the way I'm using it, or is the API itself flawed?</p>
  <p>I tried using pressKey() and then releaseKey() as a workaround, but that doesn't work with JComboBox either, and my program instead hangs on pressKey(). That being said, I am not able to use pressKey() and releaseKey() to test a JComboBox with FEST either.</p>
  <p>*Environment details:<br />
  Language version: java version &quot;1.8.0_131&quot;<br />
  Platform version (e.g. .NET 3.5; note that this isn’t always implicit from the language version, or vice versa)<br />
  Operating system: Red Hat Release 6.10 (Santiago)<br />
  IDE: Netbeans 8.0.2</p>
  <p>Sample GUI application:</p>
  <pre><code>package javapractice;
  
  import java.awt.Dimension;
  import java.awt.FlowLayout;
  import java.awt.event.ItemEvent;
  import java.awt.event.ItemListener;
  import javax.swing.JComboBox;
  import javax.swing.JFrame;
  import javax.swing.JLabel;
  import javax.swing.JPanel;
  import javax.swing.JTextField;
  
  public class ComboBoxSample extends JFrame implements ItemListener{
      JPanel jp;
      JComboBox jcb;
      JLabel result;
      JLabel title;
      JTextField jtc;
  
      public static void main(String[] args) {
          ComboBoxSample frame = new ComboBoxSample();
      }
      
      ComboBoxSample() {
          super();
          this.setDefaultCloseOperation(EXIT_ON_CLOSE);
          this.setVisible(true);
          this.setTitle(&quot;Testing AssertJ&quot;);
          this.setLayout(new FlowLayout());
          jp = new JPanel();
          jcb = new JComboBox(new String[] {&quot;Pork&quot;, &quot;Beans&quot;, &quot;Rice&quot;});
          jcb.setEditable(true);
          jcb.setName(&quot;combob&quot;);
          jtc = new JTextField();
          jtc.setEditable(true);
          jtc.setPreferredSize(new Dimension(150, 25));
          jtc.setName(&quot;textb&quot;);
          title = new JLabel(&quot;Food: &quot;);
          result = new JLabel(&quot;No food&quot;);
          jp.add(title);
          jp.add(jcb);
          jp.add(result);
          jp.add(jtc);
          this.add(jp);
          this.setLocationRelativeTo(null);
          jcb.addItemListener(this);
          
  
          this.pack();
          this.repaint();        
      }
  
      @Override
      public void itemStateChanged(ItemEvent e) {
          if(e.getSource() == jcb) {
              result.setText(&quot;I'm eating &quot; + jcb.getSelectedItem());
          }
          this.pack();
      }
      
      public void cleanUp() {
          jcb = null;
          result = null;
          jtc = null;
          jp = null;
          title = null;
      }   
  }
  </code></pre>
  <p>Test File for Fest:</p>
  <pre><code>package javapractice;
  
  import com.sun.glass.events.KeyEvent;
  import org.junit.After;
  import org.junit.AfterClass;
  import org.junit.Before;
  import org.junit.BeforeClass;
  import org.junit.Test;
  
  /**
   * Fest imports.
   */
  import org.fest.swing.edt.FailOnThreadViolationRepaintManager;
  import org.fest.swing.edt.GuiActionRunner;
  import org.fest.swing.edt.GuiQuery;
  import org.fest.swing.fixture.FrameFixture;
  
  public class ComboBoxSampleTest {
      private FrameFixture window;
      private ComboBoxSample frame;
      
      @BeforeClass
      public static void setUpClass() {
          FailOnThreadViolationRepaintManager.install();
      }
      
      @AfterClass
      public static void tearDownClass() {
          
      }
      
      @Before
      public void setUp() {
          frame = GuiActionRunner.execute(new GuiQuery&lt;ComboBoxSample&gt;() {
              @Override
              protected ComboBoxSample executeInEDT() {
                  return new ComboBoxSample();
              }
          });
          window = new FrameFixture(frame);
          window.show();
      }
      
      @After
      public void tearDown() {
          window.cleanUp();
          frame.cleanUp();
      }
  
      /**
       * Test of main method, of class ComboBoxSample.
       */
      @Test
      public void testMain() {
          //Delay so that we can see what's going on
          try {
              Thread.sleep(2000);
          } catch (InterruptedException ie) {
              
          }
          
          window.textBox(&quot;textb&quot;).enterText(&quot;hi there&quot;);
          window.textBox(&quot;textb&quot;).pressAndReleaseKeys(KeyEvent.VK_BACKSPACE);
          window.comboBox().replaceText(&quot;Bean&quot;);
          window.comboBox().pressAndReleaseKeys(KeyEvent.VK_S);
          window.comboBox().pressAndReleaseKeys(KeyEvent.VK_DOWN);
          window.comboBox().pressAndReleaseKeys(KeyEvent.VK_DOWN);
          window.comboBox().pressAndReleaseKeys(KeyEvent.VK_DOWN);
          window.comboBox().pressAndReleaseKeys(KeyEvent.VK_ENTER);
      }
  }
  </code></pre>
  <p>Test File for AssertJ:</p>
  <pre><code>package javapractice;
  
  import com.sun.glass.events.KeyEvent;
  import org.junit.After;
  import org.junit.AfterClass;
  import org.junit.Before;
  import org.junit.BeforeClass;
  import org.junit.Test;
  
  /**
   * AssertJ imports.
   */
  import org.assertj.swing.edt.FailOnThreadViolationRepaintManager;
  import org.assertj.swing.edt.GuiActionRunner;
  import org.assertj.swing.fixture.FrameFixture;
  
  public class ComboBoxSampleTest {
      private FrameFixture window;
      private ComboBoxSample frame;
      
      @BeforeClass
      public static void setUpClass() {
          FailOnThreadViolationRepaintManager.install();
      }
      
      @AfterClass
      public static void tearDownClass() {
          
      }
      
      @Before
      public void setUp() {
          frame = GuiActionRunner.execute(() -&gt; new ComboBoxSample());
          window = new FrameFixture(frame);
          window.show();
      }
      
      @After
      public void tearDown() {
          window.cleanUp();
          frame.cleanUp();
      }
  
      /**
       * Test of main method, of class ComboBoxSample.
       */
      @Test
      public void testMain() {
          //Delay so that we can see what's going on
          try {
              Thread.sleep(2000);
          } catch (InterruptedException ie) {
              
          }
          
          window.textBox(&quot;textb&quot;).enterText(&quot;hi there&quot;);
          window.textBox(&quot;textb&quot;).pressAndReleaseKeys(KeyEvent.VK_BACKSPACE);
          window.comboBox().replaceText(&quot;Bean&quot;);
          //the above line is the last one to execute
          window.comboBox().pressAndReleaseKeys(KeyEvent.VK_S);
          window.comboBox().pressAndReleaseKeys(KeyEvent.VK_DOWN);
          window.comboBox().pressAndReleaseKeys(KeyEvent.VK_DOWN);
          window.comboBox().pressAndReleaseKeys(KeyEvent.VK_DOWN);
          window.comboBox().pressAndReleaseKeys(KeyEvent.VK_ENTER);
      }
  }
  </code></pre>