void (@NotNull FileType fileType, @NotNull String newExtension) { FileType oldFileType = myFileTypeManager.getFileTypeByExtension(newExtension); try { DefaultLogger.disableStderrDumping(getTestRootDisposable()); myFileTypeManager.getRegisteredFileTypes(); // ensure pending file types empty assertNotSame(FileTypes.UNKNOWN, oldFileType); WriteAction.run(() -> myFileTypeManager.removeAssociatedExtension(fileType, newExtension)); WriteAction.run(() -> myFileTypeManager.getRemovedMappingTracker().add(new ExtensionFileNameMatcher(newExtension), oldFileType.getName(), true)); WriteAction.run(() -> myFileTypeManager.associateExtension(fileType, newExtension)); assertEquals(fileType, myFileTypeManager.getFileTypeByFileName("foo." + newExtension)); } finally { WriteAction.run(() -> { myFileTypeManager.removeAssociatedExtension(fileType, newExtension); myFileTypeManager.getRemovedMappingTracker().removeIf(mapping -> mapping.getFileTypeName().equals(oldFileType.getName()) && mapping.getFileNameMatcher() instanceof ExtensionFileNameMatcher && ((ExtensionFileNameMatcher)mapping.getFileNameMatcher()).getExtension().equals(newExtension)); myFileTypeManager.associateExtension(oldFileType, newExtension); }); } assertEquals(oldFileType, myFileTypeManager.getFileTypeByFileName("foo." + newExtension)); }