@@ -40,11 +40,19 @@ class SentryOkHttpInterceptorTest {
4040 whenever(hub.options).thenReturn(SentryOptions ())
4141 }
4242
43- fun getSut (isSpanActive : Boolean = true, httpStatusCode : Int = 201, responseBody : String = "success", socketPolicy : SocketPolicy = SocketPolicy .KEEP_OPEN ): OkHttpClient {
43+ fun getSut (
44+ isSpanActive : Boolean = true,
45+ httpStatusCode : Int = 201,
46+ responseBody : String = "success",
47+ socketPolicy : SocketPolicy = SocketPolicy .KEEP_OPEN
48+ ): OkHttpClient {
4449 if (isSpanActive) {
4550 whenever(hub.span).thenReturn(sentryTracer)
4651 }
47- server.enqueue(MockResponse ().setBody(responseBody).setSocketPolicy(socketPolicy).setResponseCode(httpStatusCode))
52+ server.enqueue(MockResponse ()
53+ .setBody(responseBody)
54+ .setSocketPolicy(socketPolicy)
55+ .setResponseCode(httpStatusCode))
4856 server.start()
4957 return OkHttpClient .Builder ().addInterceptor(interceptor).build()
5058 }
@@ -53,7 +61,9 @@ class SentryOkHttpInterceptorTest {
5361 private val fixture = Fixture ()
5462
5563 private val getRequest = { Request .Builder ().get().url(fixture.server.url(" /hello" )).build() }
56- private val postRequest = { Request .Builder ().post(" request-body" .toRequestBody(" text/plain" .toMediaType())).url(fixture.server.url(" /hello" )).build() }
64+ private val postRequest = { Request .Builder ().post(" request-body"
65+ .toRequestBody(" text/plain"
66+ .toMediaType())).url(fixture.server.url(" /hello" )).build() }
5767
5868 @Test
5969 fun `when there is an active span, adds sentry trace header to the request` () {
@@ -117,6 +127,7 @@ class SentryOkHttpInterceptorTest {
117127 })
118128 }
119129
130+ @SuppressWarnings(" SwallowedException" )
120131 @Test
121132 fun `adds breadcrumb when http calls results in exception` () {
122133 val chain = mock<Interceptor .Chain >()
@@ -126,19 +137,24 @@ class SentryOkHttpInterceptorTest {
126137 try {
127138 fixture.interceptor.intercept(chain)
128139 fail()
129- } catch (e: IOException ) {}
130-
140+ } catch (e: IOException ) {
141+ // ignore me
142+ }
131143 verify(fixture.hub).addBreadcrumb(check<Breadcrumb > {
132144 assertEquals(" http" , it.type)
133145 })
134146 }
135147
148+ @SuppressWarnings(" SwallowedException" )
136149 @Test
137150 fun `sets status and throwable when call results in IOException` () {
138151 val sut = fixture.getSut(socketPolicy = SocketPolicy .DISCONNECT_AT_START )
139152 try {
140153 sut.newCall(getRequest()).execute()
141- } catch (e: IOException ) {}
154+ fail()
155+ } catch (e: IOException ) {
156+ // ignore
157+ }
142158 val httpClientSpan = fixture.sentryTracer.children.first()
143159 assertEquals(SpanStatus .INTERNAL_ERROR , httpClientSpan.status)
144160 assertTrue(httpClientSpan.throwable is IOException )
0 commit comments