title: Android Unit Tests : Mock context that also returns a looper
body: <p>Here is my sample code :<br>
  <strong>SomeClass.java</strong></p>
  
  <pre><code>public class SomeClass {
      public SomeClass(Context mContext) {
          final Looper looper = mContext.getMainLooper();
          Handler mHandler = new Handler(looper);
      }
  }
  </code></pre>
  
  <p><strong>SomeClassTest.java</strong></p>
  
  <pre><code>public class SomeClassTest {
      private SomeClass mSomeClass;
  
      @Mock
      private Context mContext;
  
      @before
      public void setup(){
          mSomeClass = new SomeClass(mContext);
      }
  }
  </code></pre>
  
  <p>The above code generates a <code>NullPointerException</code> at the line <code>final Looper looper = mContext.getMainLooper();</code> in <code>SomeClass</code>.
  <br>
  How can I setup the mock context object to avoid this exception ?</p>