From fdc0c49e2262bcacf578fe6cb497eb4c6fdf458d Mon Sep 17 00:00:00 2001 From: Alexey Kudravtsev Date: Mon, 20 Aug 2018 15:58:33 +0300 Subject: [PATCH] better assertions: no need to import Assert --- .../configurations/JavaCommandLineTest.java | 2 - .../java/openapi/vfs/JrtFileSystemTest.java | 43 ++++++++--------- .../intellij/diagnostic/DialogAppenderTest.kt | 1 - .../updates/StartupActionScriptManagerTest.kt | 2 - .../ide/updates/UpdateInfoParsingTest.kt | 2 - .../ide/updates/UpdateStrategyTest.kt | 3 -- .../application/RunnableActionsTest.kt | 8 +--- ...UpdatePluginsFromCustomRepositoryTest.java | 3 -- .../vfs/ArchiveFileSystemPerformanceTest.kt | 1 - .../openapi/vfs/DummyFileSystemTest.java | 2 - .../openapi/vfs/VfsUtilLightTest.java | 2 - .../openapi/vfs/VfsUtilPerformanceTest.java | 27 +++-------- .../com/intellij/openapi/vfs/VfsUtilTest.java | 2 - .../openapi/vfs/VirtualFileListenerTest.java | 3 -- .../openapi/vfs/VirtualFileVisitorTest.java | 2 - .../vfs/impl/VirtualFilePointerTest.java | 48 ++++++++++--------- .../openapi/vfs/local/FileWatcherTest.kt | 2 - .../openapi/vfs/local/JarFileSystemTest.java | 18 ++++--- .../vfs/local/LocalFileSystemTest.java | 31 ++++++------ .../vfs/local/SymlinkHandlingTest.java | 1 - .../com/intellij/util/ui/IconScaleTest.java | 2 - .../intellij/testFramework/VfsTestUtil.java | 2 +- .../fixtures/BareTestFixtureTestCase.java | 5 +- 23 files changed, 88 insertions(+), 124 deletions(-) diff --git a/java/java-tests/testSrc/com/intellij/java/execution/configurations/JavaCommandLineTest.java b/java/java-tests/testSrc/com/intellij/java/execution/configurations/JavaCommandLineTest.java index d1b10a72477a..e990aab873e9 100644 --- a/java/java-tests/testSrc/com/intellij/java/execution/configurations/JavaCommandLineTest.java +++ b/java/java-tests/testSrc/com/intellij/java/execution/configurations/JavaCommandLineTest.java @@ -28,8 +28,6 @@ import com.intellij.testFramework.IdeaTestUtil; import com.intellij.testFramework.fixtures.BareTestFixtureTestCase; import org.junit.Test; -import static org.junit.Assert.*; - public class JavaCommandLineTest extends BareTestFixtureTestCase { @Test public void testJdkMissing() { diff --git a/java/java-tests/testSrc/com/intellij/java/openapi/vfs/JrtFileSystemTest.java b/java/java-tests/testSrc/com/intellij/java/openapi/vfs/JrtFileSystemTest.java index 436d43f0035d..1bbfebf1dac0 100644 --- a/java/java-tests/testSrc/com/intellij/java/openapi/vfs/JrtFileSystemTest.java +++ b/java/java-tests/testSrc/com/intellij/java/openapi/vfs/JrtFileSystemTest.java @@ -15,6 +15,7 @@ import com.intellij.openapi.vfs.newvfs.events.VFileEvent; import com.intellij.openapi.vfs.pointers.VirtualFilePointer; import com.intellij.openapi.vfs.pointers.VirtualFilePointerManager; import com.intellij.testFramework.VfsTestUtil; +import org.assertj.core.api.Assertions; import com.intellij.testFramework.fixtures.BareTestFixtureTestCase; import com.intellij.testFramework.rules.TempDirectory; import org.junit.After; @@ -32,8 +33,6 @@ import java.util.List; import java.util.stream.Collectors; import java.util.stream.Stream; -import static org.assertj.core.api.Assertions.assertThat; - public class JrtFileSystemTest extends BareTestFixtureTestCase { @Rule public TempDirectory myTempDir = new TempDirectory(); @@ -49,8 +48,8 @@ public class JrtFileSystemTest extends BareTestFixtureTestCase { setupJrtFileSystem(); myRoot = findRoot(myTempPath.toString()); - assertThat(myRoot).isNotNull(); - assertThat(JrtFileSystem.isRoot(myRoot)).isTrue(); + assertNotNull(myRoot); + assertTrue(JrtFileSystem.isRoot(myRoot)); } @After @@ -70,50 +69,50 @@ public class JrtFileSystemTest extends BareTestFixtureTestCase { @Test public void nonRoot() { VirtualFile root = findRoot(JavaTestUtil.getJavaTestDataPath()); - assertThat(root).isNull(); + assertNull(root); } @Test public void basicOps() throws IOException { - assertThat(childNames(myRoot)).containsExactlyInAnyOrder("java.base", "test.a"); + Assertions.assertThat(childNames(myRoot)).containsExactlyInAnyOrder("java.base", "test.a"); VirtualFile moduleRoot = myRoot.findChild("test.a"); - assertThat(moduleRoot).isNotNull(); - assertThat(JrtFileSystem.isModuleRoot(moduleRoot)).isTrue(); - assertThat(childNames(moduleRoot)).containsExactlyInAnyOrder("pkg_a", "module-info.class"); + Assertions.assertThat(moduleRoot).isNotNull(); + Assertions.assertThat(JrtFileSystem.isModuleRoot(moduleRoot)).isTrue(); + Assertions.assertThat(childNames(moduleRoot)).containsExactlyInAnyOrder("pkg_a", "module-info.class"); VirtualFile classFile = moduleRoot.findFileByRelativePath("pkg_a/A.class"); - assertThat(classFile).isNotNull(); + Assertions.assertThat(classFile).isNotNull(); byte[] bytes = classFile.contentsToByteArray(); - assertThat(bytes.length).isGreaterThan(10); - assertThat(ByteBuffer.wrap(bytes).getInt()).isEqualTo(0xCAFEBABE); + Assertions.assertThat(bytes.length).isGreaterThan(10); + Assertions.assertThat(ByteBuffer.wrap(bytes).getInt()).isEqualTo(0xCAFEBABE); } @Test public void refresh() throws IOException { - assertThat(childNames(myRoot)).containsExactlyInAnyOrder("java.base", "test.a"); + Assertions.assertThat(childNames(myRoot)).containsExactlyInAnyOrder("java.base", "test.a"); VirtualFile local = LocalFileSystem.getInstance().findFileByPath(myTempPath.toString()); - assertThat(local).isNotNull(); + Assertions.assertThat(local).isNotNull(); Path modules = myTempPath.resolve("lib/modules"); Files.move(modules, myTempPath.resolve("lib/modules.bak"), StandardCopyOption.ATOMIC_MOVE); Files.copy(myTestData.resolve("image2"), modules); Files.write(myTempPath.resolve("release"), "JAVA_VERSION=9.0.1\n".getBytes(CharsetToolkit.UTF8_CHARSET)); List events = VfsTestUtil.getEvents(() -> local.refresh(false, true)); - assertThat(childNames(myRoot)).describedAs("events=" + events).containsExactlyInAnyOrder("java.base", "test.a", "test.b"); + Assertions.assertThat(childNames(myRoot)).describedAs("events=" + events).containsExactlyInAnyOrder("java.base", "test.a", "test.b"); if (SystemInfo.isUnix) { - assertThat(FileUtil.delete(myTempPath.toFile())).isTrue(); + Assertions.assertThat(FileUtil.delete(myTempPath.toFile())).isTrue(); events = VfsTestUtil.getEvents(() -> local.refresh(false, true)); - assertThat(myRoot.isValid()).describedAs("events=" + events).isFalse(); + Assertions.assertThat(myRoot.isValid()).describedAs("events=" + events).isFalse(); } } @Test public void filePointers() throws IOException { VirtualFile vTemp = LocalFileSystem.getInstance().refreshAndFindFileByPath(myTempPath.toString()); - assertThat(vTemp).isNotNull(); + Assertions.assertThat(vTemp).isNotNull(); VirtualFilePointerManager manager = VirtualFilePointerManager.getInstance(); VirtualFilePointer[] pointers = {manager.create(vTemp, myDisposable, null), manager.create(myRoot, myDisposable, null)}; assertPointers(pointers, true); @@ -121,7 +120,7 @@ public class JrtFileSystemTest extends BareTestFixtureTestCase { if (SystemInfo.isUnix) { VirtualFile testRoot = vTemp.getParent(); - assertThat(FileUtil.delete(myTempPath.toFile())).isTrue(); + Assertions.assertThat(FileUtil.delete(myTempPath.toFile())).isTrue(); testRoot.refresh(false, true); assertPointers(pointers, false); @@ -129,7 +128,7 @@ public class JrtFileSystemTest extends BareTestFixtureTestCase { testRoot.refresh(false, true); assertPointers(pointers, true); - assertThat(FileUtil.delete(myTempPath.toFile())).isTrue(); + Assertions.assertThat(FileUtil.delete(myTempPath.toFile())).isTrue(); testRoot.refresh(false, true); assertPointers(pointers, false); } @@ -145,7 +144,7 @@ public class JrtFileSystemTest extends BareTestFixtureTestCase { } private static void assertPointers(VirtualFilePointer[] pointers, boolean valid) { - assertThat(pointers).allMatch(p -> p.isValid() == valid); - assertThat(pointers).allMatch(p -> p.getFile() == null || p.getFile().isValid()); + Assertions.assertThat(pointers).allMatch(p -> p.isValid() == valid); + Assertions.assertThat(pointers).allMatch(p -> p.getFile() == null || p.getFile().isValid()); } } \ No newline at end of file diff --git a/platform/platform-tests/testSrc/com/intellij/diagnostic/DialogAppenderTest.kt b/platform/platform-tests/testSrc/com/intellij/diagnostic/DialogAppenderTest.kt index 4b43d1bf1bd8..79b2895ed963 100644 --- a/platform/platform-tests/testSrc/com/intellij/diagnostic/DialogAppenderTest.kt +++ b/platform/platform-tests/testSrc/com/intellij/diagnostic/DialogAppenderTest.kt @@ -7,7 +7,6 @@ import com.intellij.testFramework.fixtures.BareTestFixtureTestCase import org.apache.log4j.Level import org.apache.log4j.Logger import org.apache.log4j.spi.LoggingEvent -import org.junit.Assert.* import org.junit.Test /** diff --git a/platform/platform-tests/testSrc/com/intellij/ide/updates/StartupActionScriptManagerTest.kt b/platform/platform-tests/testSrc/com/intellij/ide/updates/StartupActionScriptManagerTest.kt index 175e2cba18fe..352d9c791c6d 100644 --- a/platform/platform-tests/testSrc/com/intellij/ide/updates/StartupActionScriptManagerTest.kt +++ b/platform/platform-tests/testSrc/com/intellij/ide/updates/StartupActionScriptManagerTest.kt @@ -14,8 +14,6 @@ import org.junit.Test import java.io.File import java.io.FileOutputStream import java.io.ObjectOutputStream -import kotlin.test.assertFalse -import kotlin.test.assertTrue class StartupActionScriptManagerTest : BareTestFixtureTestCase() { @Rule @JvmField val tempDir = TempDirectory() diff --git a/platform/platform-tests/testSrc/com/intellij/ide/updates/UpdateInfoParsingTest.kt b/platform/platform-tests/testSrc/com/intellij/ide/updates/UpdateInfoParsingTest.kt index 7d0afbffef92..f84de19d89c0 100644 --- a/platform/platform-tests/testSrc/com/intellij/ide/updates/UpdateInfoParsingTest.kt +++ b/platform/platform-tests/testSrc/com/intellij/ide/updates/UpdateInfoParsingTest.kt @@ -11,8 +11,6 @@ import org.junit.Test import java.io.IOException import java.net.URL import java.text.SimpleDateFormat -import kotlin.test.assertEquals -import kotlin.test.assertNotNull class UpdateInfoParsingTest : BareTestFixtureTestCase() { @Test fun liveJetbrainsUpdateFile() { diff --git a/platform/platform-tests/testSrc/com/intellij/ide/updates/UpdateStrategyTest.kt b/platform/platform-tests/testSrc/com/intellij/ide/updates/UpdateStrategyTest.kt index 4349579f4118..f731c6854e21 100644 --- a/platform/platform-tests/testSrc/com/intellij/ide/updates/UpdateStrategyTest.kt +++ b/platform/platform-tests/testSrc/com/intellij/ide/updates/UpdateStrategyTest.kt @@ -7,9 +7,6 @@ import com.intellij.testFramework.fixtures.BareTestFixtureTestCase import com.intellij.util.loadElement import org.assertj.core.api.Assertions.assertThat import org.junit.Test -import kotlin.test.assertEquals -import kotlin.test.assertNotNull -import kotlin.test.assertNull // unless stated otherwise, the behavior described in cases is true for 162+ class UpdateStrategyTest : BareTestFixtureTestCase() { diff --git a/platform/platform-tests/testSrc/com/intellij/openapi/application/RunnableActionsTest.kt b/platform/platform-tests/testSrc/com/intellij/openapi/application/RunnableActionsTest.kt index 328dc81788ee..286a69193cd6 100644 --- a/platform/platform-tests/testSrc/com/intellij/openapi/application/RunnableActionsTest.kt +++ b/platform/platform-tests/testSrc/com/intellij/openapi/application/RunnableActionsTest.kt @@ -19,7 +19,6 @@ import com.intellij.openapi.command.WriteCommandAction import com.intellij.testFramework.fixtures.BareTestFixtureTestCase import org.assertj.core.api.Assertions.assertThat import org.junit.Test -import kotlin.test.fail class RunnableActionsTest : BareTestFixtureTestCase() { private val message = "" @@ -45,12 +44,7 @@ class RunnableActionsTest : BareTestFixtureTestCase() { assertThat(e.message).endsWith(message) } - val result = try { - action.executeSilently() - } - catch(e: RuntimeException) { - fail("BaseActionRunnable.executeSilently() should capture exceptions") - } + val result:RunResult = action.executeSilently() assertThat(result.hasException()).isTrue() assertThat(result.throwable.message).endsWith(message) } diff --git a/platform/platform-tests/testSrc/com/intellij/openapi/updateSettings/UpdatePluginsFromCustomRepositoryTest.java b/platform/platform-tests/testSrc/com/intellij/openapi/updateSettings/UpdatePluginsFromCustomRepositoryTest.java index 759d5d073e52..273bfb9a6cfa 100644 --- a/platform/platform-tests/testSrc/com/intellij/openapi/updateSettings/UpdatePluginsFromCustomRepositoryTest.java +++ b/platform/platform-tests/testSrc/com/intellij/openapi/updateSettings/UpdatePluginsFromCustomRepositoryTest.java @@ -20,9 +20,6 @@ import java.util.ArrayList; import java.util.LinkedHashMap; import java.util.Map; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; - public class UpdatePluginsFromCustomRepositoryTest extends BareTestFixtureTestCase { @Test public void testOnlyCompatiblePluginsAreChecked() throws Exception { diff --git a/platform/platform-tests/testSrc/com/intellij/openapi/vfs/ArchiveFileSystemPerformanceTest.kt b/platform/platform-tests/testSrc/com/intellij/openapi/vfs/ArchiveFileSystemPerformanceTest.kt index 52fbe4408bd3..2913f3147839 100644 --- a/platform/platform-tests/testSrc/com/intellij/openapi/vfs/ArchiveFileSystemPerformanceTest.kt +++ b/platform/platform-tests/testSrc/com/intellij/openapi/vfs/ArchiveFileSystemPerformanceTest.kt @@ -20,7 +20,6 @@ import com.intellij.testFramework.PlatformTestUtil import com.intellij.testFramework.fixtures.BareTestFixtureTestCase import org.junit.Before import org.junit.Test -import kotlin.test.assertEquals class ArchiveFileSystemPerformanceTest : BareTestFixtureTestCase() { private lateinit var fs: ArchiveFileSystem diff --git a/platform/platform-tests/testSrc/com/intellij/openapi/vfs/DummyFileSystemTest.java b/platform/platform-tests/testSrc/com/intellij/openapi/vfs/DummyFileSystemTest.java index 3932b975fc9f..c4dc8f0da691 100644 --- a/platform/platform-tests/testSrc/com/intellij/openapi/vfs/DummyFileSystemTest.java +++ b/platform/platform-tests/testSrc/com/intellij/openapi/vfs/DummyFileSystemTest.java @@ -26,8 +26,6 @@ import org.junit.Test; import java.io.IOException; import static com.intellij.openapi.util.Pair.pair; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; public class DummyFileSystemTest extends BareTestFixtureTestCase { @Test diff --git a/platform/platform-tests/testSrc/com/intellij/openapi/vfs/VfsUtilLightTest.java b/platform/platform-tests/testSrc/com/intellij/openapi/vfs/VfsUtilLightTest.java index 95f09b395392..c24922f4558a 100644 --- a/platform/platform-tests/testSrc/com/intellij/openapi/vfs/VfsUtilLightTest.java +++ b/platform/platform-tests/testSrc/com/intellij/openapi/vfs/VfsUtilLightTest.java @@ -10,8 +10,6 @@ import org.junit.Test; import static com.intellij.mock.MockVirtualFile.dir; import static com.intellij.mock.MockVirtualFile.file; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; public class VfsUtilLightTest extends BareTestFixtureTestCase { private static VirtualFile myRoot; diff --git a/platform/platform-tests/testSrc/com/intellij/openapi/vfs/VfsUtilPerformanceTest.java b/platform/platform-tests/testSrc/com/intellij/openapi/vfs/VfsUtilPerformanceTest.java index 5347b7a8b7c8..5842f622bdba 100644 --- a/platform/platform-tests/testSrc/com/intellij/openapi/vfs/VfsUtilPerformanceTest.java +++ b/platform/platform-tests/testSrc/com/intellij/openapi/vfs/VfsUtilPerformanceTest.java @@ -17,7 +17,6 @@ package com.intellij.openapi.vfs; import com.intellij.concurrency.JobLauncher; import com.intellij.concurrency.JobSchedulerImpl; -import com.intellij.openapi.application.WriteAction; import com.intellij.openapi.command.WriteCommandAction; import com.intellij.openapi.progress.ProgressManager; import com.intellij.openapi.util.Disposer; @@ -33,10 +32,7 @@ import com.intellij.openapi.vfs.newvfs.events.VFileDeleteEvent; import com.intellij.openapi.vfs.newvfs.events.VFileEvent; import com.intellij.openapi.vfs.newvfs.impl.VirtualDirectoryImpl; import com.intellij.openapi.vfs.newvfs.persistent.PersistentFS; -import com.intellij.testFramework.EdtTestUtil; -import com.intellij.testFramework.PlatformTestUtil; -import com.intellij.testFramework.RunFirst; -import com.intellij.testFramework.SkipSlowTestLocally; +import com.intellij.testFramework.*; import com.intellij.testFramework.fixtures.BareTestFixtureTestCase; import com.intellij.testFramework.fixtures.impl.LightTempDirTestFixtureImpl; import com.intellij.testFramework.rules.TempDirectory; @@ -59,8 +55,6 @@ import java.util.concurrent.TimeUnit; import java.util.stream.Collectors; import java.util.stream.IntStream; -import static org.junit.Assert.*; - @RunFirst @SkipSlowTestLocally public class VfsUtilPerformanceTest extends BareTestFixtureTestCase { @@ -316,17 +310,10 @@ public class VfsUtilPerformanceTest extends BareTestFixtureTestCase { ); } - private VirtualDirectoryImpl createTempFsDirectory() throws IOException { - VirtualDirectoryImpl temp = WriteAction.computeAndWait(() -> - (VirtualDirectoryImpl)TempFileSystem.getInstance().findFileByPath("/").createChildDirectory(this, "temp")); - Disposer.register(getTestRootDisposable(), () -> { - try { - WriteAction.runAndWait(() -> temp.delete(this)); - } - catch (IOException e) { - throw new RuntimeException(); - } - }); + private VirtualDirectoryImpl createTempFsDirectory() { + VirtualFile root = TempFileSystem.getInstance().findFileByPath("/"); + VirtualDirectoryImpl temp = (VirtualDirectoryImpl)VfsTestUtil.createDir(root, "temp"); + Disposer.register(getTestRootDisposable(), () -> VfsTestUtil.deleteFile(temp)); return temp; } @@ -334,7 +321,7 @@ public class VfsUtilPerformanceTest extends BareTestFixtureTestCase { WriteCommandAction.runWriteCommandAction(null, () -> PersistentFS.getInstance().processEvents(events)); } - private void eventsForCreating(List events, int N, VirtualDirectoryImpl temp) { + private void eventsForCreating(List events, int N, VirtualDirectoryImpl temp) { events.clear(); TempFileSystem fs = TempFileSystem.getInstance(); IntStream.range(0, N) @@ -349,7 +336,7 @@ public class VfsUtilPerformanceTest extends BareTestFixtureTestCase { temp.removeChildren(new TIntHashSet(), names); } - private void eventsForDeleting(List events, VirtualDirectoryImpl temp) { + private void eventsForDeleting(List events, VirtualDirectoryImpl temp) { events.clear(); temp.getCachedChildren().stream() .map(v->new VFileDeleteEvent(this, v, false)) diff --git a/platform/platform-tests/testSrc/com/intellij/openapi/vfs/VfsUtilTest.java b/platform/platform-tests/testSrc/com/intellij/openapi/vfs/VfsUtilTest.java index 793dec78d800..b3d28428e2bb 100644 --- a/platform/platform-tests/testSrc/com/intellij/openapi/vfs/VfsUtilTest.java +++ b/platform/platform-tests/testSrc/com/intellij/openapi/vfs/VfsUtilTest.java @@ -26,8 +26,6 @@ import java.util.Arrays; import java.util.Collections; import java.util.List; -import static org.junit.Assert.*; - public class VfsUtilTest extends BareTestFixtureTestCase { @Rule public TempDirectory myTempDir = new TempDirectory(); diff --git a/platform/platform-tests/testSrc/com/intellij/openapi/vfs/VirtualFileListenerTest.java b/platform/platform-tests/testSrc/com/intellij/openapi/vfs/VirtualFileListenerTest.java index 2892d556b74f..24307b4a2d77 100644 --- a/platform/platform-tests/testSrc/com/intellij/openapi/vfs/VirtualFileListenerTest.java +++ b/platform/platform-tests/testSrc/com/intellij/openapi/vfs/VirtualFileListenerTest.java @@ -25,9 +25,6 @@ import org.junit.Test; import java.io.IOException; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; - /** * @author nik */ diff --git a/platform/platform-tests/testSrc/com/intellij/openapi/vfs/VirtualFileVisitorTest.java b/platform/platform-tests/testSrc/com/intellij/openapi/vfs/VirtualFileVisitorTest.java index 7240d8226b27..469799a98aab 100644 --- a/platform/platform-tests/testSrc/com/intellij/openapi/vfs/VirtualFileVisitorTest.java +++ b/platform/platform-tests/testSrc/com/intellij/openapi/vfs/VirtualFileVisitorTest.java @@ -17,8 +17,6 @@ import java.util.Collections; import static com.intellij.mock.MockVirtualFile.dir; import static com.intellij.mock.MockVirtualFile.file; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; public class VirtualFileVisitorTest extends BareTestFixtureTestCase { private static VirtualFile myRoot; diff --git a/platform/platform-tests/testSrc/com/intellij/openapi/vfs/impl/VirtualFilePointerTest.java b/platform/platform-tests/testSrc/com/intellij/openapi/vfs/impl/VirtualFilePointerTest.java index a303051d1c39..d14dea764a3e 100644 --- a/platform/platform-tests/testSrc/com/intellij/openapi/vfs/impl/VirtualFilePointerTest.java +++ b/platform/platform-tests/testSrc/com/intellij/openapi/vfs/impl/VirtualFilePointerTest.java @@ -47,9 +47,7 @@ import java.util.concurrent.atomic.AtomicReference; import java.util.stream.Collectors; import java.util.stream.IntStream; -import static com.intellij.openapi.util.io.FileUtil.toSystemIndependentName; -import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.Assert.*; +import static com.intellij.testFramework.UsefulTestCase.*; /** * @author dsl @@ -59,7 +57,8 @@ public class VirtualFilePointerTest extends BareTestFixtureTestCase { private final Disposable disposable = Disposer.newDisposable(); private VirtualFilePointerManagerImpl myVirtualFilePointerManager; - private int numberOfPointersBefore, numberOfListenersBefore; + private int numberOfPointersBefore; + private int numberOfListenersBefore; @Before public void setUp() { @@ -71,7 +70,8 @@ public class VirtualFilePointerTest extends BareTestFixtureTestCase { @After public void tearDown() { Disposer.dispose(disposable); - int nPointers = myVirtualFilePointerManager.numberOfPointers(), nListeners = myVirtualFilePointerManager.numberOfListeners(); + int nPointers = myVirtualFilePointerManager.numberOfPointers(); + int nListeners = myVirtualFilePointerManager.numberOfListeners(); myVirtualFilePointerManager = null; assertEquals(numberOfPointersBefore, nPointers); assertEquals(numberOfListenersBefore, nListeners); @@ -124,7 +124,7 @@ public class VirtualFilePointerTest extends BareTestFixtureTestCase { getVirtualFile(myTempDir.getRoot()).refresh(false, true); assertTrue(fileToCreatePointer.isValid()); assertEquals("[before:false, after:true]", fileToCreateListener.log.toString()); - String expectedUrl = VirtualFileManager.constructUrl(LocalFileSystem.PROTOCOL, toSystemIndependentName(fileToCreate.getPath())); + String expectedUrl = VirtualFileManager.constructUrl(LocalFileSystem.PROTOCOL, FileUtil.toSystemIndependentName(fileToCreate.getPath())); assertEquals(expectedUrl.toUpperCase(Locale.US), fileToCreatePointer.getUrl().toUpperCase(Locale.US)); } @@ -135,8 +135,8 @@ public class VirtualFilePointerTest extends BareTestFixtureTestCase { LightVirtualFile root = new LightVirtualFile("/"); LightVirtualFile a = createLightFile(root, "a"); LightVirtualFile b = createLightFile(root, "b"); - assertThat(myVirtualFilePointerManager.getPointersUnder(a, "p1")).containsExactly(p1); - assertThat(myVirtualFilePointerManager.getPointersUnder(b, "p2")).containsExactly(p2); + assertSameElements(myVirtualFilePointerManager.getPointersUnder(a, "p1"), p1); + assertSameElements(myVirtualFilePointerManager.getPointersUnder(b, "p2"), p2); } @Test @@ -147,8 +147,8 @@ public class VirtualFilePointerTest extends BareTestFixtureTestCase { LightVirtualFile root = new LightVirtualFile("/"); LightVirtualFile a = createLightFile(root, "a"); LightVirtualFile b = createLightFile(root, "b"); - assertThat(myVirtualFilePointerManager.getPointersUnder(a, "p1")).containsExactly(p1); - assertThat(myVirtualFilePointerManager.getPointersUnder(b, "p2")).containsExactly(p2); + assertSameElements(myVirtualFilePointerManager.getPointersUnder(a, "p1"), p1); + assertSameElements(myVirtualFilePointerManager.getPointersUnder(b, "p2"), p2); } private static LightVirtualFile createLightFile(LightVirtualFile parent, String name) { @@ -283,12 +283,12 @@ public class VirtualFilePointerTest extends BareTestFixtureTestCase { public void testTwoPointersBecomeOneAfterFileRenamedUnderTheOtherName() throws IOException { File f1 = myTempDir.newFile("f1"); VirtualFile vFile1 = getVirtualFile(f1); - String url1 = VirtualFileManager.constructUrl(LocalFileSystem.PROTOCOL, toSystemIndependentName(f1.getPath())); + String url1 = VirtualFileManager.constructUrl(LocalFileSystem.PROTOCOL, FileUtil.toSystemIndependentName(f1.getPath())); LoggingListener listener1 = new LoggingListener(); VirtualFilePointer pointer1 = myVirtualFilePointerManager.create(url1, disposable, listener1); assertTrue(pointer1.isValid()); - String url2 = VirtualFileManager.constructUrl(LocalFileSystem.PROTOCOL, toSystemIndependentName(f1.getParent()) + "/f2"); + String url2 = VirtualFileManager.constructUrl(LocalFileSystem.PROTOCOL, FileUtil.toSystemIndependentName(f1.getParent()) + "/f2"); LoggingListener listener2 = new LoggingListener(); VirtualFilePointer pointer2 = myVirtualFilePointerManager.create(url2, disposable, listener2); assertFalse(pointer2.isValid()); @@ -311,8 +311,8 @@ public class VirtualFilePointerTest extends BareTestFixtureTestCase { getVirtualFile(myTempDir.getRoot()).refresh(false, true); assertTrue(fileToCreatePointer.isValid()); assertEquals("[before:false, after:true]", fileToCreateListener.log.toString()); - String expectedUrl = VirtualFileManager.constructUrl(LocalFileSystem.PROTOCOL, toSystemIndependentName(fileToCreate.getPath())); - assertThat(expectedUrl).isEqualToIgnoringCase(fileToCreatePointer.getUrl()); + String expectedUrl = VirtualFileManager.constructUrl(LocalFileSystem.PROTOCOL, FileUtil.toSystemIndependentName(fileToCreate.getPath())); + assertEquals(expectedUrl.toUpperCase(), fileToCreatePointer.getUrl().toUpperCase()); } @Test @@ -341,7 +341,7 @@ public class VirtualFilePointerTest extends BareTestFixtureTestCase { VirtualFilePointerListener listener = new LoggingListener(); VirtualFilePointer jarParentPointer = createPointerByFile(jarParent, listener); - String jarUrl = VirtualFileManager.constructUrl(JarFileSystem.PROTOCOL, toSystemIndependentName(jar.getPath()) + JarFileSystem.JAR_SEPARATOR); + String jarUrl = VirtualFileManager.constructUrl(JarFileSystem.PROTOCOL, FileUtil.toSystemIndependentName(jar.getPath()) + JarFileSystem.JAR_SEPARATOR); VirtualFilePointer jarPointer = myVirtualFilePointerManager.create(jarUrl, disposable, listener); VirtualFilePointer[] pointersToWatch = {jarParentPointer, jarPointer}; assertTrue(jarParentPointer.isValid()); @@ -353,7 +353,7 @@ public class VirtualFilePointerTest extends BareTestFixtureTestCase { verifyPointersInCorrectState(pointersToWatch); assertFalse(jarParentPointer.isValid()); assertFalse(jarPointer.isValid()); - assertThat(vTemp.getChildren()).isEmpty(); + assertEmpty(vTemp.getChildren()); assertTrue(jarParent.mkdir()); FileUtil.copy(originalJar, jar); @@ -361,7 +361,8 @@ public class VirtualFilePointerTest extends BareTestFixtureTestCase { assertTrue(jar.exists()); assertTrue(jarParent.exists()); assertTrue(jarParent.getParentFile().exists()); - assertThat(jarParent.list()).containsExactly(jar.getName()); + File child = assertOneElement(PlatformTestUtil.notNull(jarParent.listFiles())); + assertEquals(jar.getName(), child.getName()); vTemp.refresh(false, true); verifyPointersInCorrectState(pointersToWatch); assertTrue(jarParentPointer.isValid()); @@ -385,7 +386,7 @@ public class VirtualFilePointerTest extends BareTestFixtureTestCase { getVirtualFile(jar); // Make sure we receive events when jar changes VirtualFilePointerListener listener = new LoggingListener(); - String jarUrl = VirtualFileManager.constructUrl(JarFileSystem.PROTOCOL, toSystemIndependentName(jar.getPath()) + JarFileSystem.JAR_SEPARATOR); + String jarUrl = VirtualFileManager.constructUrl(JarFileSystem.PROTOCOL, FileUtil.toSystemIndependentName(jar.getPath()) + JarFileSystem.JAR_SEPARATOR); VirtualFilePointer jarPointer = myVirtualFilePointerManager.create(jarUrl, disposable, listener); VirtualFilePointer[] pointersToWatch = {jarPointer}; assertTrue(jar.delete()); @@ -571,12 +572,12 @@ public class VirtualFilePointerTest extends BareTestFixtureTestCase { VirtualFile mockVirtualFile = new MockVirtualFile("test_name", "test_text"); Disposable disposable = Disposer.newDisposable(); VirtualFilePointer pointer = myVirtualFilePointerManager.create(mockVirtualFile, disposable, null); - assertThat(pointer).isInstanceOf(IdentityVirtualFilePointer.class); + assertInstanceOf(pointer, IdentityVirtualFilePointer.class); assertTrue(pointer.isValid()); VirtualFile virtualFileWithSameUrl = new MockVirtualFile("test_name", "test_text"); VirtualFilePointer updatedPointer = myVirtualFilePointerManager.create(virtualFileWithSameUrl, disposable, null); - assertThat(updatedPointer).isInstanceOf(IdentityVirtualFilePointer.class); + assertInstanceOf(updatedPointer, IdentityVirtualFilePointer.class); assertTrue(pointer.isValid()); assertEquals(1, myVirtualFilePointerManager.numberOfCachedUrlToIdentity()); @@ -726,13 +727,16 @@ public class VirtualFilePointerTest extends BareTestFixtureTestCase { } private VirtualFilePointer createPointerByFile(File file, VirtualFilePointerListener fileListener) { - String url = VirtualFileManager.constructUrl(LocalFileSystem.PROTOCOL, toSystemIndependentName(file.getPath())); + String url = VirtualFileManager.constructUrl(LocalFileSystem.PROTOCOL, FileUtil.toSystemIndependentName(file.getPath())); VirtualFile vFile = getVirtualFile(file); return vFile != null ? myVirtualFilePointerManager.create(vFile, disposable, fileListener) : myVirtualFilePointerManager.create(url, disposable, fileListener); } private static void verifyPointersInCorrectState(VirtualFilePointer[] pointers) { - assertThat(pointers).allMatch(p -> p.getFile() == null || p.getFile().isValid()); + for (VirtualFilePointer pointer : pointers) { + final VirtualFile file = pointer.getFile(); + assertTrue(file == null || file.isValid()); + } } } \ No newline at end of file diff --git a/platform/platform-tests/testSrc/com/intellij/openapi/vfs/local/FileWatcherTest.kt b/platform/platform-tests/testSrc/com/intellij/openapi/vfs/local/FileWatcherTest.kt index 803f77357503..9c507841ad85 100644 --- a/platform/platform-tests/testSrc/com/intellij/openapi/vfs/local/FileWatcherTest.kt +++ b/platform/platform-tests/testSrc/com/intellij/openapi/vfs/local/FileWatcherTest.kt @@ -42,8 +42,6 @@ import java.nio.file.Files import java.nio.file.Paths import java.util.* import java.util.concurrent.atomic.AtomicBoolean -import kotlin.test.assertEquals -import kotlin.test.assertFalse import kotlin.test.assertTrue class FileWatcherTest : BareTestFixtureTestCase() { 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 3e8725717b8d..8570e369859a 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 @@ -20,6 +20,7 @@ import com.intellij.testFramework.PlatformTestUtil; import com.intellij.testFramework.fixtures.BareTestFixtureTestCase; import com.intellij.testFramework.rules.TempDirectory; import com.intellij.util.SystemProperties; +import com.intellij.util.containers.ContainerUtil; import org.jetbrains.annotations.NotNull; import org.junit.Rule; import org.junit.Test; @@ -35,12 +36,11 @@ import java.util.concurrent.Future; import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeoutException; import java.util.jar.JarFile; -import java.util.stream.Stream; import static com.intellij.openapi.util.io.IoTestUtil.assertTimestampsEqual; import static com.intellij.testFramework.PlatformTestUtil.assertPathsEqual; -import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.Assert.*; +import static com.intellij.testFramework.UsefulTestCase.assertOneElement; +import static com.intellij.testFramework.UsefulTestCase.assertSameElements; public class JarFileSystemTest extends BareTestFixtureTestCase { @Rule public TempDirectory tempDir = new TempDirectory(); @@ -92,7 +92,8 @@ public class JarFileSystemTest extends BareTestFixtureTestCase { assertNotNull(vFile); VirtualFile jarRoot = findByPath(jar.getPath() + JarFileSystem.JAR_SEPARATOR); - assertThat(Stream.of(jarRoot.getChildren()).map(VirtualFile::getName)).containsExactly("META-INF"); + VirtualFile child = assertOneElement(jarRoot.getChildren()); + assertEquals("META-INF", child.getName()); VirtualFile entry = findByPath(jar.getPath() + JarFileSystem.JAR_SEPARATOR + JarFile.MANIFEST_NAME); assertEquals("", VfsUtilCore.loadText(entry)); @@ -119,7 +120,10 @@ public class JarFileSystemTest extends BareTestFixtureTestCase { assertTrue(updated.get()); assertTrue(entry.isValid()); assertEquals("update", VfsUtilCore.loadText(entry)); - assertThat(Stream.of(jarRoot.getChildren()).map(VirtualFile::getName)).containsExactlyInAnyOrder("META-INF", "some.txt"); + List children = ContainerUtil.map(jarRoot.getChildren(), f -> f.getName()); + assertEquals(2, children.size()); + assertSameElements(children, "META-INF", "some.txt"); + VirtualFile newEntry = findByPath(jar.getPath() + JarFileSystem.JAR_SEPARATOR + "some.txt"); assertEquals("some text", VfsUtilCore.loadText(newEntry)); } @@ -259,7 +263,9 @@ public class JarFileSystemTest extends BareTestFixtureTestCase { VirtualFile small1 = jarRoot.findChild("small1"); VirtualFile small2 = jarRoot.findChild("small2"); VirtualFile large = jarRoot.findChild("large"); - try (InputStream is1 = small1.getInputStream(); InputStream is2 = small2.getInputStream(); InputStream il = large.getInputStream()) { + try (InputStream is1 = small1.getInputStream(); + InputStream is2 = small2.getInputStream(); + InputStream il = large.getInputStream()) { assertSame(is1.getClass(), is2.getClass()); assertNotSame(is1.getClass(), il.getClass()); } diff --git a/platform/platform-tests/testSrc/com/intellij/openapi/vfs/local/LocalFileSystemTest.java b/platform/platform-tests/testSrc/com/intellij/openapi/vfs/local/LocalFileSystemTest.java index 9c7e0c0202fb..7bb271deef9f 100644 --- a/platform/platform-tests/testSrc/com/intellij/openapi/vfs/local/LocalFileSystemTest.java +++ b/platform/platform-tests/testSrc/com/intellij/openapi/vfs/local/LocalFileSystemTest.java @@ -47,8 +47,7 @@ import java.util.Set; import static com.intellij.testFramework.EdtTestUtil.runInEdtAndGet; import static com.intellij.testFramework.EdtTestUtil.runInEdtAndWait; -import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.Assert.*; +import static com.intellij.testFramework.UsefulTestCase.*; import static org.junit.Assume.assumeFalse; import static org.junit.Assume.assumeTrue; @@ -232,7 +231,7 @@ public class LocalFileSystemTest extends BareTestFixtureTestCase { String newName = "new_temp_file"; VirtualFile copy = WriteAction.compute(() -> fileToCopy.copy(this, toVDir, newName)); assertEquals(newName, copy.getName()); - assertThat(copy.contentsToByteArray()).containsExactly(byteContent); + assertArrayEquals(copy.contentsToByteArray(), byteContent); }); } @@ -405,11 +404,11 @@ public class LocalFileSystemTest extends BareTestFixtureTestCase { assertNotNull(virtualDir); virtualDir.getChildren(); virtualDir.refresh(false, true); - assertThat(virtualDir.getChildren()).hasSize(1); + assertOneElement(virtualDir.getChildren()); FileUtil.writeToFile(new File(tempDir.getRoot(), "Bar.java"), content); virtualDir.refresh(false, true); - assertThat(virtualDir.getChildren()).hasSize(2); + assertEquals(2, virtualDir.getChildren().length); } @Test @@ -437,7 +436,7 @@ public class LocalFileSystemTest extends BareTestFixtureTestCase { File file = tempDir.newFile("test\\file.txt"); VirtualFile vDir = myFS.refreshAndFindFileByIoFile(tempDir.getRoot()); assertNotNull(vDir); - assertThat(vDir.getChildren()).isEmpty(); + assertEmpty(vDir.getChildren()); ((VirtualFileSystemEntry)vDir).markDirtyRecursively(); vDir.refresh(false, true); @@ -467,7 +466,7 @@ public class LocalFileSystemTest extends BareTestFixtureTestCase { assertNotNull(sourceFile); VirtualFile parentDir = myFS.refreshAndFindFileByIoFile(sub); assertNotNull(parentDir); - assertThat(topDir.getChildren()).hasSize(2); + assertEquals(2, topDir.getChildren().length); try { sourceFile.copy(this, parentDir, "."); @@ -486,14 +485,15 @@ public class LocalFileSystemTest extends BareTestFixtureTestCase { public void testCaseInsensitiveRename() throws IOException { File file = tempDir.newFile("file.txt"); File home = PlatformTestUtil.notNull(file.getParentFile()); - assertThat(home.list()).containsExactly("file.txt"); + assertSameElements(home.list(),"file.txt"); VirtualFile vFile = myFS.refreshAndFindFileByIoFile(file); assertNotNull(vFile); runInEdtAndWait(() -> WriteAction.run(() -> vFile.rename(LocalFileSystemTest.class, "FILE.txt"))); assertEquals("FILE.txt", vFile.getName()); - assertThat(home.list()).containsExactly("FILE.txt"); + + assertSameElements(home.list(), "FILE.txt"); } @Test @@ -558,11 +558,11 @@ public class LocalFileSystemTest extends BareTestFixtureTestCase { FileUtil.writeToFile(file2, "++"); ((NewVirtualFile)topDir).markDirtyRecursively(); topDir.refresh(false, false); - assertThat(processed).containsExactly(vFile1); // vFile2 should stay unvisited after non-recursive refresh + assertSameElements(processed, vFile1); // vFile2 should stay unvisited after non-recursive refresh processed.clear(); topDir.refresh(false, true); - assertThat(processed).containsExactly(vFile2); // vFile2 changes should be picked up by a next recursive refresh + assertSameElements(processed, vFile2); // vFile2 changes should be picked up by a next recursive refresh } finally { connection.disconnect(); @@ -650,11 +650,12 @@ public class LocalFileSystemTest extends BareTestFixtureTestCase { RefreshWorker.setCancellingCondition(file -> file.getPath().endsWith(top.getName() + "/sub_2/file_2")); topDir.refresh(false, true); - assertThat(processed.size()).isGreaterThan(0).isLessThan(files.size()); + assertNotEmpty(processed); + assertTrue(processed.size() myFS.moveFile(this, file, target)); - assertThat(srcDir.list()).isEmpty(); - assertThat(dstDir.list()).containsExactly(link.getName()); + assertEmpty(srcDir.list()); + assertSameElements(dstDir.list(), link.getName()); }); } diff --git a/platform/platform-tests/testSrc/com/intellij/openapi/vfs/local/SymlinkHandlingTest.java b/platform/platform-tests/testSrc/com/intellij/openapi/vfs/local/SymlinkHandlingTest.java index 55aa1ed617e4..8be836858492 100644 --- a/platform/platform-tests/testSrc/com/intellij/openapi/vfs/local/SymlinkHandlingTest.java +++ b/platform/platform-tests/testSrc/com/intellij/openapi/vfs/local/SymlinkHandlingTest.java @@ -35,7 +35,6 @@ import java.util.Set; import static com.intellij.openapi.util.io.IoTestUtil.*; import static com.intellij.testFramework.PlatformTestUtil.assertPathsEqual; -import static org.junit.Assert.*; import static org.junit.Assume.assumeTrue; public class SymlinkHandlingTest extends BareTestFixtureTestCase { diff --git a/platform/platform-tests/testSrc/com/intellij/util/ui/IconScaleTest.java b/platform/platform-tests/testSrc/com/intellij/util/ui/IconScaleTest.java index 1d6021e0659c..ca501f41e84f 100644 --- a/platform/platform-tests/testSrc/com/intellij/util/ui/IconScaleTest.java +++ b/platform/platform-tests/testSrc/com/intellij/util/ui/IconScaleTest.java @@ -29,8 +29,6 @@ import java.net.MalformedURLException; import static com.intellij.util.ui.JBUI.ScaleType.SYS_SCALE; import static com.intellij.util.ui.JBUI.ScaleType.USR_SCALE; import static com.intellij.util.ui.TestScaleHelper.*; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotSame; /** * Tests that {@link com.intellij.openapi.util.ScalableIcon#scale(float)} works correctly for custom JB icons. diff --git a/platform/testFramework/src/com/intellij/testFramework/VfsTestUtil.java b/platform/testFramework/src/com/intellij/testFramework/VfsTestUtil.java index 53dd89a3c691..e54ff5c50a0e 100644 --- a/platform/testFramework/src/com/intellij/testFramework/VfsTestUtil.java +++ b/platform/testFramework/src/com/intellij/testFramework/VfsTestUtil.java @@ -51,7 +51,7 @@ public class VfsTestUtil { @NotNull private static VirtualFile createFileOrDir(VirtualFile root, String relativePath, String text, boolean dir) { try { - return WriteAction.compute(() -> { + return WriteAction.computeAndWait(() -> { VirtualFile parent = root; for (String name : StringUtil.tokenize(PathUtil.getParentPath(relativePath), "/")) { VirtualFile child = parent.findChild(name); diff --git a/platform/testFramework/src/com/intellij/testFramework/fixtures/BareTestFixtureTestCase.java b/platform/testFramework/src/com/intellij/testFramework/fixtures/BareTestFixtureTestCase.java index 5171202e0273..f52b33e8fa28 100644 --- a/platform/testFramework/src/com/intellij/testFramework/fixtures/BareTestFixtureTestCase.java +++ b/platform/testFramework/src/com/intellij/testFramework/fixtures/BareTestFixtureTestCase.java @@ -12,7 +12,9 @@ import com.intellij.testFramework.SkipInHeadlessEnvironment; import com.intellij.testFramework.SkipSlowTestLocally; import com.intellij.testFramework.TestFrameworkUtil; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.TestOnly; import org.junit.After; +import org.junit.Assert; import org.junit.Before; import org.junit.Rule; import org.junit.rules.TestName; @@ -21,7 +23,8 @@ import static com.intellij.testFramework.TestFrameworkUtil.SKIP_HEADLESS; import static com.intellij.testFramework.TestFrameworkUtil.SKIP_SLOW; import static org.junit.Assume.assumeFalse; -public abstract class BareTestFixtureTestCase { +@TestOnly +public abstract class BareTestFixtureTestCase extends Assert { public static final Logger LOG = Logger.getInstance(BareTestFixtureTestCase.class); @Rule public final TestName myNameRule = new TestName();