summaryrefslogtreecommitdiff
path: root/platform/testFramework
diff options
context:
space:
mode:
Diffstat (limited to 'platform/testFramework')
-rw-r--r--platform/testFramework/src/com/intellij/mock/Mock.java2
-rw-r--r--platform/testFramework/src/com/intellij/mock/MockVirtualFileSystem.java21
-rw-r--r--platform/testFramework/src/com/intellij/testFramework/FlyIdeaTestCase.java35
-rw-r--r--platform/testFramework/src/com/intellij/testFramework/PlatformTestUtil.java3
-rw-r--r--platform/testFramework/src/com/intellij/testFramework/TestActionEvent.java9
-rw-r--r--platform/testFramework/src/com/intellij/testFramework/UsefulTestCase.java12
-rw-r--r--platform/testFramework/src/com/intellij/testFramework/fixtures/IdeaTestFixtureFactory.java2
-rw-r--r--platform/testFramework/src/com/intellij/testFramework/fixtures/TestFixtureBuilder.java2
-rw-r--r--platform/testFramework/src/com/intellij/testFramework/fixtures/impl/CodeInsightTestFixtureImpl.java12
-rw-r--r--platform/testFramework/src/com/intellij/testFramework/fixtures/impl/HeavyTestFixtureBuilderImpl.java2
-rw-r--r--platform/testFramework/src/com/intellij/testFramework/fixtures/impl/IdeaTestFixtureFactoryImpl.java1
-rw-r--r--platform/testFramework/src/com/intellij/testFramework/fixtures/impl/LightTestFixtureBuilderImpl.java2
-rw-r--r--platform/testFramework/testFramework.iml2
13 files changed, 62 insertions, 43 deletions
diff --git a/platform/testFramework/src/com/intellij/mock/Mock.java b/platform/testFramework/src/com/intellij/mock/Mock.java
index 73d6538c52b9..a2768f2e1851 100644
--- a/platform/testFramework/src/com/intellij/mock/Mock.java
+++ b/platform/testFramework/src/com/intellij/mock/Mock.java
@@ -435,7 +435,7 @@ public class Mock {
}
@Override
- public void setSelectedEditor(@NotNull VirtualFile file, String fileEditorProviderId) {
+ public void setSelectedEditor(@NotNull VirtualFile file, @NotNull String fileEditorProviderId) {
}
}
diff --git a/platform/testFramework/src/com/intellij/mock/MockVirtualFileSystem.java b/platform/testFramework/src/com/intellij/mock/MockVirtualFileSystem.java
index 8550f973a8ea..9854cea82835 100644
--- a/platform/testFramework/src/com/intellij/mock/MockVirtualFileSystem.java
+++ b/platform/testFramework/src/com/intellij/mock/MockVirtualFileSystem.java
@@ -20,30 +20,37 @@ import com.intellij.openapi.vfs.DeprecatedVirtualFileSystem;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.openapi.vfs.VirtualFileSystem;
import com.intellij.testFramework.LightVirtualFile;
+import gnu.trove.THashMap;
import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
import java.io.File;
import java.io.IOException;
import java.util.Collection;
-import java.util.HashMap;
+import java.util.Map;
public class MockVirtualFileSystem extends DeprecatedVirtualFileSystem {
private final MyVirtualFile myRoot = new MyVirtualFile("", null);
public static final String PROTOCOL = "mock";
@Override
+ @NotNull
public VirtualFile findFileByPath(@NotNull String path) {
path = path.replace(File.separatorChar, '/');
path = path.replace('/', ':');
if (StringUtil.startsWithChar(path, ':')) path = path.substring(1);
- String[] components = path.split(":");
MyVirtualFile file = myRoot;
- for (String component : components) {
+ for (String component : StringUtil.split(path, ":")) {
file = file.getOrCreate(component);
}
return file;
}
+ @NotNull
+ public VirtualFile getRoot() {
+ return myRoot;
+ }
+
@Override
@NotNull
public String getProtocol() {
@@ -93,11 +100,12 @@ public class MockVirtualFileSystem extends DeprecatedVirtualFileSystem {
}
public class MyVirtualFile extends LightVirtualFile {
- private final HashMap<String, MyVirtualFile> myChildren = new HashMap<String, MyVirtualFile>();
+ private final Map<String, MyVirtualFile> myChildren = new THashMap<String, MyVirtualFile>();
private final MyVirtualFile myParent;
- public MyVirtualFile(String name, MyVirtualFile parent) {
+ public MyVirtualFile(@NotNull String name, @Nullable MyVirtualFile parent) {
super(name);
+
myParent = parent;
}
@@ -107,7 +115,8 @@ public class MockVirtualFileSystem extends DeprecatedVirtualFileSystem {
return MockVirtualFileSystem.this;
}
- public MyVirtualFile getOrCreate(String name) {
+ @NotNull
+ public MyVirtualFile getOrCreate(@NotNull String name) {
MyVirtualFile file = myChildren.get(name);
if (file == null) {
file = new MyVirtualFile(name, this);
diff --git a/platform/testFramework/src/com/intellij/testFramework/FlyIdeaTestCase.java b/platform/testFramework/src/com/intellij/testFramework/FlyIdeaTestCase.java
index 02a39f148e24..098d76599f5b 100644
--- a/platform/testFramework/src/com/intellij/testFramework/FlyIdeaTestCase.java
+++ b/platform/testFramework/src/com/intellij/testFramework/FlyIdeaTestCase.java
@@ -1,36 +1,35 @@
+/*
+ * Copyright 2000-2014 JetBrains s.r.o.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
package com.intellij.testFramework;
-import com.intellij.mock.MockApplicationEx;
import com.intellij.openapi.Disposable;
-import com.intellij.openapi.application.Application;
-import com.intellij.openapi.application.ApplicationManager;
-import com.intellij.openapi.application.ex.ApplicationManagerEx;
import com.intellij.openapi.util.Disposer;
import com.intellij.openapi.util.io.FileUtil;
import junit.framework.TestCase;
-import org.jetbrains.annotations.NotNull;
import java.io.File;
import java.io.IOException;
-import java.util.concurrent.Future;
public abstract class FlyIdeaTestCase extends TestCase {
-
- private Disposable myRootDisposable;
+ private final Disposable myRootDisposable = Disposer.newDisposable();
private File myTempDir;
@Override
protected void setUp() throws Exception {
- final Application old = ApplicationManagerEx.getApplication();
- myRootDisposable = Disposer.newDisposable();
- MockApplicationEx app = new MockApplicationEx(getRootDisposable()) {
- @NotNull
- @Override
- public Future<?> executeOnPooledThread(@NotNull Runnable action) {
- return old != null ? old.executeOnPooledThread(action) : super.executeOnPooledThread(action);
- }
- };
- ApplicationManager.setApplication(app, myRootDisposable);
+ LightPlatformTestCase.initApplication();
}
public File getTempDir() throws IOException {
diff --git a/platform/testFramework/src/com/intellij/testFramework/PlatformTestUtil.java b/platform/testFramework/src/com/intellij/testFramework/PlatformTestUtil.java
index ee6e519cb583..fcf0e225ea5f 100644
--- a/platform/testFramework/src/com/intellij/testFramework/PlatformTestUtil.java
+++ b/platform/testFramework/src/com/intellij/testFramework/PlatformTestUtil.java
@@ -413,7 +413,8 @@ public class PlatformTestUtil {
for (int i= n /2- n / part /2; i< n /2+ n / part /2; i++) {
total += time[i];
}
- return total/(n / part);
+ int middlePartLength = n / part;
+ return middlePartLength == 0 ? 0 : total / middlePartLength;
}
public static boolean canRunTest(@NotNull Class testCaseClass) {
diff --git a/platform/testFramework/src/com/intellij/testFramework/TestActionEvent.java b/platform/testFramework/src/com/intellij/testFramework/TestActionEvent.java
index 764e80453ad6..0f5ab8b3c8ae 100644
--- a/platform/testFramework/src/com/intellij/testFramework/TestActionEvent.java
+++ b/platform/testFramework/src/com/intellij/testFramework/TestActionEvent.java
@@ -16,10 +16,7 @@
package com.intellij.testFramework;
import com.intellij.ide.DataManager;
-import com.intellij.openapi.actionSystem.ActionManager;
-import com.intellij.openapi.actionSystem.AnAction;
-import com.intellij.openapi.actionSystem.AnActionEvent;
-import com.intellij.openapi.actionSystem.DataContext;
+import com.intellij.openapi.actionSystem.*;
import org.jetbrains.annotations.NotNull;
/**
@@ -35,4 +32,8 @@ public class TestActionEvent extends AnActionEvent {
public TestActionEvent(@NotNull AnAction action) {
this(DataManager.getInstance().getDataContext(), action);
}
+
+ public TestActionEvent() {
+ super(null, DataManager.getInstance().getDataContext(), "", new Presentation(), ActionManager.getInstance(), 0);
+ }
}
diff --git a/platform/testFramework/src/com/intellij/testFramework/UsefulTestCase.java b/platform/testFramework/src/com/intellij/testFramework/UsefulTestCase.java
index 6deda3d4b70a..6f03fd02446e 100644
--- a/platform/testFramework/src/com/intellij/testFramework/UsefulTestCase.java
+++ b/platform/testFramework/src/com/intellij/testFramework/UsefulTestCase.java
@@ -224,7 +224,7 @@ public abstract class UsefulTestCase extends TestCase {
}
public static CompositeException doCheckForSettingsDamage(@NotNull CodeStyleSettings oldCodeStyleSettings,
- @NotNull CodeStyleSettings currentCodeStyleSettings) throws Exception {
+ @NotNull CodeStyleSettings currentCodeStyleSettings) throws Exception {
CompositeException result = new CompositeException();
final CodeInsightSettings settings = CodeInsightSettings.getInstance();
try {
@@ -234,9 +234,13 @@ public abstract class UsefulTestCase extends TestCase {
}
catch (AssertionError error) {
CodeInsightSettings clean = new CodeInsightSettings();
- Element temp = new Element("temp");
- clean.writeExternal(temp);
- settings.loadState(temp);
+ for (Field field : clean.getClass().getFields()) {
+ try {
+ ReflectionUtil.copyFieldValue(clean, settings, field);
+ }
+ catch (Exception ignored) {
+ }
+ }
result.add(error);
}
diff --git a/platform/testFramework/src/com/intellij/testFramework/fixtures/IdeaTestFixtureFactory.java b/platform/testFramework/src/com/intellij/testFramework/fixtures/IdeaTestFixtureFactory.java
index 010caad8fcd2..ecc5bff4dc50 100644
--- a/platform/testFramework/src/com/intellij/testFramework/fixtures/IdeaTestFixtureFactory.java
+++ b/platform/testFramework/src/com/intellij/testFramework/fixtures/IdeaTestFixtureFactory.java
@@ -37,6 +37,7 @@ public abstract class IdeaTestFixtureFactory {
}
}
+ @NotNull
public static IdeaTestFixtureFactory getFixtureFactory() {
return ourInstance;
}
@@ -59,6 +60,7 @@ public abstract class IdeaTestFixtureFactory {
public abstract TestFixtureBuilder<IdeaProjectTestFixture> createFixtureBuilder(@NotNull String name);
+ @NotNull
public abstract TestFixtureBuilder<IdeaProjectTestFixture> createLightFixtureBuilder();
public abstract TestFixtureBuilder<IdeaProjectTestFixture> createLightFixtureBuilder(@Nullable LightProjectDescriptor projectDescriptor);
diff --git a/platform/testFramework/src/com/intellij/testFramework/fixtures/TestFixtureBuilder.java b/platform/testFramework/src/com/intellij/testFramework/fixtures/TestFixtureBuilder.java
index b275ec521c8c..1d0e648611ef 100644
--- a/platform/testFramework/src/com/intellij/testFramework/fixtures/TestFixtureBuilder.java
+++ b/platform/testFramework/src/com/intellij/testFramework/fixtures/TestFixtureBuilder.java
@@ -17,11 +17,13 @@
package com.intellij.testFramework.fixtures;
import com.intellij.testFramework.builders.ModuleFixtureBuilder;
+import org.jetbrains.annotations.NotNull;
/**
* @author mike
*/
public interface TestFixtureBuilder<T extends IdeaTestFixture> {
+ @NotNull
T getFixture();
<M extends ModuleFixtureBuilder> M addModule(Class<M> builderClass);
diff --git a/platform/testFramework/src/com/intellij/testFramework/fixtures/impl/CodeInsightTestFixtureImpl.java b/platform/testFramework/src/com/intellij/testFramework/fixtures/impl/CodeInsightTestFixtureImpl.java
index 8aafb17da1de..f4264f760cd9 100644
--- a/platform/testFramework/src/com/intellij/testFramework/fixtures/impl/CodeInsightTestFixtureImpl.java
+++ b/platform/testFramework/src/com/intellij/testFramework/fixtures/impl/CodeInsightTestFixtureImpl.java
@@ -185,7 +185,7 @@ public class CodeInsightTestFixtureImpl extends BaseFixture implements CodeInsig
}
VirtualFile result;
- final String path = fromFile.getPath();
+ final String path = fromFile.getAbsolutePath();
if (myTempDirFixture instanceof LightTempDirTestFixtureImpl) {
VfsRootAccess.allowRootAccess(path);
Disposer.register(myTestRootDisposable, new Disposable() {
@@ -1025,13 +1025,9 @@ public class CodeInsightTestFixtureImpl extends BaseFixture implements CodeInsig
final CodeCompletionHandlerBase handler = new CodeCompletionHandlerBase(type) {
@Override
- protected void completionFinished(int offset1,
- int offset2,
- CompletionProgressIndicator indicator,
- LookupElement[] items,
- boolean hasModifiers) {
- myEmptyLookup = items.length == 0;
- super.completionFinished(offset1, offset2, indicator, items, hasModifiers);
+ protected void completionFinished(CompletionProgressIndicator indicator, boolean hasModifiers) {
+ myEmptyLookup = indicator.getLookup().getItems().isEmpty();
+ super.completionFinished(indicator, hasModifiers);
}
};
Editor editor = getCompletionEditor();
diff --git a/platform/testFramework/src/com/intellij/testFramework/fixtures/impl/HeavyTestFixtureBuilderImpl.java b/platform/testFramework/src/com/intellij/testFramework/fixtures/impl/HeavyTestFixtureBuilderImpl.java
index c7b7779fe92a..412c87ee5bce 100644
--- a/platform/testFramework/src/com/intellij/testFramework/fixtures/impl/HeavyTestFixtureBuilderImpl.java
+++ b/platform/testFramework/src/com/intellij/testFramework/fixtures/impl/HeavyTestFixtureBuilderImpl.java
@@ -22,6 +22,7 @@ import com.intellij.testFramework.fixtures.IdeaProjectTestFixture;
import com.intellij.testFramework.fixtures.TestFixtureBuilder;
import com.intellij.util.pico.ConstructorInjectionComponentAdapter;
import com.intellij.util.pico.IdeaPicoContainer;
+import org.jetbrains.annotations.NotNull;
import org.picocontainer.MutablePicoContainer;
import java.lang.reflect.Field;
@@ -50,6 +51,7 @@ class HeavyTestFixtureBuilderImpl implements TestFixtureBuilder<IdeaProjectTestF
return (M)adapter.getComponentInstance(myContainer);
}
+ @NotNull
@Override
public HeavyIdeaTestFixture getFixture() {
return myFixture;
diff --git a/platform/testFramework/src/com/intellij/testFramework/fixtures/impl/IdeaTestFixtureFactoryImpl.java b/platform/testFramework/src/com/intellij/testFramework/fixtures/impl/IdeaTestFixtureFactoryImpl.java
index ce73993b60a7..1b375d401d0e 100644
--- a/platform/testFramework/src/com/intellij/testFramework/fixtures/impl/IdeaTestFixtureFactoryImpl.java
+++ b/platform/testFramework/src/com/intellij/testFramework/fixtures/impl/IdeaTestFixtureFactoryImpl.java
@@ -62,6 +62,7 @@ public class IdeaTestFixtureFactoryImpl extends IdeaTestFixtureFactory {
return new HeavyTestFixtureBuilderImpl(new HeavyIdeaTestFixtureImpl(name), myFixtureBuilderProviders);
}
+ @NotNull
@Override
public TestFixtureBuilder<IdeaProjectTestFixture> createLightFixtureBuilder() {
return new LightTestFixtureBuilderImpl<IdeaProjectTestFixture>(new LightIdeaTestFixtureImpl(
diff --git a/platform/testFramework/src/com/intellij/testFramework/fixtures/impl/LightTestFixtureBuilderImpl.java b/platform/testFramework/src/com/intellij/testFramework/fixtures/impl/LightTestFixtureBuilderImpl.java
index 43a2ee7c031c..a196e4211649 100644
--- a/platform/testFramework/src/com/intellij/testFramework/fixtures/impl/LightTestFixtureBuilderImpl.java
+++ b/platform/testFramework/src/com/intellij/testFramework/fixtures/impl/LightTestFixtureBuilderImpl.java
@@ -19,6 +19,7 @@ package com.intellij.testFramework.fixtures.impl;
import com.intellij.testFramework.builders.ModuleFixtureBuilder;
import com.intellij.testFramework.fixtures.IdeaProjectTestFixture;
import com.intellij.testFramework.fixtures.TestFixtureBuilder;
+import org.jetbrains.annotations.NotNull;
/**
* @author mike
@@ -31,6 +32,7 @@ class LightTestFixtureBuilderImpl<F extends IdeaProjectTestFixture> implements T
myFixture = fixture;
}
+ @NotNull
@Override
public F getFixture() {
return myFixture;
diff --git a/platform/testFramework/testFramework.iml b/platform/testFramework/testFramework.iml
index 7985252e6abc..19a4097b1f15 100644
--- a/platform/testFramework/testFramework.iml
+++ b/platform/testFramework/testFramework.iml
@@ -20,7 +20,7 @@
<orderEntry type="library" exported="" scope="TEST" name="Mocks" level="project" />
<orderEntry type="module" module-name="java-runtime" exported="" />
<orderEntry type="module" module-name="vcs-impl" />
- <orderEntry type="library" name="Groovy" level="project" />
+ <orderEntry type="library" exported="" name="Groovy" level="project" />
<orderEntry type="module" module-name="platform-resources" exported="" scope="RUNTIME" />
<orderEntry type="module" module-name="dom-impl" exported="" scope="RUNTIME" />
<orderEntry type="module" module-name="relaxng" exported="" scope="RUNTIME" />