void (String @NotNull [] files, @NotNull String phraseToComplete, String @NotNull [] expectedOrder, @NotNull Predicate<PsiMember> resultFilter) { myFixture.configureByFiles(files); myFixture.type(phraseToComplete); final int offset = myFixture.getCaretOffset(); final LookupElement[] completionVariantsBeforeCompilation = myFixture.complete(CompletionType.BASIC); WriteCommandAction.runWriteCommandAction(myFixture.getProject(), () -> myFixture.getDocument(myFixture.getFile()).deleteString(offset - phraseToComplete.length(), offset)); rebuildProject(); myFixture.type(phraseToComplete); final LookupElement[] completionVariantsAfterCompilation = myFixture.complete(CompletionType.BASIC); assertNotEquals("Seems the test doesn't test anything: compiler indices doesn't affect on sorting", Arrays.toString(completionVariantsBeforeCompilation), Arrays.toString(completionVariantsAfterCompilation)); final String[] orderedMethods = Arrays.stream(completionVariantsAfterCompilation) .map(l -> l.getObject()) .filter(o -> o instanceof PsiMember) .map(o -> ((PsiMember)o)) .filter(resultFilter) .map(CompilerReferenceDataInCompletionTest::getPresentation) .toArray(String[]::new); assertOrderedEquals(orderedMethods, expectedOrder); }