mirror of
https://github.com/corda/corda.git
synced 2024-12-19 21:17:58 +00:00
CORDA-3944 Clean up ExceptionsErrorCodeFunctionsTest (#6568)
* Increase timeout to provide more of an error margin, after seeing a test failure in Jenkins. * Move shared strings to constants. * Extract chain building code into recursive function.
This commit is contained in:
parent
ff5bdcb559
commit
b3a98763ea
@ -9,26 +9,32 @@ import org.junit.Test
|
|||||||
import kotlin.test.assertEquals
|
import kotlin.test.assertEquals
|
||||||
|
|
||||||
class ExceptionsErrorCodeFunctionsTest {
|
class ExceptionsErrorCodeFunctionsTest {
|
||||||
|
private companion object {
|
||||||
@Test(timeout=3_000)
|
private const val EXCEPTION_MESSAGE = "This is exception "
|
||||||
fun `error code for message prints out message and full stack trace`() {
|
private const val TEST_MESSAGE = "This is a test message"
|
||||||
val originalMessage = SimpleMessage("This is a test message")
|
private fun makeChain(previous: Exception?, ttl: Int): Exception {
|
||||||
var previous: Exception? = null
|
val current = TestThrowable(ttl, previous)
|
||||||
val throwables = (0..10).map {
|
return if (ttl == 0) {
|
||||||
val current = TestThrowable(it, previous)
|
current
|
||||||
previous = current
|
} else {
|
||||||
current
|
makeChain(current, ttl - 1)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
val exception = throwables.last()
|
}
|
||||||
|
|
||||||
|
@Test(timeout=5_000)
|
||||||
|
fun `error code for message prints out message and full stack trace`() {
|
||||||
|
val originalMessage = SimpleMessage(TEST_MESSAGE)
|
||||||
|
val exception = makeChain(null, 10)
|
||||||
val message = originalMessage.withErrorCodeFor(exception, Level.ERROR)
|
val message = originalMessage.withErrorCodeFor(exception, Level.ERROR)
|
||||||
assertThat(message.formattedMessage, contains("This is a test message".toRegex()))
|
assertThat(message.formattedMessage, contains(TEST_MESSAGE.toRegex()))
|
||||||
for (i in (0..10)) {
|
for (i in (0..10)) {
|
||||||
assertThat(message.formattedMessage, contains("This is exception $i".toRegex()))
|
assertThat(message.formattedMessage, contains("$EXCEPTION_MESSAGE $i".toRegex()))
|
||||||
}
|
}
|
||||||
assertEquals(message.format, originalMessage.format)
|
assertEquals(message.format, originalMessage.format)
|
||||||
assertEquals(message.parameters, originalMessage.parameters)
|
assertEquals(message.parameters, originalMessage.parameters)
|
||||||
assertEquals(message.throwable, originalMessage.throwable)
|
assertEquals(message.throwable, originalMessage.throwable)
|
||||||
}
|
}
|
||||||
|
|
||||||
private class TestThrowable(index: Int, cause: Exception?) : Exception("This is exception $index", cause)
|
private class TestThrowable(index: Int, cause: Exception?) : Exception("$EXCEPTION_MESSAGE $index", cause)
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user