@Test
    public final void testUpdate() {
        // Test that the update function can move a paddle.
        Robot robot;
        try {
            robot = new Robot();
            Field paddleField, directionField;
            Paddle paddle;

            // Check that direction starts at 0
            {
                // Gain access to the paddle
                paddleField = testgame.getClass().getDeclaredField("paddle");
                paddleField.setAccessible(true);
                paddle = (Paddle) paddleField.get(testgame);
                // Gain access to the direction field of the paddle
                directionField =
                        paddle.getClass().getDeclaredField("direction");
                directionField.setAccessible(true);

                assertEquals(0, directionField.get(paddle));
            }

            // Check that when 'a' is pressed direction is set to -1
            {
                // Press 'A'
                robot.keyPress(KeyEvent.VK_A);
                // The game needs a little time to register the key
                Thread.sleep(SLEEPDELAY);

                // Gain access to the paddle
                paddleField = testgame.getClass().getDeclaredField("paddle");
                paddleField.setAccessible(true);
                paddle = (Paddle) paddleField.get(testgame);
                directionField =
                        paddle.getClass().getDeclaredField("direction");
                directionField.setAccessible(true);

                assertEquals(-1, directionField.get(paddle));
            }

            // Check that when 'a' is released direction is reset to 0
            {
                // Release 'A'
                robot.keyRelease(KeyEvent.VK_A);
                // The game needs a little time to register the key
                Thread.sleep(SLEEPDELAY);

                // Gain access to the paddle
                paddleField = testgame.getClass().getDeclaredField("paddle");
                paddleField.setAccessible(true);
                paddle = (Paddle) paddleField.get(testgame);
                directionField =
                        paddle.getClass().getDeclaredField("direction");
                directionField.setAccessible(true);

                assertEquals(0, directionField.get(paddle));
            }

            // Check that when 'd' is pressed with 'a' released direction is set
            // to 1
            {
                // Press 'D'
                robot.keyPress(KeyEvent.VK_D);
                // The game needs a little time to register the key
                Thread.sleep(SLEEPDELAY);

                // Gain access to the paddle after a change
                paddleField = testgame.getClass().getDeclaredField("paddle");
                paddleField.setAccessible(true);
                paddle = (Paddle) paddleField.get(testgame);
                directionField =
                        paddle.getClass().getDeclaredField("direction");
                directionField.setAccessible(true);

                assertEquals(1, directionField.get(paddle));
            }

            // Check that when 'd' is released direction is reset to 0
            {
                // Release 'D'
                robot.keyRelease(KeyEvent.VK_D);
                // The game needs a little time to register the key
                Thread.sleep(SLEEPDELAY);

                // Gain access to the paddle after a change
                paddleField = testgame.getClass().getDeclaredField("paddle");
                paddleField.setAccessible(true);
                paddle = (Paddle) paddleField.get(testgame);
                directionField =
                        paddle.getClass().getDeclaredField("direction");
                directionField.setAccessible(true);
                assertEquals(0, directionField.get(paddle));
            }

            // Check that when two direction buttons are pressed, the first
            // one pressed is dominant
            {

                // Press keys, a first.
                robot.keyPress(KeyEvent.VK_A);
                // The game needs a little time to register the key
                Thread.sleep(SLEEPDELAY);
                robot.keyPress(KeyEvent.VK_D);
                // The game needs a little time to register the key
                Thread.sleep(SLEEPDELAY);

                // Gain access to the paddle after a change
                paddleField = testgame.getClass().getDeclaredField("paddle");
                paddleField.setAccessible(true);
                paddle = (Paddle) paddleField.get(testgame);
                directionField =
                        paddle.getClass().getDeclaredField("direction");
                directionField.setAccessible(true);

                assertEquals(-1, directionField.get(paddle));

//                // Release D. A should stay active.
//                robot.keyRelease(KeyEvent.VK_D);
//                // The game needs a little time to register the key. This case
//                // may take a little longer than usual
//                Thread.sleep(SLEEPDELAY);
//
//                // Gain access to the paddle after a change
//                paddleField = testgame.getClass().getDeclaredField("paddle");
//                paddleField.setAccessible(true);
//                paddle = (Paddle) paddleField.get(testgame);
//                directionField =
//                        paddle.getClass().getDeclaredField("direction");
//                directionField.setAccessible(true);
//
//                assertEquals(-1, directionField.get(paddle));
//
//                // Reapply D and then release A. D should go active.
//                robot.keyPress(KeyEvent.VK_D);
//                // The game needs a little time to register the key
//                Thread.sleep(SLEEPDELAY);
//                robot.keyRelease(KeyEvent.VK_A);
//                // The game needs a little time to register the key
//                Thread.sleep(SLEEPDELAY);
//
//                // Gain access to the paddle after a change
//                paddleField = testgame.getClass().getDeclaredField("paddle");
//                paddleField.setAccessible(true);
//                paddle = (Paddle) paddleField.get(testgame);
//                directionField =
//                        paddle.getClass().getDeclaredField("direction");
//                directionField.setAccessible(true);
//
//                assertEquals(1, directionField.get(paddle));
            }

        } catch (IllegalAccessException e) {
            // TODO Auto-generated catch block
            fail("Can't access the direction field.");
        } catch (NoSuchFieldException e) {
            e.printStackTrace();
            fail("The direction field does not exist.");
        } catch (AWTException e) {
            e.printStackTrace();
            fail("Can't create the testing robot.");
        } catch (InterruptedException e1) {
            // Fired when the sleep function fails
            e1.printStackTrace();
        } finally {
            robot = null;
        }
    }