mirror of
https://github.com/corda/corda.git
synced 2025-01-18 02:39:51 +00:00
Merge pull request #7647 from corda/bk/jd17_fixes_15_jan
ENT-11113 Test case no longer using reflection to change final modifier on node logger
This commit is contained in:
commit
4b92233cdd
@ -2,24 +2,19 @@ package net.corda.node.services.config
|
||||
|
||||
import com.typesafe.config.Config
|
||||
import com.typesafe.config.ConfigFactory
|
||||
import net.corda.node.internal.Node
|
||||
import org.assertj.core.api.Assertions.assertThatExceptionOfType
|
||||
import org.junit.After
|
||||
import org.junit.Assert
|
||||
import org.junit.Before
|
||||
import org.junit.Ignore
|
||||
import org.junit.Test
|
||||
import org.mockito.ArgumentMatchers.contains
|
||||
import org.mockito.kotlin.spy
|
||||
import org.mockito.kotlin.verify
|
||||
import org.slf4j.Logger
|
||||
import java.lang.reflect.Field
|
||||
import java.lang.reflect.Modifier
|
||||
import java.io.ByteArrayOutputStream
|
||||
import java.io.PrintStream
|
||||
import java.nio.file.Files
|
||||
import java.nio.file.Path
|
||||
import kotlin.io.path.deleteExisting
|
||||
import kotlin.io.path.div
|
||||
import kotlin.test.assertFalse
|
||||
import kotlin.test.assertTrue
|
||||
|
||||
class ConfigHelperTests {
|
||||
private var baseDir: Path? = null
|
||||
@ -70,24 +65,19 @@ class ConfigHelperTests {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Test(timeout = 300_000)
|
||||
@Ignore("TODO JDK17: Modifiers no longer supported")
|
||||
fun `bad keys are ignored and warned for`() {
|
||||
val loggerField = Node::class.java.getDeclaredField("staticLog")
|
||||
loggerField.isAccessible = true
|
||||
val modifiersField = Field::class.java.getDeclaredField("modifiers")
|
||||
modifiersField.isAccessible = true
|
||||
modifiersField.setInt(loggerField, loggerField.modifiers and Modifier.FINAL.inv())
|
||||
val originalLogger = loggerField.get(null) as Logger
|
||||
val spyLogger = spy(originalLogger)
|
||||
loggerField.set(null, spyLogger)
|
||||
|
||||
val config = loadConfig("corda_bad_key" to "2077")
|
||||
|
||||
verify(spyLogger).warn(contains("(property or environment variable) cannot be mapped to an existing Corda"))
|
||||
assertFalse(config?.hasPath("corda_bad_key") ?: true)
|
||||
|
||||
loggerField.set(null, originalLogger)
|
||||
val originalOut = System.out
|
||||
try {
|
||||
val outContent = ByteArrayOutputStream()
|
||||
System.setOut(PrintStream(outContent));
|
||||
val config = loadConfig("corda_bad_key" to "2077")
|
||||
assertTrue(outContent.toString().contains("(property or environment variable) cannot be mapped to an existing Corda"))
|
||||
assertFalse(config?.hasPath("corda_bad_key") ?: true)
|
||||
} finally {
|
||||
System.setOut(originalOut);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user