Skip to content

Commit ce9aff7

Browse files
oheger-boschsschuberth
authored andcommitted
test(utils): Move an unmockAll() call to an afterEach block
`UtilsTest` is going to be extended by more test cases that require mocking. Reverting the mocking centrally is safer and requires less boilerplate code than doing this in a `try`-`finally` construct for each test case. Signed-off-by: Oliver Heger <[email protected]>
1 parent 13b50b3 commit ce9aff7

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed

utils/ort/src/test/kotlin/UtilsTest.kt

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,10 @@ import org.apache.logging.log4j.kotlin.CoroutineThreadContext
4747
import org.apache.logging.log4j.kotlin.withLoggingContext
4848

4949
class UtilsTest : WordSpec({
50+
afterEach {
51+
unmockkAll()
52+
}
53+
5054
"filterVersionNames" should {
5155
"return an empty list for a blank version" {
5256
val names = listOf("dummy")
@@ -437,21 +441,17 @@ class UtilsTest : WordSpec({
437441
mockkObject(OrtProxySelector)
438442
mockkStatic(Authenticator::class)
439443

440-
try {
441-
val passwordAuth = mockk<PasswordAuthentication>()
444+
val passwordAuth = mockk<PasswordAuthentication>()
442445

443-
every {
444-
Authenticator.requestPasswordAuthentication(host, null, port, scheme, null, null)
445-
} returns passwordAuth
446+
every {
447+
Authenticator.requestPasswordAuthentication(host, null, port, scheme, null, null)
448+
} returns passwordAuth
446449

447-
requestPasswordAuthentication(host, port, scheme) shouldBe passwordAuth
450+
requestPasswordAuthentication(host, port, scheme) shouldBe passwordAuth
448451

449-
verify {
450-
OrtAuthenticator.install()
451-
OrtProxySelector.install()
452-
}
453-
} finally {
454-
unmockkAll()
452+
verify {
453+
OrtAuthenticator.install()
454+
OrtProxySelector.install()
455455
}
456456
}
457457

0 commit comments

Comments
 (0)