title: How to write junit test for a class that has member variables that are topComponents?
body: <pre><code>public class Something {
  
  private static Something something = new  Something();
  
  public static Something get(){
      return something;
  }
  
  private EventQueueWindow eventQueue;
  
  private Something(){
      TopComponent tc = WindowManager.getDefault().findTopComponent("EventQueueWindow");
      eventQueue = (EventQueueWindow) tc;
  }
  
  EventQueue getQueue(){
      return eventQueue;
  }
  
  }//end class Something
  </code></pre>
  
  <p>Now I want to write a JUnit test which requires the ability to access eventQueue.</p>
  
  <pre><code>public void testgetQueue() {
      Something something = Something.get();
      assertEquals("Failed to return EventQueueWindow",something.getQueue().getClass(), EventQueueWindow.class);
  }
  </code></pre>
  
  <p>I get a <code>java.lang.NullPointerException</code> when I run the test because <code>eventQueue</code> has a <code>null</code> value despite it being assigned a value in class <code>Something's</code> constructor. I've read around that this may have something to do with components being handle in a different thread or not being initialized before the test is run. But I'm pretty new to java and unit testing and don't know how to solve this problem. Any guidance would be appreciated.</p>