title: How can I simulate keypress in junit test?
body: <p>I have this in my main class <code>Board</code> (extends <code>JPanel</code>):</p>
  
  <pre><code> public class TAdapter extends KeyAdapter {
  
     public void keyPressed(KeyEvent e) {
  
          int key = e.getKeyCode();
  
          if ((key == KeyEvent.VK_LEFT) &amp;&amp; (!right)) {
              left = true;
              up = false;
              down = false;
          }
    }
  </code></pre>
  
  <p>I am trying to test if left becomes true when I press the left key:</p>
  
  <pre><code> @Test
   public void testKeyPressed() throws AWTException {
      Board instance = new Board();
      Robot rob = new Robot();
      instance.setFocusable(true);
      instance.requestFocus();
      rob.keyPress(KeyEvent.VK_LEFT);
      System.out.println(instance.up);
  }
  </code></pre>
  
  <p>Thanks!</p>