void () { final PsiClass[] classes = JavaDirectoryService.getInstance().getClasses(getPackageDirectory()); PsiClass psiClass = classes[0]; FileEditorManager.getInstance(getProject()).openFile(psiClass.getContainingFile().getVirtualFile(), true); ProjectView projectView = ProjectView.getInstance(getProject()); ((ProjectViewImpl)projectView).setAutoscrollFromSource(true, ProjectViewPane.ID); ToolWindow toolWindow = ToolWindowManager.getInstance(getProject()).getToolWindow(ToolWindowId.PROJECT_VIEW); new ProjectViewToolWindowFactory().createToolWindowContent(getProject(), toolWindow); projectView.changeView(ProjectViewPane.ID); PlatformTestUtil.dispatchAllInvocationEventsInIdeEventQueue(); JComponent component = ((ProjectViewImpl)projectView).getComponent(); DataContext context = DataManager.getInstance().getDataContext(component); PsiElement element = CommonDataKeys.PSI_FILE.getData(context); assertThat(((PsiJavaFile)element).getName()).isEqualTo("Class1.java"); }