void (String classNameToSearch, String[] expectedFileNames, SearchScope scope) { final PsiClass aClass = myJavaFacade.findClass(classNameToSearch); assertNotNull(aClass); PsiReference[] refs = ReferencesSearch.search(aClass, scope, false).toArray(PsiReference.EMPTY_ARRAY); ArrayList<PsiFile> files = new ArrayList<>(); for (PsiReference ref : refs) { PsiFile file = ref.getElement().getContainingFile(); if (!files.contains(file)) { files.add(file); } } assertEquals("files count", expectedFileNames.length, files.size()); Collections.sort(files, Comparator.comparing(PsiFileSystemItem::getName)); Arrays.sort(expectedFileNames); for (int i = 0; i < expectedFileNames.length; i++) { String name = expectedFileNames[i]; PsiFile file = files.get(i); assertEquals(name, file.getName()); } }