void () { PsiDirectory root = ProjectRootUtil.getAllContentRoots(myProject) [0]; PsiFile file = PsiFileFactory.getInstance(myProject).createFileFromText("New.java", JavaFileType.INSTANCE, "class A{ Object o;}"); final PsiFile finalFile = file; file = WriteAction.compute(() -> (PsiFile)root.add(finalFile)); assertNotNull(file); PsiClass objectClass = myJavaFacade.findClass(CommonClassNames.JAVA_LANG_OBJECT, GlobalSearchScope.allScope(getProject())); assertNotNull(objectClass); checkUsages(objectClass, new String[]{"New.java"}); }