mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
couple of tests moved to community
This commit is contained in:
@@ -0,0 +1,50 @@
|
||||
/*
|
||||
* Copyright (c) 2000-2005 by JetBrains s.r.o. All Rights Reserved.
|
||||
* Use is subject to license terms.
|
||||
*/
|
||||
package com.intellij.psi.util.proximity;
|
||||
|
||||
import com.intellij.openapi.application.Result;
|
||||
import com.intellij.openapi.command.WriteCommandAction;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.testFramework.PsiTestUtil;
|
||||
import com.intellij.testFramework.fixtures.IdeaTestFixtureFactory;
|
||||
import com.intellij.testFramework.fixtures.JavaCodeInsightFixtureTestCase;
|
||||
import com.intellij.testFramework.fixtures.TempDirTestFixture;
|
||||
|
||||
/**
|
||||
* @author peter
|
||||
*/
|
||||
public class ProximityTest extends JavaCodeInsightFixtureTestCase {
|
||||
|
||||
public void testSameSourceRoot() throws Throwable {
|
||||
final TempDirTestFixture root1 = IdeaTestFixtureFactory.getFixtureFactory().createTempDirTestFixture();
|
||||
final TempDirTestFixture root2 = IdeaTestFixtureFactory.getFixtureFactory().createTempDirTestFixture();
|
||||
|
||||
root1.setUp();
|
||||
root2.setUp();
|
||||
|
||||
try {
|
||||
new WriteCommandAction(getProject()) {
|
||||
@Override
|
||||
protected void run(Result result) throws Throwable {
|
||||
PsiTestUtil.addSourceContentToRoots(myModule, root1.getFile(""));
|
||||
PsiTestUtil.addSourceContentToRoots(myModule, root2.getFile(""));
|
||||
}
|
||||
}.execute();
|
||||
|
||||
final VirtualFile file1 = root1.createFile("buy.txt", "");
|
||||
final VirtualFile file2 = root2.createFile("buy.txt", "");
|
||||
final VirtualFile ctx = root2.createFile("ctx.txt", "");
|
||||
|
||||
final PsiProximityComparator comparator = new PsiProximityComparator(getPsiManager().findFile(ctx));
|
||||
assertTrue(comparator.compare(getPsiManager().findFile(file1), getPsiManager().findFile(file2)) > 0);
|
||||
assertTrue(comparator.compare(getPsiManager().findFile(file2), getPsiManager().findFile(file1)) < 0);
|
||||
}
|
||||
finally {
|
||||
root1.tearDown();
|
||||
root2.tearDown();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
/*
|
||||
* Copyright (c) 2000-2005 by JetBrains s.r.o. All Rights Reserved.
|
||||
* Use is subject to license terms.
|
||||
*/
|
||||
package com.intellij.statistics;
|
||||
|
||||
import com.intellij.psi.statistics.StatisticsInfo;
|
||||
import com.intellij.psi.statistics.StatisticsManager;
|
||||
import com.intellij.psi.statistics.impl.StatisticsManagerImpl;
|
||||
import com.intellij.testFramework.LightPlatformTestCase;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
|
||||
/**
|
||||
* @author peter
|
||||
*/
|
||||
public class StatisticsManagerTest extends LightPlatformTestCase {
|
||||
@NonNls private static final String TEST_CONTEXT = "testContext";
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
((StatisticsManagerImpl)StatisticsManager.getInstance()).clearStatistics();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void tearDown() throws Exception {
|
||||
((StatisticsManagerImpl)StatisticsManager.getInstance()).clearStatistics();
|
||||
super.tearDown();
|
||||
}
|
||||
|
||||
private void incUseCount(String value, int times) {
|
||||
for (int i = 0; i < times; i++) {
|
||||
StatisticsManager.getInstance().incUseCount(new StatisticsInfo(TEST_CONTEXT, value));
|
||||
}
|
||||
}
|
||||
|
||||
private int getUseCount(String value) {
|
||||
return StatisticsManager.getInstance().getUseCount(new StatisticsInfo(TEST_CONTEXT, value));
|
||||
}
|
||||
|
||||
public void testIncUseCount() throws Throwable {
|
||||
incUseCount("b", 1);
|
||||
assertEquals(1, getUseCount("b"));
|
||||
assertEquals(0, getUseCount("c"));
|
||||
|
||||
incUseCount("c", 1);
|
||||
assertEquals(1, getUseCount("b"));
|
||||
assertEquals(1, getUseCount("c"));
|
||||
}
|
||||
|
||||
public void testFlexibility() throws Throwable {
|
||||
incUseCount("b", 100);
|
||||
incUseCount("c", 4);
|
||||
assertTrue(getUseCount("c") > getUseCount("b"));
|
||||
}
|
||||
|
||||
public void testReturn() throws Throwable {
|
||||
incUseCount("b", 100);
|
||||
incUseCount("c", 4);
|
||||
incUseCount("b", 1);
|
||||
assertTrue(getUseCount("c") >= getUseCount("b"));
|
||||
incUseCount("b", 3);
|
||||
assertTrue(getUseCount("c") < getUseCount("b"));
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user