@@ -12,8 +12,10 @@ import io.sentry.protocol.SentryTransaction
1212import io.sentry.protocol.User
1313import io.sentry.util.HintUtils
1414import org.awaitility.kotlin.await
15+ import org.mockito.Mockito
1516import java.lang.RuntimeException
1617import java.net.InetAddress
18+ import kotlin.test.AfterTest
1719import kotlin.test.Test
1820import kotlin.test.assertEquals
1921import kotlin.test.assertFalse
@@ -32,10 +34,12 @@ class MainEventProcessorTest {
3234 }
3335 val getLocalhost = mock<InetAddress >()
3436 val sentryTracer = SentryTracer (TransactionContext (" " , " " ), mock())
37+ private val hostnameCacheMock = Mockito .mockStatic(HostnameCache ::class .java)
3538
3639 fun getSut (attachThreads : Boolean = true, attachStackTrace : Boolean = true, environment : String? = "environment", tags : Map <String , String > = emptyMap(), sendDefaultPii : Boolean? = null, serverName : String? = "server", host : String? = null, resolveHostDelay : Long? = null, hostnameCacheDuration : Long = 10, proguardUuid : String? = null): MainEventProcessor {
3740 sentryOptions.isAttachThreads = attachThreads
3841 sentryOptions.isAttachStacktrace = attachStackTrace
42+ sentryOptions.isAttachServerName = true
3943 sentryOptions.environment = environment
4044 sentryOptions.serverName = serverName
4145 if (sendDefaultPii != null ) {
@@ -52,10 +56,21 @@ class MainEventProcessorTest {
5256 host
5357 }
5458 val hostnameCache = HostnameCache (hostnameCacheDuration) { getLocalhost }
55- return MainEventProcessor (sentryOptions, hostnameCache)
59+ hostnameCacheMock.`when `<Any > { HostnameCache .getInstance() }.thenReturn(hostnameCache)
60+
61+ return MainEventProcessor (sentryOptions)
62+ }
63+
64+ fun teardown () {
65+ hostnameCacheMock.close()
5666 }
5767 }
5868
69+ @AfterTest
70+ fun teardown () {
71+ fixture.teardown()
72+ }
73+
5974 private val fixture = Fixture ()
6075
6176 @Test
@@ -448,7 +463,10 @@ class MainEventProcessorTest {
448463
449464 @Test
450465 fun `when processor is closed, closes hostname cache` () {
451- val sut = fixture.getSut()
466+ val sut = fixture.getSut(serverName = null )
467+
468+ sut.process(SentryTransaction (fixture.sentryTracer), Hint ())
469+
452470 sut.close()
453471 assertNotNull(sut.hostnameCache) {
454472 assertTrue(it.isClosed())
0 commit comments