void () { ChangedFilesStructure fs = new ChangedFilesStructure(myWorkingDirectory); String initialFile = "initial file"; PsiFile toModify = fs.createFile("Modified.txt", initialFile, initialFile + " + unused import"); PsiFile toModify2 = fs.createFile("Modified2.txt", initialFile, initialFile + " + another unused import"); PsiFile toKeep = fs.createFile("NonModified.txt", initialFile, initialFile); PsiFile toKeep2 = fs.createFile("NonModified2.txt", initialFile, initialFile); OptimizeImportsAction optimizeImports = new OptimizeImportsAction(); OptimizeImportsAction.setProcessVcsChangedFilesInTests(true); try { optimizeImports.actionPerformed(TestActionEvent.createTestEvent(dataId -> { if (CommonDataKeys.PROJECT.is(dataId)) { return getProject(); } if (LangDataKeys.MODULE_CONTEXT.is(dataId)) { return getModule(); } return null; })); } finally { OptimizeImportsAction.setProcessVcsChangedFilesInTests(false); } assertTrue(isImportsOptimized(toModify)); assertTrue(isImportsOptimized(toModify2)); assertFalse(isImportsOptimized(toKeep)); assertFalse(isImportsOptimized(toKeep2)); }