Skip to content

Commit b8c0a32

Browse files
committed
add tests for profiler provider
1 parent ebf77e1 commit b8c0a32

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
package io.sentry.asyncprofiler.provider
2+
3+
import io.sentry.ILogger
4+
import io.sentry.ISentryExecutorService
5+
import io.sentry.NoOpContinuousProfiler
6+
import io.sentry.asyncprofiler.profiling.JavaContinuousProfiler
7+
import one.profiler.AsyncProfiler
8+
import org.mockito.Mockito.mock
9+
import org.mockito.Mockito.mockStatic
10+
import kotlin.test.Test
11+
import kotlin.test.assertSame
12+
import kotlin.test.assertTrue
13+
14+
15+
class AsyncProfilerContinuousProfilerProviderTest {
16+
17+
@Test
18+
fun `provider returns JavaAsyncProfiler if AsyncProfiler can be loaded`() {
19+
val profiler = AsyncProfilerContinuousProfilerProvider().getContinuousProfiler(
20+
mock(ILogger::class.java),
21+
"",
22+
10,
23+
mock(ISentryExecutorService::class.java)
24+
)
25+
26+
assertTrue(profiler is JavaContinuousProfiler)
27+
}
28+
29+
@Test
30+
fun `provider return NoopProfiler if AsyncProfiler cannot be loaded`() {
31+
mockStatic(AsyncProfiler::class.java).use {
32+
it.`when`<Any> { AsyncProfiler.getInstance() }.thenReturn(null)
33+
34+
val profiler = AsyncProfilerContinuousProfilerProvider().getContinuousProfiler(
35+
mock(ILogger::class.java),
36+
"",
37+
10,
38+
mock(ISentryExecutorService::class.java)
39+
)
40+
41+
assertSame(NoOpContinuousProfiler.getInstance(), profiler)
42+
}
43+
}
44+
}

0 commit comments

Comments
 (0)