mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
move ProgressReporterTest closer to the implementation
GitOrigin-RevId: 262bfe17271fcdd7678de8b6f558e6e77084bb83
This commit is contained in:
committed by
intellij-monorepo-bot
parent
3e0c1919c2
commit
5dff5028f1
Generated
+1
@@ -1076,6 +1076,7 @@
|
||||
<module fileurl="file://$PROJECT_DIR$/platform/util/jdom/intellij.platform.util.jdom.iml" filepath="$PROJECT_DIR$/platform/util/jdom/intellij.platform.util.jdom.iml" />
|
||||
<module fileurl="file://$PROJECT_DIR$/platform/util/nanoxml/intellij.platform.util.nanoxml.iml" filepath="$PROJECT_DIR$/platform/util/nanoxml/intellij.platform.util.nanoxml.iml" />
|
||||
<module fileurl="file://$PROJECT_DIR$/platform/util/progress/intellij.platform.util.progress.iml" filepath="$PROJECT_DIR$/platform/util/progress/intellij.platform.util.progress.iml" />
|
||||
<module fileurl="file://$PROJECT_DIR$/platform/util/progress/intellij.platform.util.progress.tests.iml" filepath="$PROJECT_DIR$/platform/util/progress/intellij.platform.util.progress.tests.iml" />
|
||||
<module fileurl="file://$PROJECT_DIR$/platform/util-rt/intellij.platform.util.rt.iml" filepath="$PROJECT_DIR$/platform/util-rt/intellij.platform.util.rt.iml" />
|
||||
<module fileurl="file://$PROJECT_DIR$/platform/util/rt-java8/intellij.platform.util.rt.java8.iml" filepath="$PROJECT_DIR$/platform/util/rt-java8/intellij.platform.util.rt.java8.iml" />
|
||||
<module fileurl="file://$PROJECT_DIR$/platform/util/testSrc/intellij.platform.util.tests.iml" filepath="$PROJECT_DIR$/platform/util/testSrc/intellij.platform.util.tests.iml" />
|
||||
|
||||
@@ -90,5 +90,6 @@
|
||||
<orderEntry type="module" module-name="intellij.platform.util.coroutines" scope="TEST" />
|
||||
<orderEntry type="library" scope="TEST" name="kotlin-test-assertions-core-jvm" level="project" />
|
||||
<orderEntry type="module" module-name="intellij.platform.ijent" scope="TEST" />
|
||||
<orderEntry type="module" module-name="intellij.platform.util.progress.tests" scope="TEST" />
|
||||
</component>
|
||||
</module>
|
||||
+2
-1
@@ -1,10 +1,11 @@
|
||||
// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
package com.intellij.openapi.progress
|
||||
|
||||
import com.intellij.openapi.application.ModalityState
|
||||
import com.intellij.openapi.application.asContextElement
|
||||
import com.intellij.openapi.application.impl.ModalityStateEx
|
||||
import com.intellij.platform.util.progress.impl.ProgressState
|
||||
import com.intellij.platform.util.progress.progressReporterTest
|
||||
import com.intellij.platform.util.progress.withRawProgressReporter
|
||||
import com.intellij.testFramework.common.timeoutRunBlocking
|
||||
import kotlinx.coroutines.CancellationException
|
||||
|
||||
+2
-1
@@ -1,10 +1,11 @@
|
||||
// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
package com.intellij.openapi.progress
|
||||
|
||||
import com.intellij.concurrency.currentThreadContextOrNull
|
||||
import com.intellij.openapi.application.impl.ModalityStateEx
|
||||
import com.intellij.platform.util.progress.impl.ProgressState
|
||||
import com.intellij.platform.util.progress.progressReporter
|
||||
import com.intellij.platform.util.progress.progressReporterTest
|
||||
import com.intellij.platform.util.progress.rawProgressReporter
|
||||
import com.intellij.platform.util.progress.withRawProgressReporter
|
||||
import com.intellij.testFramework.common.timeoutRunBlocking
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module type="JAVA_MODULE" version="4">
|
||||
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
||||
<exclude-output />
|
||||
<content url="file://$MODULE_DIR$/tests">
|
||||
<sourceFolder url="file://$MODULE_DIR$/tests" isTestSource="true" packagePrefix="com.intellij.platform.util.progress" />
|
||||
</content>
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
<orderEntry type="library" scope="TEST" name="kotlin-stdlib" level="project" />
|
||||
<orderEntry type="library" scope="TEST" name="kotlinx-coroutines-core" level="project" />
|
||||
<orderEntry type="library" scope="TEST" name="JUnit5" level="project" />
|
||||
<orderEntry type="module" module-name="intellij.platform.util.progress" scope="TEST" />
|
||||
<orderEntry type="module" module-name="intellij.platform.testFramework.common" scope="TEST" />
|
||||
<orderEntry type="module" module-name="intellij.platform.util" scope="TEST" />
|
||||
<orderEntry type="module" module-name="intellij.platform.testFramework" scope="TEST" />
|
||||
</component>
|
||||
</module>
|
||||
+4
-37
@@ -1,24 +1,11 @@
|
||||
// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
package com.intellij.openapi.progress
|
||||
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
package com.intellij.platform.util.progress
|
||||
|
||||
import com.intellij.platform.util.progress.asContextElement
|
||||
import com.intellij.platform.util.progress.durationStep
|
||||
import com.intellij.platform.util.progress.impl.ACCEPTABLE_FRACTION_OVERFLOW
|
||||
import com.intellij.platform.util.progress.impl.ProgressState
|
||||
import com.intellij.platform.util.progress.impl.TextDetailsProgressReporter
|
||||
import com.intellij.platform.util.progress.indeterminateStep
|
||||
import com.intellij.platform.util.progress.itemDuration
|
||||
import com.intellij.platform.util.progress.progressReporter
|
||||
import com.intellij.platform.util.progress.progressStep
|
||||
import com.intellij.platform.util.progress.rawProgressReporter
|
||||
import com.intellij.platform.util.progress.withRawProgressReporter
|
||||
import com.intellij.testFramework.UsefulTestCase.assertOrderedEquals
|
||||
import com.intellij.testFramework.common.timeoutRunBlocking
|
||||
import com.intellij.util.containers.ContainerUtil
|
||||
import com.intellij.util.containers.init
|
||||
import com.intellij.util.containers.tail
|
||||
import kotlinx.coroutines.*
|
||||
import org.junit.jupiter.api.Assertions.*
|
||||
import org.junit.jupiter.api.Assertions.assertTrue
|
||||
import org.junit.jupiter.api.Assertions.fail
|
||||
import org.junit.jupiter.api.Test
|
||||
|
||||
class ProgressReporterTest {
|
||||
@@ -803,23 +790,3 @@ class ProgressReporterTest {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
internal fun progressReporterTest(
|
||||
vararg expectedUpdates: ProgressState,
|
||||
action: suspend CoroutineScope.() -> Unit,
|
||||
) = timeoutRunBlocking {
|
||||
val actualUpdates = ContainerUtil.createConcurrentList<ProgressState>()
|
||||
val progressReporter = TextDetailsProgressReporter(this)
|
||||
val collector = launch(Dispatchers.Unconfined + CoroutineName("state collector")) {
|
||||
progressReporter.progressState.collect { state ->
|
||||
actualUpdates.add(state)
|
||||
}
|
||||
}
|
||||
withContext(progressReporter.asContextElement(), action)
|
||||
progressReporter.close()
|
||||
progressReporter.awaitCompletion()
|
||||
collector.cancelAndJoin()
|
||||
assertEquals(ProgressState(null, null, -1.0), actualUpdates.first())
|
||||
assertEquals(ProgressState(null, null, 1.0), actualUpdates.last())
|
||||
assertOrderedEquals(actualUpdates.toList().init().tail(), expectedUpdates.toList())
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
package com.intellij.platform.util.progress
|
||||
|
||||
import com.intellij.platform.util.progress.impl.ProgressState
|
||||
import com.intellij.platform.util.progress.impl.TextDetailsProgressReporter
|
||||
import com.intellij.testFramework.TestLoggerFactory
|
||||
import com.intellij.testFramework.UsefulTestCase.assertOrderedEquals
|
||||
import com.intellij.testFramework.common.timeoutRunBlocking
|
||||
import com.intellij.util.containers.ContainerUtil
|
||||
import com.intellij.util.containers.init
|
||||
import com.intellij.util.containers.tail
|
||||
import kotlinx.coroutines.*
|
||||
import org.junit.jupiter.api.Assertions.assertEquals
|
||||
import org.junit.jupiter.api.assertThrows
|
||||
|
||||
fun progressReporterTest(
|
||||
vararg expectedUpdates: ProgressState,
|
||||
action: suspend CoroutineScope.() -> Unit,
|
||||
) = timeoutRunBlocking {
|
||||
val actualUpdates = ContainerUtil.createConcurrentList<ProgressState>()
|
||||
val progressReporter = TextDetailsProgressReporter(this)
|
||||
val collector = launch(Dispatchers.Unconfined + CoroutineName("state collector")) {
|
||||
progressReporter.progressState.collect { state ->
|
||||
actualUpdates.add(state)
|
||||
}
|
||||
}
|
||||
withContext(progressReporter.asContextElement(), action)
|
||||
progressReporter.close()
|
||||
progressReporter.awaitCompletion()
|
||||
collector.cancelAndJoin()
|
||||
assertEquals(ProgressState(null, null, -1.0), actualUpdates.first())
|
||||
assertEquals(ProgressState(null, null, 1.0), actualUpdates.last())
|
||||
assertOrderedEquals(actualUpdates.toList().init().tail(), expectedUpdates.toList())
|
||||
}
|
||||
|
||||
internal inline fun <reified T : Throwable> assertLogThrows(executable: () -> Unit): T {
|
||||
return assertThrows<T> {
|
||||
val loggerError = assertThrows<TestLoggerFactory.TestLoggerAssertionError>(executable)
|
||||
throw requireNotNull(loggerError.cause)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user