@Test
public void testGoToInstance() {

  FakeInstanceObject referer =
    new FakeInstanceObject.Builder(myFakeCaptureObject, 1, "REFERER").setFields(Collections.singletonList("mField")).build();
  FakeInstanceObject referee = new FakeInstanceObject.Builder(myFakeCaptureObject, 2, "REFEREE").build();
  referer.setFieldValue("mField", OBJECT, referee);
  myFakeCaptureObject.addInstanceObjects(ImmutableSet.of(referer, referee));
  myStage.selectCaptureDuration(
    new CaptureDurationData<>(1, false, false, new CaptureEntry<CaptureObject>(new Object(), () -> myFakeCaptureObject)),
    null);
  assertNotNull(myStage.getSelectedCapture());
  myStage
    .selectClassSet((ClassSet)myFakeCaptureObject.getHeapSet(FakeCaptureObject.DEFAULT_HEAP_ID).findContainingClassifierSet(referee));
  assertNotNull(myStage.getSelectedClassSet());
  myStage.selectInstanceObject(referee);
  JTree tree = myDetailsView.getReferenceTree();
  assertNotNull(tree);
  assertEquals(referee, myStage.getSelectedInstanceObject());
  // Check that the Go To Instance menu item exists but is disabled since no instance is selected
  List<ContextMenuItem> menus = myFakeIdeProfilerComponents.getComponentContextMenus(tree);
  assertNotNull(menus);
  assertEquals(1, menus.size());
  assertEquals("Go to Instance", menus.get(0).getText());
  assertFalse(menus.get(0).isEnabled());
  // Selects the referer node and triggers the context menu action to select the ref instance.
  TreeNode refNode = ((MemoryObjectTreeNode)tree.getModel().getRoot()).getChildAt(0);
  tree.setSelectionPath(new TreePath(refNode));
  assertTrue(menus.get(0).isEnabled());
  menus.get(0).run();
  assertEquals(myFakeCaptureObject.getHeapSet(FakeCaptureObject.DEFAULT_HEAP_ID), myStage.getSelectedHeapSet());
  assertNotNull(myStage.getSelectedClassSet());
  assertEquals(myStage.getSelectedClassSet(), myStage.getSelectedClassSet().findContainingClassifierSet(referer));
  assertEquals(referer, myStage.getSelectedInstanceObject());
}