title: Unit testing a class with private environment variables
body: <p>I have an EJB which I want to unit test its public methods. I am testing EJB as a pojo. So I just have instantiate it and called the public method. </p>
  
  <p>The problem is that public method sets some glassfish environment properties the environment variable is private. So I am not able to set it outside of the class and when I just call that public method for the environment object it throws nullPointerException.</p>
  
  <p>The class that I want to test has,</p>
  
  <pre><code>@Resource(name="NameServiceEnvironment")
  private Properties nameServiceEnvironment;
  
  
  
      public void setup() {
  
          // Set the environment.
          Properties environment = new Properties(); 
          environment.setProperty("name.host", this.nameServiceEnvironment.getProperty(NAME_HOST));
          environment.setProperty("name.port", this.nameServiceEnvironment.getProperty(NAME_PORT));
  
  ...}
  </code></pre>
  
  <p>So now for nameServiceEnvironment it throws the null pointer exception.</p>
  
  <p>Now from the test class I've just instantiated the above class and called the setup method.</p>
  
  <p>Thanks.</p>