Image

JUnit blocks on Message Dialog

For a project where I'm browsing through database records I've added a message dialog for the user if there are no more records to browse. It looks something like this:



    protected void next()
    {
        if (movies.next()) {
            // set the text fields
        }
        else {
            JOptionPane.showMessageDialog(
                this,
                "There are no more records in the database",
                "Movie Project",
                JOptionPane.INFORMATION_MESSAGE
            );
        }
        showMessage("Next called");
    }


I'm testing with JUnit and I want to show that calling next() when there are no more records merely fails to update the fields. However, when I make that final next() call, my JUnit tests block, presumably because it's waiting for me to click the "OK" button. Is there someway around this? Is there someway I can get the application to think that the "OK" button has been clicked?