@Test
public void testFragmentLeaks() {

  long baseClassNativeFragmentId = 1;
  long subClassNativeFragmentId = 2;
  long baseClassSupportFragmentId = 3;
  long baseClassAndroidxFragmentId = 5;
  FakeCaptureObject capture = new FakeCaptureObject.Builder().build();
  // null FragmentManager and not waiting to be GC'd
  FakeInstanceObject leakingNativeBaseNativeFragment =
    new FakeInstanceObject.Builder(capture, baseClassNativeFragmentId, ActivityFragmentLeakInstanceFilter.NATIVE_FRAGMENT_CLASS_NAME)
      .addField(ActivityFragmentLeakInstanceFilter.FRAGFMENT_MANAGER_FIELD_NAME, ValueObject.ValueType.OBJECT, null)
      .setDepth(1)
      .build();
  // null FragmentManager but waiting to be GC'd
  FakeInstanceObject nonLeakingBaseNativeFragment =
    new FakeInstanceObject.Builder(capture, baseClassNativeFragmentId, ActivityFragmentLeakInstanceFilter.NATIVE_FRAGMENT_CLASS_NAME)
      .addField(ActivityFragmentLeakInstanceFilter.FRAGFMENT_MANAGER_FIELD_NAME, ValueObject.ValueType.OBJECT, null)
      .build();
  // null FragmentManager and not waiting to be GC'd
  FakeInstanceObject leakingSubClassNativeFragment =
    new FakeInstanceObject.Builder(capture, subClassNativeFragmentId, "my.native.fragment.subclass")
      .setSuperClassId(baseClassNativeFragmentId)
      .addField(ActivityFragmentLeakInstanceFilter.FRAGFMENT_MANAGER_FIELD_NAME, ValueObject.ValueType.OBJECT, null)
      .setDepth(1)
      .build();
  // non-null FragmentManager
  FakeInstanceObject nonLeakingSubClassNativeFragment =
    new FakeInstanceObject.Builder(capture, subClassNativeFragmentId, "my.native.fragment.subclass")
      .setSuperClassId(baseClassNativeFragmentId)
      .addField(ActivityFragmentLeakInstanceFilter.FRAGFMENT_MANAGER_FIELD_NAME, ValueObject.ValueType.OBJECT, new Object())
      .setDepth(1)
      .build();
  // null FragmentManager and not waiting to be GC'd
  FakeInstanceObject leakingSupportBaseNativeFragment =
    new FakeInstanceObject.Builder(capture, baseClassSupportFragmentId, ActivityFragmentLeakInstanceFilter.SUPPORT_FRAGMENT_CLASS_NAME)
      .addField(ActivityFragmentLeakInstanceFilter.FRAGFMENT_MANAGER_FIELD_NAME, ValueObject.ValueType.OBJECT, null)
      .setDepth(1)
      .build();
  // no mFragmentManager field
  FakeInstanceObject nonleakingAndroidXBaseNativeFragment =
    new FakeInstanceObject.Builder(capture, baseClassAndroidxFragmentId, ActivityFragmentLeakInstanceFilter.ANDROIDX_FRAGMENT_CLASS_NAME)
      .build();
  Set<InstanceObject> instances = ImmutableSet.of(leakingNativeBaseNativeFragment,
                                                  nonLeakingBaseNativeFragment,
                                                  leakingSubClassNativeFragment,
                                                  nonLeakingSubClassNativeFragment,
                                                  leakingSupportBaseNativeFragment,
                                                  nonleakingAndroidXBaseNativeFragment);
  ActivityFragmentLeakInstanceFilter filter = new ActivityFragmentLeakInstanceFilter();
  Set<InstanceObject> result = filter.filter(instances, capture.getClassDatabase());
  assertThat(result).containsExactly(leakingNativeBaseNativeFragment, leakingSubClassNativeFragment, leakingSupportBaseNativeFragment);
}