Home > Articles > Programming > Java

  • Print
  • + Share This
Like this article? We recommend

Constructing a Non-Renderable Frame

Instead of directly assigning a new JFrame instance to the frame instance variable, we isolate construction of the JFrame to the factory method createFrame. We’ll override this method in our test and have it instead supply an instance of NonRenderableFrame. In Listing 5, we use an anonymous inner class override of the HoldEm class to accomplish this goal.

Listing 5 Redefining createFrame to supply a NonRenderableFrame.

protected void setUp() {
  app = new HoldEm() {
   JFrame createFrame() {
     return new NonRenderableFrame();

  frame = app.frame();

There are a number of ways to get HoldEm to use a NonRenderableFrame instead of the normal production definition. The overriding technique shown is one approach. It has the interesting effect of requiring the test to know a bit about the implementation details of HoldEm. Code in HoldEmTest is dependent upon the fact that there’s a non-public method named createFrame defined in HoldEm.

  • + Share This
  • 🔖 Save To Your Account