From af0be0eae1092f6d720226c0c6b7f8af2f0035cc Mon Sep 17 00:00:00 2001 From: peter Date: Tue, 7 Feb 2012 15:23:55 +0100 Subject: [PATCH] don't redefine application in PathMacroManagerTest --- .../impl/ModulePathMacroManager.java | 4 ++- .../impl/ApplicationPathMacroManager.java | 3 ++ .../components/impl/BasePathMacroManager.java | 6 ++++ .../impl/ProjectPathMacroManager.java | 7 +++-- .../components/impl/PathMacroManagerTest.java | 29 +++++++------------ 5 files changed, 27 insertions(+), 22 deletions(-) diff --git a/platform/lang-impl/src/com/intellij/openapi/components/impl/ModulePathMacroManager.java b/platform/lang-impl/src/com/intellij/openapi/components/impl/ModulePathMacroManager.java index 693ebd26d06a..8136ae66517c 100644 --- a/platform/lang-impl/src/com/intellij/openapi/components/impl/ModulePathMacroManager.java +++ b/platform/lang-impl/src/com/intellij/openapi/components/impl/ModulePathMacroManager.java @@ -18,6 +18,7 @@ package com.intellij.openapi.components.impl; import com.intellij.application.options.PathMacrosImpl; import com.intellij.application.options.ReplacePathToMacroMap; +import com.intellij.openapi.application.PathMacros; import com.intellij.openapi.components.ExpandMacroToPathMap; import com.intellij.openapi.components.PathMacroMap; import com.intellij.openapi.module.Module; @@ -29,7 +30,8 @@ import java.io.File; public class ModulePathMacroManager extends BasePathMacroManager { private final Module myModule; - public ModulePathMacroManager(final Module module) { + public ModulePathMacroManager(PathMacros pathMacros, Module module) { + super(pathMacros); myModule = module; } diff --git a/platform/platform-impl/src/com/intellij/openapi/components/impl/ApplicationPathMacroManager.java b/platform/platform-impl/src/com/intellij/openapi/components/impl/ApplicationPathMacroManager.java index 134708f38230..1a93f02aff2f 100644 --- a/platform/platform-impl/src/com/intellij/openapi/components/impl/ApplicationPathMacroManager.java +++ b/platform/platform-impl/src/com/intellij/openapi/components/impl/ApplicationPathMacroManager.java @@ -19,4 +19,7 @@ package com.intellij.openapi.components.impl; * @author mike */ public class ApplicationPathMacroManager extends BasePathMacroManager { + public ApplicationPathMacroManager() { + super(null); + } } diff --git a/platform/platform-impl/src/com/intellij/openapi/components/impl/BasePathMacroManager.java b/platform/platform-impl/src/com/intellij/openapi/components/impl/BasePathMacroManager.java index c2bd7334b432..cb0c74515555 100644 --- a/platform/platform-impl/src/com/intellij/openapi/components/impl/BasePathMacroManager.java +++ b/platform/platform-impl/src/com/intellij/openapi/components/impl/BasePathMacroManager.java @@ -17,6 +17,7 @@ package com.intellij.openapi.components.impl; import com.intellij.application.options.PathMacrosImpl; import com.intellij.application.options.ReplacePathToMacroMap; +import com.intellij.openapi.application.PathMacros; import com.intellij.openapi.components.ExpandMacroToPathMap; import com.intellij.openapi.components.PathMacroManager; import com.intellij.openapi.components.PathMacroMap; @@ -34,6 +35,11 @@ import java.util.*; public class BasePathMacroManager extends PathMacroManager { private PathMacrosImpl myPathMacros; + + public BasePathMacroManager(@Nullable PathMacros pathMacros) { + myPathMacros = (PathMacrosImpl)pathMacros; + } + protected static void addFileHierarchyReplacements(ReplacePathToMacroMap result, String variableName, @Nullable String _path, @Nullable String stopAt) { diff --git a/platform/platform-impl/src/com/intellij/openapi/components/impl/ProjectPathMacroManager.java b/platform/platform-impl/src/com/intellij/openapi/components/impl/ProjectPathMacroManager.java index 1c9f79824353..e5ea2c207571 100644 --- a/platform/platform-impl/src/com/intellij/openapi/components/impl/ProjectPathMacroManager.java +++ b/platform/platform-impl/src/com/intellij/openapi/components/impl/ProjectPathMacroManager.java @@ -17,10 +17,10 @@ package com.intellij.openapi.components.impl; import com.intellij.application.options.PathMacrosImpl; import com.intellij.application.options.ReplacePathToMacroMap; +import com.intellij.openapi.application.PathMacros; import com.intellij.openapi.components.ExpandMacroToPathMap; import com.intellij.openapi.components.PathMacroMap; import com.intellij.openapi.project.Project; -import com.intellij.openapi.project.ex.ProjectEx; import com.intellij.openapi.util.text.StringUtil; import com.intellij.openapi.vfs.VirtualFile; import org.jetbrains.annotations.Nullable; @@ -28,9 +28,10 @@ import org.jetbrains.annotations.Nullable; import java.io.File; public class ProjectPathMacroManager extends BasePathMacroManager { - private final ProjectEx myProject; + private final Project myProject; - public ProjectPathMacroManager(final ProjectEx project) { + public ProjectPathMacroManager(PathMacros pathMacros, Project project) { + super(pathMacros); myProject = project; } diff --git a/platform/platform-tests/testSrc/com/intellij/openapi/components/impl/PathMacroManagerTest.java b/platform/platform-tests/testSrc/com/intellij/openapi/components/impl/PathMacroManagerTest.java index 47e6857aeabb..4d7ee34cd7d1 100644 --- a/platform/platform-tests/testSrc/com/intellij/openapi/components/impl/PathMacroManagerTest.java +++ b/platform/platform-tests/testSrc/com/intellij/openapi/components/impl/PathMacroManagerTest.java @@ -3,15 +3,12 @@ package com.intellij.openapi.components.impl; import com.intellij.application.options.PathMacrosImpl; import com.intellij.application.options.ReplacePathToMacroMap; import com.intellij.mock.MockFileSystem; -import com.intellij.openapi.Disposable; -import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.application.ModalityState; import com.intellij.openapi.application.PathMacros; import com.intellij.openapi.application.PathManager; import com.intellij.openapi.application.ex.ApplicationEx; import com.intellij.openapi.module.Module; import com.intellij.openapi.project.ex.ProjectEx; -import com.intellij.openapi.util.Disposer; import com.intellij.openapi.util.SystemInfo; import com.intellij.openapi.util.text.StringUtil; import com.intellij.openapi.vfs.VirtualFile; @@ -19,6 +16,7 @@ import com.intellij.util.SystemProperties; import com.intellij.util.io.fs.FileSystem; import com.intellij.util.io.fs.IFileSystem; import org.hamcrest.Description; +import org.jetbrains.annotations.Nullable; import org.jmock.Expectations; import org.jmock.Mockery; import org.jmock.api.Action; @@ -57,7 +55,6 @@ public class PathMacroManagerTest { private IFileSystem myOldFileSystem; protected MockFileSystem myFileSystem; protected PicoContainer myAppPico; - private Disposable myDisposable = Disposer.newDisposable(); @Before public final void setupApplication() throws Exception { @@ -66,9 +63,12 @@ public class PathMacroManagerTest { context.checking(new Expectations() { { - allowing(myApplication).isUnitTestMode(); will(returnValue(false)); - allowing(myApplication).getName(); will(returnValue("IDEA")); - allowing(myApplication).getPicoContainer(); will(returnValue(myAppPico)); + allowing(myApplication).isUnitTestMode(); + will(returnValue(false)); + allowing(myApplication).getName(); + will(returnValue("IDEA")); + allowing(myApplication).getPicoContainer(); + will(returnValue(myAppPico)); //some tests leave invokeLaters after them... allowing(myApplication).invokeLater(with(any(Runnable.class)), with(any(ModalityState.class))); @@ -81,6 +81,7 @@ public class PathMacroManagerTest { } @Override + @Nullable public Object invoke(final Invocation invocation) throws Throwable { ((Runnable)invocation.getParameter(0)).run(); return null; @@ -88,8 +89,6 @@ public class PathMacroManagerTest { }); } }); - - ApplicationManager.setApplication(myApplication, myDisposable); } @Before @@ -99,12 +98,6 @@ public class PathMacroManagerTest { FileSystem.FILE_SYSTEM = myFileSystem; } - @After - public final void restoreApplication() throws Exception { - Disposer.dispose(myDisposable); - myDisposable = null; - } - @After public final void restoreFilesystem() throws Exception { FileSystem.FILE_SYSTEM = myOldFileSystem; @@ -145,7 +138,7 @@ public class PathMacroManagerTest { setUpMocks("/tmp/foo"); - final ReplacePathToMacroMap replacePathMap = new ModulePathMacroManager(myModule).getReplacePathMap(); + final ReplacePathToMacroMap replacePathMap = new ModulePathMacroManager(myPathMacros, myModule).getReplacePathMap(); final String s = mapToString(replacePathMap); assertEquals("file:/tmp/foo/module -> file:$MODULE_DIR$\n" + "file://tmp/foo/module -> file:/$MODULE_DIR$\n" + @@ -190,7 +183,7 @@ public class PathMacroManagerTest { setUpMocks("/tmp/foo"); - final ReplacePathToMacroMap replacePathMap = new ProjectPathMacroManager(myProject).getReplacePathMap(); + final ReplacePathToMacroMap replacePathMap = new ProjectPathMacroManager(myPathMacros, myProject).getReplacePathMap(); final String s = mapToString(replacePathMap); assertEquals("file:/tmp/foo -> file:$PROJECT_DIR$\n" + "file://tmp/foo -> file:/$PROJECT_DIR$\n" + @@ -228,7 +221,7 @@ public class PathMacroManagerTest { setUpMocks(USER_HOME + "/IdeaProjects/foo"); - final ReplacePathToMacroMap replacePathMap = new ModulePathMacroManager(myModule).getReplacePathMap(); + final ReplacePathToMacroMap replacePathMap = new ModulePathMacroManager(myPathMacros, myModule).getReplacePathMap(); final String s = mapToString(replacePathMap); assertEquals("file:" + USER_HOME + "/IdeaProjects/foo/module -> file:$MODULE_DIR$\n" + "file:/" + USER_HOME + "/IdeaProjects/foo/module -> file:/$MODULE_DIR$\n" +