From ffe6785649519aee34009bf69593b34fbc138063 Mon Sep 17 00:00:00 2001 From: Roman Shevchenko Date: Fri, 30 Aug 2013 17:10:03 +0400 Subject: [PATCH] Test cleanup --- .../openapi/vfs/JarFileSystemTest.java | 61 +++++++++++-------- 1 file changed, 37 insertions(+), 24 deletions(-) diff --git a/java/java-tests/testSrc/com/intellij/openapi/vfs/JarFileSystemTest.java b/java/java-tests/testSrc/com/intellij/openapi/vfs/JarFileSystemTest.java index dc48b51ee662..52be1927ad5d 100644 --- a/java/java-tests/testSrc/com/intellij/openapi/vfs/JarFileSystemTest.java +++ b/java/java-tests/testSrc/com/intellij/openapi/vfs/JarFileSystemTest.java @@ -1,25 +1,39 @@ +/* + * Copyright 2000-2013 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.openapi.vfs; import com.intellij.openapi.projectRoots.Sdk; import com.intellij.openapi.roots.ModuleRootManager; -import com.intellij.openapi.util.SystemInfo; import com.intellij.testFramework.IdeaTestCase; -import java.io.File; +import java.io.IOException; -public class JarFileSystemTest extends IdeaTestCase{ - public void testFindFile() throws Exception{ - Sdk jdk = ModuleRootManager.getInstance(myModule).getSdk(); - VirtualFile jdkHome = jdk.getHomeDirectory(); - String rtJarPath = new File(jdkHome.getPath() + "/src.zip").getCanonicalPath().replace(File.separator, "/"); +import static com.intellij.testFramework.PlatformTestUtil.assertPathsEqual; - VirtualFile file1 = findByPath(rtJarPath + JarFileSystem.JAR_SEPARATOR); - assertTrue(file1.isDirectory()); +public class JarFileSystemTest extends IdeaTestCase { + public void testFindFile() throws IOException { + String rtJarPath = getJdkRtPath("src.zip"); + + VirtualFile jarRoot = findByPath(rtJarPath + JarFileSystem.JAR_SEPARATOR); + assertTrue(jarRoot.isDirectory()); VirtualFile file2 = findByPath(rtJarPath + JarFileSystem.JAR_SEPARATOR + "java"); assertTrue(file2.isDirectory()); - VirtualFile file3 = file1.findChild("java"); + VirtualFile file3 = jarRoot.findChild("java"); assertEquals(file2, file3); VirtualFile file4 = findByPath(rtJarPath + JarFileSystem.JAR_SEPARATOR + "java/lang/Object.java"); @@ -30,13 +44,11 @@ public class JarFileSystemTest extends IdeaTestCase{ assertTrue(bytes.length > 10); } - public void testMetaInf() throws Exception{ - Sdk jdk = ModuleRootManager.getInstance(myModule).getSdk(); - VirtualFile jdkHome = jdk.getHomeDirectory(); - String rtJarPath = jdkHome.getPath() + "/jre/lib/rt.jar"; + public void testMetaInf() { + String rtJarPath = getJdkRtPath("jre/lib/rt.jar"); - VirtualFile jarRoot = JarFileSystem.getInstance().findFileByPath(rtJarPath + JarFileSystem.JAR_SEPARATOR); - assertNotNull(jarRoot); + VirtualFile jarRoot = findByPath(rtJarPath + JarFileSystem.JAR_SEPARATOR); + assertTrue(jarRoot.isDirectory()); VirtualFile metaInf = jarRoot.findChild("META-INF"); assertNotNull(metaInf); @@ -45,17 +57,18 @@ public class JarFileSystemTest extends IdeaTestCase{ assertEquals(1, children.length); } + private String getJdkRtPath(String relativePath) { + Sdk jdk = ModuleRootManager.getInstance(myModule).getSdk(); + assertNotNull(jdk); + VirtualFile jdkHome = jdk.getHomeDirectory(); + assertNotNull(jdkHome); + return jdkHome.getPath() + "/" + relativePath; + } + private static VirtualFile findByPath(String path) { VirtualFile file = JarFileSystem.getInstance().findFileByPath(path); assertNotNull(file); - final String filePath = file.getPath(); - final String message = "paths are not equal, path1 = " + path + " found: " + filePath; - if (SystemInfo.isFileSystemCaseSensitive) { - assertEquals(message, path, file.getPath()); - } - else { - assertTrue(message, path.equalsIgnoreCase(filePath)); - } + assertPathsEqual(path, file.getPath()); return file; } }