title: Unit test condition for findFragmentByTag
body: <pre><code>Android Studio 3.2 Canary 2
  Build #AI-173.4591728, built on February 8, 2018
  JRE: 1.8.0_152-release-1024-b01 amd64
  JVM: OpenJDK 64-Bit Server VM by JetBrains s.r.o
  Linux 4.14.18-300.fc27.x86_64
  </code></pre>
  
  <p>I have the following activity and I want to unit test the case where the fragment is already attached and should return a non-null. And should fall into the else condition:</p>
  
  <p>This is my activity:</p>
  
  <pre><code>public class BillingActivity extends AppCompatActivity {
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.billing_container);
  
          if(getSupportFragmentManager().findFragmentByTag(BillingView.TAG) == null) {
              final FragmentTransaction fragmentTransaction =
                      getSupportFragmentManager().beginTransaction();
  
              fragmentTransaction.add(
                      R.id.billing_view_container,
                      BillingView.newInstance(),
                      BillingView.TAG);
  
              fragmentTransaction.commit();
          }
          else {
              Timber.d("Fragment already attached");
          }
      }
  }
  </code></pre>
  
  <p>The test class is this: I can write the test to attach a fragment, but I want to test the condition when a fragment is already attached and should return non-null.</p>
  
  <pre><code>class BillingActivityTest: BaseRobolectricTestRunner() {
      private lateinit var billingActivity: BillingActivity
  
      @Before
      fun setup() {
          billingActivity = Robolectric.buildActivity(BillingActivity::class.java)
                  .create()
                  .start()
                  .get()
      }
  
      @Test
      fun testBillingActivityIsNotNullValue() {
          assertThat(billingActivity, `is`(notNullValue()))
      }
  
      @Test
      fun testBillingFragmentHasStarted() {
          val actualFragment = billingActivity
                  .supportFragmentManager
                  .findFragmentByTag(BillingView.TAG)
  
          assertThat(actualFragment.tag, `is`(BillingView.TAG))
      }
  
      @Test
      fun testBillingFragmentAlreadyAttached() {
          /* how to test */
      }
  }
  </code></pre>
  
  <p>Thanks for any suggestions,</p>