title: How to test broadcast receiver is executed in unit test?
body: <p>I need to invoke a method on main thread, for that purpose i am using @UiThreadTest and calling the method inside my test.
  That method is responsible to send broadcast receiver. 
  So i am registering the receiver and setting a boolean value to test if broadcast has been sent or not.
  In logs i am able to see the broadcast is executed. 
  But getting assertion failure error inside test.
  Is this some threading issue?</p>
  
  <p>//broadcase receiver</p>
  
  <pre><code>private class Receiver extends BroadcastReceiver {
      @Override
      public void onReceive(Context context, final Intent intent) {
         if (mUiUpdateReceiver != null &amp;&amp; intent.getAction().equals(MessageCenter.INTENT_UI_REFRESH)) {
             mbroadcastFlag = true;
         }
      }
  }
  </code></pre>
  
  <p>//test</p>
  
  <pre><code>@UiThreadTest
      public void test_broadcast () throws Exception{
          mUiUpdateReceiver = new Receiver();
          IntentFilter intentFilter = new IntentFilter();
          intentFilter.addAction(SampleClass.INTENT_REFRESH);
  
          LocalBroadcastManager.getInstance(mAppContext).registerReceiver(mUiUpdateReceiver, intentFilter);
  
          mbroadcastFlag = false;
          sampleClass.method();
          Thread.sleep(2000);
          assertTrue(mbroadcastFlag);
          LocalBroadcastManager.getInstance(mAppContext).unregisterReceiver(mUiUpdateReceiver);
  
      }
  </code></pre>