void () { final String className = "Foo"; myFixture.addClass("class " + className + " {}"); final GlobalSearchScope scope = GlobalSearchScope.allScope(getProject()); final List<Boolean> foundClassProcessAll = new ArrayList<>(Arrays.asList(false)); final List<Boolean> foundClassStub = new ArrayList<>(Arrays.asList(false)); try { StubIndex.getInstance().processAllKeys(JavaStubIndexKeys.CLASS_SHORT_NAMES, getProject(), aClass -> { if (!className.equals(aClass)) return true; foundClassProcessAll.set(0, true); // adding file will add file to index's dirty set, but it should not be processed within current read action myFixture.addFileToProject("Bar.java", "class Bar { }"); StubIndex.getInstance() .processElements(JavaStubIndexKeys.CLASS_SHORT_NAMES, aClass, getProject(), scope, PsiClass.class, clazz -> { foundClassStub.set(0, true); return true; }); return true; }); } catch (Exception e) { if (!(e instanceof RuntimeException)) throw e; } assertTrue(foundClassProcessAll.get(0)); assertTrue(foundClassStub.get(0));// allow access stub index processing other index }