mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
[tests] test cases for IDEA-236701
GitOrigin-RevId: 04c387920f3cb4f21b5c96e1147941a926f73a6a
This commit is contained in:
committed by
intellij-monorepo-bot
parent
71ca0b2cb9
commit
10d5f7c003
Binary file not shown.
@@ -0,0 +1,102 @@
|
||||
// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
package com.intellij.java.codeInsight;
|
||||
|
||||
import com.intellij.openapi.module.Module;
|
||||
import com.intellij.openapi.roots.ContentEntry;
|
||||
import com.intellij.openapi.roots.ModifiableRootModel;
|
||||
import com.intellij.testFramework.PsiTestUtil;
|
||||
import com.intellij.testFramework.fixtures.*;
|
||||
import com.intellij.testFramework.fixtures.impl.LightTempDirTestFixtureImpl;
|
||||
import com.intellij.testFramework.rules.TempDirectory;
|
||||
import net.bytebuddy.ByteBuddy;
|
||||
import net.bytebuddy.implementation.StubMethod;
|
||||
import net.bytebuddy.jar.asm.Opcodes;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.UncheckedIOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.jar.JarOutputStream;
|
||||
import java.util.zip.ZipEntry;
|
||||
import java.util.zip.ZipOutputStream;
|
||||
|
||||
import static com.intellij.testFramework.EdtTestUtil.runInEdtAndWait;
|
||||
|
||||
public class ClsResolveTest {
|
||||
@Rule public TempDirectory tempDir = new TempDirectory();
|
||||
|
||||
private JavaCodeInsightTestFixture myFixture;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
Path jar = generateMutantJar();
|
||||
DefaultLightProjectDescriptor descriptor = new DefaultLightProjectDescriptor() {
|
||||
@Override
|
||||
public void configureModule(@NotNull Module module, @NotNull ModifiableRootModel model, @NotNull ContentEntry contentEntry) {
|
||||
super.configureModule(module, model, contentEntry);
|
||||
PsiTestUtil.addLibrary(model, "mutant", jar.getParent().toString(), jar.getFileName().toString());
|
||||
}
|
||||
};
|
||||
TestFixtureBuilder<IdeaProjectTestFixture> builder = IdeaTestFixtureFactory.getFixtureFactory().createLightFixtureBuilder(descriptor);
|
||||
myFixture = JavaTestFixtureFactory.getFixtureFactory().createCodeInsightFixture(builder.getFixture(), new LightTempDirTestFixtureImpl(true));
|
||||
myFixture.setUp();
|
||||
}
|
||||
|
||||
//<editor-fold desc="Test data generation">
|
||||
private Path generateMutantJar() {
|
||||
try {
|
||||
Path file = tempDir.newFile("mutant.jar").toPath();
|
||||
try (JarOutputStream jar = new JarOutputStream(Files.newOutputStream(file))) {
|
||||
writeEntry(jar, "mutant1/aB.class", classBytes("mutant1.aB", "m1"));
|
||||
writeEntry(jar, "mutant1/ab.class", classBytes("mutant1.ab", "m2"));
|
||||
writeEntry(jar, "MUTANT2/C.class", classBytes("MUTANT2.C", "m3"));
|
||||
writeEntry(jar, "mutant2/D.class", classBytes("mutant2.D", "m4"));
|
||||
}
|
||||
return file;
|
||||
}
|
||||
catch (IOException e) {
|
||||
throw new UncheckedIOException(e);
|
||||
}
|
||||
}
|
||||
|
||||
private static void writeEntry(ZipOutputStream zip, String name, byte[] data) throws IOException {
|
||||
ZipEntry entry = new ZipEntry(name);
|
||||
zip.putNextEntry(entry);
|
||||
zip.write(data);
|
||||
zip.closeEntry();
|
||||
}
|
||||
|
||||
private static byte[] classBytes(String name, String method) {
|
||||
return new ByteBuddy()
|
||||
.subclass(Object.class).modifiers(Opcodes.ACC_PUBLIC).name(name)
|
||||
.defineMethod(method, void.class, Opcodes.ACC_PUBLIC | Opcodes.ACC_STATIC).intercept(StubMethod.INSTANCE)
|
||||
.make().getBytes();
|
||||
}
|
||||
//</editor-fold>
|
||||
|
||||
@After
|
||||
public void tearDown() throws Exception {
|
||||
myFixture.tearDown();
|
||||
myFixture = null;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void resolveIntoMutantJar() {
|
||||
runInEdtAndWait(() -> {
|
||||
myFixture.configureByText(
|
||||
"test.java",
|
||||
"class test {{\n" +
|
||||
" mutant1.aB.m1();\n" +
|
||||
" mutant1.ab.m2();\n" +
|
||||
" MUTANT2.C.m3();\n" +
|
||||
" mutant2.D.m4();\n" +
|
||||
"}}");
|
||||
myFixture.checkHighlighting();
|
||||
});
|
||||
}
|
||||
}
|
||||
+7
-16
@@ -3,7 +3,6 @@ package com.intellij.openapi.vfs.local;
|
||||
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.application.PathManager;
|
||||
import com.intellij.openapi.application.ex.PathManagerEx;
|
||||
import com.intellij.openapi.util.Ref;
|
||||
import com.intellij.openapi.util.io.FileAttributes;
|
||||
import com.intellij.openapi.util.io.FileUtil;
|
||||
@@ -18,7 +17,6 @@ import com.intellij.openapi.vfs.newvfs.BulkFileListener;
|
||||
import com.intellij.openapi.vfs.newvfs.events.VFileContentChangeEvent;
|
||||
import com.intellij.openapi.vfs.newvfs.events.VFileEvent;
|
||||
import com.intellij.testFramework.PlatformTestUtil;
|
||||
import com.intellij.testFramework.UsefulTestCase;
|
||||
import com.intellij.testFramework.fixtures.BareTestFixtureTestCase;
|
||||
import com.intellij.testFramework.rules.TempDirectory;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
@@ -231,6 +229,11 @@ public class JarFileSystemTest extends BareTestFixtureTestCase {
|
||||
writeEntry(zip, "a/b");
|
||||
writeEntry(zip, "a/b/c.txt");
|
||||
writeEntry(zip, "x\\y\\z.txt");
|
||||
writeEntry(zip, "/x/f.txt");
|
||||
writeEntry(zip, "d1/aB");
|
||||
writeEntry(zip, "d1/ab");
|
||||
writeEntry(zip, "D2/f1");
|
||||
writeEntry(zip, "d2/f2");
|
||||
}
|
||||
|
||||
String rootPath = FileUtil.toSystemIndependentName(testZip.getPath()) + JarFileSystem.JAR_SEPARATOR;
|
||||
@@ -247,7 +250,8 @@ public class JarFileSystemTest extends BareTestFixtureTestCase {
|
||||
return true;
|
||||
}
|
||||
});
|
||||
assertThat(entries).containsExactlyInAnyOrder("a/", "a/b/", "a/b/c.txt", "x/", "x/y/", "x/y/z.txt");
|
||||
assertThat(entries).containsExactlyInAnyOrder(
|
||||
"a/", "a/b/", "a/b/c.txt", "x/", "x/y/", "x/f.txt", "x/y/z.txt", "d1/", "d1/aB", "d1/ab", "D2/", "D2/f1", "d2/", "d2/f2");
|
||||
}
|
||||
|
||||
private static void writeEntry(ZipOutputStream zip, String name) throws IOException {
|
||||
@@ -301,19 +305,6 @@ public class JarFileSystemTest extends BareTestFixtureTestCase {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCrazyJarWithDuplicateEntriesMustNotCrashAnything() {
|
||||
String jarPath = PathManagerEx.getTestDataPath() + "/vfs/sample.jar";
|
||||
VirtualFile vFile = LocalFileSystem.getInstance().refreshAndFindFileByPath(jarPath);
|
||||
assertNotNull(vFile);
|
||||
|
||||
VirtualFile jarRoot = JarFileSystem.getInstance().getRootByLocal(vFile);
|
||||
assertNotNull(jarRoot);
|
||||
String[] children = JarFileSystem.getInstance().list(jarRoot);
|
||||
assertEquals("com", UsefulTestCase.assertOneElement(children));
|
||||
assertEquals("Hello.class", UsefulTestCase.assertOneElement(JarFileSystem.getInstance().list(jarRoot.findFileByRelativePath("com"))));
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static VirtualFile findByPath(String path) {
|
||||
VirtualFile file = JarFileSystem.getInstance().findFileByPath(path);
|
||||
|
||||
Reference in New Issue
Block a user