forked from corda/corda
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
EG-2684 Ensure original message is logged with old-style error codes (c…
…orda#6340) * [EG-2684] Ensure original message is logged with old-style error codes * [EG-2684] Address detekt issues
- Loading branch information
Showing
2 changed files
with
36 additions
and
1 deletion.
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
34 changes: 34 additions & 0 deletions
34
common/logging/src/test/kotlin/net/corda/commmon/logging/ExceptionsErrorCodeFunctionsTest.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,34 @@ | ||
package net.corda.commmon.logging | ||
|
||
import com.natpryce.hamkrest.assertion.assertThat | ||
import com.natpryce.hamkrest.contains | ||
import net.corda.common.logging.withErrorCodeFor | ||
import org.apache.logging.log4j.Level | ||
import org.apache.logging.log4j.message.SimpleMessage | ||
import org.junit.Test | ||
import kotlin.test.assertEquals | ||
|
||
class ExceptionsErrorCodeFunctionsTest { | ||
|
||
@Test(timeout=3_000) | ||
fun `error code for message prints out message and full stack trace`() { | ||
val originalMessage = SimpleMessage("This is a test message") | ||
var previous: Exception? = null | ||
val throwables = (0..10).map { | ||
val current = TestThrowable(it, previous) | ||
previous = current | ||
current | ||
} | ||
val exception = throwables.last() | ||
val message = originalMessage.withErrorCodeFor(exception, Level.ERROR) | ||
assertThat(message.formattedMessage, contains("This is a test message".toRegex())) | ||
for (i in (0..10)) { | ||
assertThat(message.formattedMessage, contains("This is exception $i".toRegex())) | ||
} | ||
assertEquals(message.format, originalMessage.format) | ||
assertEquals(message.parameters, originalMessage.parameters) | ||
assertEquals(message.throwable, originalMessage.throwable) | ||
} | ||
|
||
private class TestThrowable(index: Int, cause: Exception?) : Exception("This is exception $index", cause) | ||
} |