本文整理汇总了Java中com.intellij.testFramework.IdeaTestUtil类的典型用法代码示例。如果您正苦于以下问题:Java IdeaTestUtil类的具体用法?Java IdeaTestUtil怎么用?Java IdeaTestUtil使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
IdeaTestUtil类属于com.intellij.testFramework包,在下文中一共展示了IdeaTestUtil类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: doTest
import com.intellij.testFramework.IdeaTestUtil; //导入依赖的package包/类
private void doTest(String className, String methodName) throws Exception {
String rootBefore = getRoot() + "/before";
PsiTestUtil.removeAllRoots(myModule, IdeaTestUtil.getMockJdk17());
final VirtualFile rootDir = PsiTestUtil.createTestProjectStructure(myProject, myModule, rootBefore, myFilesToDelete);
PsiClass aClass = myJavaFacade.findClass(className, ProjectScope.getAllScope(myProject));
assertTrue(aClass != null);
PsiElement element = aClass.findMethodsByName(methodName, false)[0];
assertTrue(element instanceof PsiMethod);
PsiMethod method = (PsiMethod)element;
final boolean condition = InlineMethodProcessor.checkBadReturns(method) && !InlineUtil.allUsagesAreTailCalls(method);
assertFalse("Bad returns found", condition);
InlineOptions options = new MockInlineMethodOptions();
final InlineMethodProcessor processor = new InlineMethodProcessor(getProject(), method, null, myEditor, options.isInlineThisOnly());
processor.run();
String rootAfter = getRoot() + "/after";
VirtualFile rootDir2 = LocalFileSystem.getInstance().findFileByPath(rootAfter.replace(File.separatorChar, '/'));
myProject.getComponent(PostprocessReformattingAspect.class).doPostponedFormatting();
PlatformTestUtil.assertDirectoriesEqual(rootDir2, rootDir);
}
示例2: testMultipleFiles
import com.intellij.testFramework.IdeaTestUtil; //导入依赖的package包/类
public void testMultipleFiles() throws Exception {
String rootBefore = getRoot();
PsiTestUtil.removeAllRoots(myModule, IdeaTestUtil.getMockJdk17());
final VirtualFile root = PsiTestUtil.createTestProjectStructure(myProject, myModule, rootBefore, myFilesToDelete);
final VirtualFile first = root.findFileByRelativePath("from/1.txt");
assertNotNull(first);
final VirtualFile second = root.findFileByRelativePath("from/2.txt");
assertNotNull(second);
final PsiFile firstPsi = myPsiManager.findFile(first);
final PsiFile secondPsi = myPsiManager.findFile(second);
assertTrue(CopyHandler.canCopy(new PsiElement[]{firstPsi, secondPsi}));
final VirtualFile toDir = root.findChild("to");
assertNotNull(toDir);
final PsiDirectory targetDirectory = myPsiManager.findDirectory(toDir);
CopyHandler.doCopy(new PsiElement[]{firstPsi, secondPsi}, targetDirectory);
assertNotNull(root.findFileByRelativePath("to/1.txt"));
assertNotNull(root.findFileByRelativePath("to/2.txt"));
}
示例3: doMultifileTest
import com.intellij.testFramework.IdeaTestUtil; //导入依赖的package包/类
private void doMultifileTest() throws Exception {
String root = JavaTestUtil.getJavaTestDataPath() + "/refactoring/copyClass/multifile/" + getTestName(true);
String rootBefore = root + "/before";
PsiTestUtil.removeAllRoots(myModule, IdeaTestUtil.getMockJdk17());
VirtualFile rootDir = PsiTestUtil.createTestProjectStructure(myProject, myModule, rootBefore, myFilesToDelete);
final HashMap<PsiFile, PsiClass[]> map = new HashMap<>();
final VirtualFile sourceDir = rootDir.findChild("p1");
for (VirtualFile file : sourceDir.getChildren()) {
final PsiFile psiFile = myPsiManager.findFile(file);
if (psiFile instanceof PsiJavaFile) {
map.put(psiFile, ((PsiJavaFile)psiFile).getClasses());
}
}
final VirtualFile targetVDir = rootDir.findChild("p2");
CopyClassesHandler.doCopyClasses(map, null, myPsiManager.findDirectory(targetVDir), myProject);
String rootAfter = root + "/after";
VirtualFile rootDir2 = LocalFileSystem.getInstance().findFileByPath(rootAfter.replace(File.separatorChar, '/'));
myProject.getComponent(PostprocessReformattingAspect.class).doPostponedFormatting();
PlatformTestUtil.assertDirectoriesEqual(rootDir2, rootDir);
}
示例4: setUp
import com.intellij.testFramework.IdeaTestUtil; //导入依赖的package包/类
@Override
public void setUp() throws Exception {
myJdkHome = IdeaTestUtil.requireRealJdkHome();
super.setUp();
assumeThat(gradleVersion, versionMatcherRule.getMatcher());
new WriteAction() {
@Override
protected void run(@NotNull Result result) throws Throwable {
Sdk oldJdk = ProjectJdkTable.getInstance().findJdk(GRADLE_JDK_NAME);
if (oldJdk != null) {
ProjectJdkTable.getInstance().removeJdk(oldJdk);
}
VirtualFile jdkHomeDir = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(new File(myJdkHome));
Sdk jdk = SdkConfigurationUtil.setupSdk(new Sdk[0], jdkHomeDir, JavaSdk.getInstance(), true, null, GRADLE_JDK_NAME);
assertNotNull("Cannot create JDK for " + myJdkHome, jdk);
ProjectJdkTable.getInstance().addJdk(jdk);
}
}.execute();
myProjectSettings = new GradleProjectSettings();
GradleSettings.getInstance(myProject).setGradleVmOptions("-Xmx64m -XX:MaxPermSize=64m");
System.setProperty(ExternalSystemExecutionSettings.REMOTE_PROCESS_IDLE_TTL_IN_MS_KEY, String.valueOf(GRADLE_DAEMON_TTL_MS));
configureWrapper();
}
示例5: doPackageCopy
import com.intellij.testFramework.IdeaTestUtil; //导入依赖的package包/类
private void doPackageCopy() throws Exception {
String root = JavaTestUtil.getJavaTestDataPath() + "/refactoring/copyClass/multifile/" + getTestName(true);
String rootBefore = root + "/before";
PsiTestUtil.removeAllRoots(myModule, IdeaTestUtil.getMockJdk17());
VirtualFile rootDir = PsiTestUtil.createTestProjectStructure(myProject, myModule, rootBefore, myFilesToDelete);
final VirtualFile targetVDir = rootDir.findChild("p2");
final PsiDirectory sourceP1Dir = myPsiManager.findDirectory(rootDir.findChild("p1"));
final PsiDirectory targetP2Dir = myPsiManager.findDirectory(targetVDir);
new CopyClassesHandler().doCopy(new PsiElement[]{sourceP1Dir}, targetP2Dir);
String rootAfter = root + "/after";
VirtualFile rootDir2 = LocalFileSystem.getInstance().findFileByPath(rootAfter.replace(File.separatorChar, '/'));
myProject.getComponent(PostprocessReformattingAspect.class).doPostponedFormatting();
PlatformTestUtil.assertDirectoriesEqual(rootDir2, rootDir);
}
示例6: doTest
import com.intellij.testFramework.IdeaTestUtil; //导入依赖的package包/类
private void doTest(String className) throws Exception {
String rootBefore = getRoot() + "/before";
PsiTestUtil.removeAllRoots(myModule, IdeaTestUtil.getMockJdk17());
final VirtualFile rootDir = PsiTestUtil.createTestProjectStructure(myProject, myModule, rootBefore, myFilesToDelete);
PsiClass classToInline = myJavaFacade.findClass(className, ProjectScope.getAllScope(myProject));
assertEquals(null, InlineToAnonymousClassHandler.getCannotInlineMessage(classToInline));
InlineToAnonymousClassProcessor processor = new InlineToAnonymousClassProcessor(myProject,
classToInline,
null, false, false, false);
UsageInfo[] usages = processor.findUsages();
MultiMap<PsiElement,String> conflicts = processor.getConflicts(usages);
assertEquals(0, conflicts.size());
processor.run();
String rootAfter = getRoot() + "/after";
VirtualFile rootDir2 = LocalFileSystem.getInstance().findFileByPath(rootAfter.replace(File.separatorChar, '/'));
myProject.getComponent(PostprocessReformattingAspect.class).doPostponedFormatting();
PlatformTestUtil.assertDirectoriesEqual(rootDir2, rootDir);
}
示例7: initProject
import com.intellij.testFramework.IdeaTestUtil; //导入依赖的package包/类
private void initProject(String folderName, final String... sourceDirs) {
final String testDir = JavaTestUtil.getJavaTestDataPath() + "/find/" + folderName;
ApplicationManager.getApplication().runWriteAction(() -> {
try{
mySourceDirs = new VirtualFile[sourceDirs.length];
for (int i = 0; i < sourceDirs.length; i++){
String sourcePath = testDir + "/" + sourceDirs[i];
mySourceDirs[i] = LocalFileSystem.getInstance().refreshAndFindFileByPath(FileUtil.toSystemIndependentName(sourcePath));
}
VirtualFile projectDir = LocalFileSystem.getInstance().refreshAndFindFileByPath(FileUtil.toSystemIndependentName(testDir));
Sdk jdk = IdeaTestUtil.getMockJdk17();
PsiTestUtil.removeAllRoots(myModule, jdk);
PsiTestUtil.addContentRoot(myModule, projectDir);
for (VirtualFile sourceDir : mySourceDirs) {
PsiTestUtil.addSourceRoot(myModule, sourceDir);
}
}
catch (Exception e){
throw new RuntimeException(e);
}
});
}
示例8: testVisibilitySorter
import com.intellij.testFramework.IdeaTestUtil; //导入依赖的package包/类
public void testVisibilitySorter() throws Exception {
dotest(new CheckAction() {
@Override
public void testClassStructure(StructureViewComponent structureViewComponent) {
structureViewComponent.setActionActive(JavaInheritedMembersNodeProvider.ID, false);
IdeaTestUtil.assertTreeEqual(structureViewComponent.getTree(), "-Class2.java\n" +
" -Class2\n" +
" __myPrivateFiield: int\n" +
" _myProtectedField: int\n" +
" myPublicField: int\n");
structureViewComponent.setActionActive(VisibilitySorter.ID, true);
IdeaTestUtil.assertTreeEqual(structureViewComponent.getTree(), "-Class2.java\n" +
" -Class2\n" +
" myPublicField: int\n" +
" _myProtectedField: int\n" +
" __myPrivateFiield: int\n");
}
});
}
示例9: testMembersOrder
import com.intellij.testFramework.IdeaTestUtil; //导入依赖的package包/类
public void testMembersOrder() throws Exception {
dotest(new CheckAction() {
@Override
public void testClassStructure(StructureViewComponent structureViewComponent) {
structureViewComponent.setActionActive(JavaInheritedMembersNodeProvider.ID, false);
IdeaTestUtil.assertTreeEqual(structureViewComponent.getTree(), "-Class2.java\n" +
" -Class2\n" +
" Class2()\n" +
" af(): void\n" +
" zf(): void\n" +
" ab: int\n" +
" z: int\n"
);
}
});
}
示例10: testLanguageLevelChange
import com.intellij.testFramework.IdeaTestUtil; //导入依赖的package包/类
public void testLanguageLevelChange() {
//noinspection unused
PsiFile psiFile = myFixture.addFileToProject("Foo.java", "class Foo {}");
GlobalSearchScope scope = GlobalSearchScope.allScope(getProject());
PlatformTestUtil.tryGcSoftlyReachableObjects();
PsiClass psiClass = JavaPsiFacade.getInstance(getProject()).findClass("Foo", scope);
assertNotNull(psiClass);
long count = PsiManager.getInstance(getProject()).getModificationTracker().getJavaStructureModificationCount();
IdeaTestUtil.setModuleLanguageLevel(myFixture.getModule(), LanguageLevel.JDK_1_3);
assertTrue(count != PsiManager.getInstance(getProject()).getModificationTracker().getJavaStructureModificationCount());
psiClass = (JavaPsiFacade.getInstance(getProject()).findClass("Foo", scope));
assertNotNull(psiClass);
assertTrue(psiClass.isValid());
}
示例11: testAnnotation
import com.intellij.testFramework.IdeaTestUtil; //导入依赖的package包/类
public void testAnnotation() throws Exception {
IdeaTestUtil.withLevel(getModule(), LanguageLevel.JDK_1_6, new Runnable() {
@Override
public void run() {
doTest();
}
});
}
示例12: testDefaultMethods
import com.intellij.testFramework.IdeaTestUtil; //导入依赖的package包/类
public void testDefaultMethods() throws Exception {
IdeaTestUtil.withLevel(getModule(), LanguageLevel.JDK_1_6, new Runnable() {
@Override
public void run() {
doTest();
}
});
}
示例13: testOverrideAnnotation
import com.intellij.testFramework.IdeaTestUtil; //导入依赖的package包/类
public void testOverrideAnnotation() throws Exception {
IdeaTestUtil.withLevel(getModule(), LanguageLevel.JDK_1_6, new Runnable() {
@Override
public void run() {
doTest();
}
});
}
示例14: testRawInheritFromNewlyGenerified
import com.intellij.testFramework.IdeaTestUtil; //导入依赖的package包/类
public void testRawInheritFromNewlyGenerified() throws Exception {
IdeaTestUtil.withLevel(getModule(), LanguageLevel.JDK_1_6, new Runnable() {
@Override
public void run() {
doTest();
}
});
}
示例15: tuneFixture
import com.intellij.testFramework.IdeaTestUtil; //导入依赖的package包/类
@Override
protected void tuneFixture(JavaModuleFixtureBuilder moduleBuilder) throws Exception {
moduleBuilder.setLanguageLevel(LanguageLevel.JDK_1_8);
moduleBuilder.addLibraryJars("guava-17.0.jar", PathManager.getHomePath().replace(File.separatorChar, '/') + "/community/lib/",
"guava-17.0.jar");
moduleBuilder.addLibraryJars("guava-17.0.jar-2", PathManager.getHomePath().replace(File.separatorChar, '/') + "/lib/",
"guava-17.0.jar");
moduleBuilder.addJdk(IdeaTestUtil.getMockJdk18Path().getPath());
}