title: Is it possible to force set an internal variable for Unit Test purpose?
body: <p>I write up a simple function below to illustrate what I try to achieve.</p>
  
  <pre><code>public class MyTempClass {
      private boolean myVariable = false;
  
      private void setupMyVariable() {
          // Some callback etc from a web service that will determine the myVariable value
          myVariable = true;
      }
  
      public void doSomethingIfVaraibleIsTrue() {
          if (myVariable) {
              // Do something.
          }
      }
  }
  </code></pre>
  
  <p>I would want to unit test MyTempClass <code>doSomethingIfVaraibleIsTrue</code> function is doing something when <code>myVariable</code> is true, and not doing something when <code>myVariable</code> is false. However <code>myVariable</code> is a private boolean, and not easily set (e.g. it is set from a callback of a service).</p>
  
  <p>I also don't want to make a setter for <code>myVariable</code> as it is really private to the class. Is there any way to Mock/Stud or make <code>myVariable</code> true so that I could unit test my <code>doSomethingIfVaraibleIsTrue</code>?</p>