From 91e3ed4c1c3ed458637c35829bd65f9512e9e445 Mon Sep 17 00:00:00 2001 From: Roman Shevchenko Date: Wed, 23 Apr 2014 13:03:48 +0200 Subject: [PATCH] vfs: .jar refresh test extended --- .../openapi/vfs/local/JarFileSystemTest.java | 8 ++++++- .../intellij/openapi/util/io/IoTestUtil.java | 21 +++++++++++-------- 2 files changed, 19 insertions(+), 10 deletions(-) diff --git a/platform/platform-tests/testSrc/com/intellij/openapi/vfs/local/JarFileSystemTest.java b/platform/platform-tests/testSrc/com/intellij/openapi/vfs/local/JarFileSystemTest.java index 250a8ff5066b..7d76baeedc62 100644 --- a/platform/platform-tests/testSrc/com/intellij/openapi/vfs/local/JarFileSystemTest.java +++ b/platform/platform-tests/testSrc/com/intellij/openapi/vfs/local/JarFileSystemTest.java @@ -75,6 +75,9 @@ public class JarFileSystemTest extends PlatformLangTestCase { VirtualFile vFile = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(jar); assertNotNull(vFile); + VirtualFile jarRoot = findByPath(jar.getPath() + JarFileSystem.JAR_SEPARATOR); + assertEquals(1, jarRoot.getChildren().length); + final VirtualFile entry = findByPath(jar.getPath() + JarFileSystem.JAR_SEPARATOR + JarFile.MANIFEST_NAME); assertContent(entry, ""); @@ -94,12 +97,15 @@ public class JarFileSystemTest extends PlatformLangTestCase { } ); - IoTestUtil.writeEntry(jar, JarFile.MANIFEST_NAME, "update"); + IoTestUtil.createTestJar(jar, JarFile.MANIFEST_NAME, "update", "some.txt", "some text"); vFile.refresh(false, false); assertTrue(updated.get()); assertTrue(entry.isValid()); assertContent(entry, "update"); + assertEquals(2, jarRoot.getChildren().length); + VirtualFile newEntry = findByPath(jar.getPath() + JarFileSystem.JAR_SEPARATOR + "some.txt"); + assertContent(newEntry, "some text"); } public void testInvalidJar() throws Exception { diff --git a/platform/util/testSrc/com/intellij/openapi/util/io/IoTestUtil.java b/platform/util/testSrc/com/intellij/openapi/util/io/IoTestUtil.java index 1d9823bbdb89..5dbe2dd1ae76 100644 --- a/platform/util/testSrc/com/intellij/openapi/util/io/IoTestUtil.java +++ b/platform/util/testSrc/com/intellij/openapi/util/io/IoTestUtil.java @@ -26,9 +26,9 @@ import java.io.*; import java.net.URL; import java.util.Locale; import java.util.Set; -import java.util.jar.JarEntry; import java.util.jar.JarFile; -import java.util.jar.JarOutputStream; +import java.util.zip.ZipEntry; +import java.util.zip.ZipOutputStream; import static org.junit.Assert.*; @@ -217,20 +217,23 @@ public class IoTestUtil { @NotNull public static File createTestJar(File jarFile) throws IOException { - writeEntry(jarFile, JarFile.MANIFEST_NAME, ""); - return jarFile; + return createTestJar(jarFile, JarFile.MANIFEST_NAME, ""); } - public static void writeEntry(@NotNull File jarFile, @NotNull String name, @NotNull String content) throws IOException { - JarOutputStream stream = new JarOutputStream(new FileOutputStream(jarFile)); + @NotNull + public static File createTestJar(@NotNull File jarFile, @NotNull String... data) throws IOException { + ZipOutputStream stream = new ZipOutputStream(new FileOutputStream(jarFile)); try { - stream.putNextEntry(new JarEntry(name)); - stream.write(content.getBytes("UTF-8")); - stream.closeEntry(); + for (int i = 0; i < data.length; i += 2) { + stream.putNextEntry(new ZipEntry(data[i])); + stream.write(data[i + 1].getBytes("UTF-8")); + stream.closeEntry(); + } } finally { stream.close(); } + return jarFile; } @NotNull