I have Swing java application with network communications to several "Players" that are represented as player objects, each with their own communication thread. The app has a "Team" object managing all player objects. Several UI components listen to events passed from the players through the Team object.
In my design, the team object fires all events on the Swing thread using invokeLater, so that the rest of my application does not need to bother with threading issues. However, I don't know how I can test the Team class in a JUnit test.
A little more background. At first I had the Team object fire its events on the player object threads (no thread switching at all). The Team unit test succeeded, but I got into many threading issues in my UI with invokeLaters and synchronized all over the place. I then decided to simplify the threading model by having the Team object fire events on the Swing thread, but now the Team unit test fails because it does not receive the events. What to do?
A solution that comes to mind is to introduce an extra object on top of Team that does the thread switch and keep the original unit test intact, but I do not like the idea of introducing complexity in production code just to make a unit test succeed.