package org.robolectric.integration_tests.atsl;

import static com.google.common.truth.Truth.assertThat;

import android.app.Instrumentation;
import android.content.Context;
import android.support.test.InstrumentationRegistry;
import android.support.test.runner.AndroidJUnit4;
import org.junit.Test;
import org.junit.runner.RunWith;

/** {@link InstrumentationRegistry} tests. */
@RunWith(AndroidJUnit4.class)
public class InstrumentationRegistryTest {

  private static Instrumentation priorInstrumentation = null;
  private static Context priorContext = null;

  @Test
  public void getArguments() {
    assertThat(InstrumentationRegistry.getArguments()).isNotNull();
  }

  @Test
  public void getInstrumentation() {
    assertThat(InstrumentationRegistry.getInstrumentation()).isNotNull();
  }

  @Test
  public void getTargetContext() {
    assertThat(InstrumentationRegistry.getTargetContext()).isNotNull();
    assertThat(InstrumentationRegistry.getTargetContext()).isEqualTo(InstrumentationRegistry.getContext());
  }

  @Test
  public void uniqueInstancesPerTest() {
    checkInstances();
  }

  @Test
  public void uniqueInstancesPerTest2() {
    checkInstances();
  }

  /**
   * Verifies that each test gets a new Instrumentation and Context, by comparing against instances
   * stored by prior test.
   */
  private void checkInstances() {
    if (priorInstrumentation == null) {
      priorInstrumentation = InstrumentationRegistry.getInstrumentation();
      priorContext = InstrumentationRegistry.getTargetContext();
    } else {
      assertThat(priorInstrumentation).isNotEqualTo(InstrumentationRegistry.getInstrumentation());
      assertThat(priorContext).isNotEqualTo(InstrumentationRegistry.getTargetContext());
    }
  }

}

@@ -945,37 +945,120 @@
 Registry.get
-Target
 Context
+()).isNotNull();%0A    assertThat(InstrumentationRegistry.getTargetContext().getPackageName
 ()).isEqualT
@@ -1051,32 +1051,41 @@
 me()).isEqualTo(
+%0A        
 InstrumentationR
@@ -1100,24 +1100,41 @@
 getContext()
+.getPackageName()
 );%0A  %7D%0A%0A  @T

Fix InstrumentationRegistryTest when running on device