-
Notifications
You must be signed in to change notification settings - Fork 627
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix TestFactory does not close AutoCloseable objects (#3739)
* Fix TestFactory does not close AutoCloseable objects * Added test * Api dumps * Fix nested testfactory bug * Change test to assert nested test factory
- Loading branch information
Showing
7 changed files
with
76 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
...ine/src/jvmTest/kotlin/com/sksamuel/kotest/engine/factory/AutoCloseableTestFactoryTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package com.sksamuel.kotest.engine.factory | ||
|
||
import io.kotest.core.spec.style.ShouldSpec | ||
import io.kotest.core.spec.style.shouldSpec | ||
import io.kotest.matchers.shouldBe | ||
import java.util.concurrent.atomic.AtomicInteger | ||
|
||
class AutoCloseableTestFactoryTest : ShouldSpec({ | ||
include( | ||
shouldSpec { | ||
include( | ||
shouldSpec { | ||
should("close is called in nested test factory") { | ||
autoClose(FirstAutoClose) | ||
} | ||
} | ||
) | ||
should("close is called in test factory") { | ||
autoClose(SecondAutoClose) | ||
} | ||
} | ||
) | ||
should("close is called") { | ||
autoClose(ThirdAutoClose) | ||
} | ||
afterSpec { | ||
FirstAutoClose.closed shouldBe 3 | ||
SecondAutoClose.closed shouldBe 2 | ||
ThirdAutoClose.closed shouldBe 1 | ||
} | ||
}) | ||
|
||
private object FirstAutoClose : AutoCloseable { | ||
var closed = -1 | ||
|
||
override fun close() { | ||
closed = closedNumber.incrementAndGet() | ||
} | ||
} | ||
|
||
private object SecondAutoClose : AutoCloseable { | ||
var closed = -1 | ||
|
||
override fun close() { | ||
closed = closedNumber.incrementAndGet() | ||
} | ||
} | ||
|
||
private object ThirdAutoClose : AutoCloseable { | ||
var closed = -1 | ||
|
||
override fun close() { | ||
closed = closedNumber.incrementAndGet() | ||
} | ||
} | ||
|
||
private var closedNumber = AtomicInteger(0) |