Skip to content

Commit 77c7624

Browse files
committed
refine ut
1 parent 158f8d4 commit 77c7624

File tree

1 file changed

+39
-60
lines changed
  • instrumentation/twilio-6.6/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/twilio

1 file changed

+39
-60
lines changed

instrumentation/twilio-6.6/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/twilio/TwilioClientTest.java

Lines changed: 39 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
package io.opentelemetry.javaagent.instrumentation.twilio;
77

8+
import static io.opentelemetry.api.common.AttributeKey.stringKey;
89
import static io.opentelemetry.api.trace.SpanKind.CLIENT;
910
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.equalTo;
1011
import static org.assertj.core.api.Assertions.assertThat;
@@ -24,7 +25,7 @@
2425
import com.twilio.rest.api.v2010.account.Call;
2526
import com.twilio.rest.api.v2010.account.Message;
2627
import com.twilio.type.PhoneNumber;
27-
import io.opentelemetry.api.common.AttributeKey;
28+
import io.opentelemetry.api.common.Attributes;
2829
import io.opentelemetry.instrumentation.testing.junit.AgentInstrumentationExtension;
2930
import io.opentelemetry.instrumentation.testing.junit.InstrumentationExtension;
3031
import io.opentelemetry.sdk.trace.data.StatusData;
@@ -133,7 +134,7 @@ static void tearDown() {
133134
}
134135

135136
@Test
136-
void synchronousMessage() {
137+
void synchronousMessage() {
137138
twilioRestClient = mock(TwilioRestClient.class);
138139
when(twilioRestClient.getObjectMapper()).thenReturn(new ObjectMapper());
139140
when(twilioRestClient.request(any()))
@@ -163,19 +164,16 @@ void synchronousMessage() {
163164
.hasKind(CLIENT)
164165
.hasAttributesSatisfyingExactly(
165166
equalTo(
166-
stringKey("twilio.type"),
167+
stringKey("twilio.type"),
167168
"com.twilio.rest.api.v2010.account.Message"),
168169
equalTo(
169-
AttributeKey.stringKey("twilio.account"),
170-
"AC14984e09e497506cf0d5eb59b1f6ace7"),
171-
equalTo(
172-
AttributeKey.stringKey("twilio.sid"),
173-
"MMXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"),
174-
equalTo(AttributeKey.stringKey("twilio.status"), "sent"))));
170+
stringKey("twilio.account"), "AC14984e09e497506cf0d5eb59b1f6ace7"),
171+
equalTo(stringKey("twilio.sid"), "MMXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"),
172+
equalTo(stringKey("twilio.status"), "sent"))));
175173
}
176174

177175
@Test
178-
void synchronousCall() throws URISyntaxException {
176+
void synchronousCall() throws URISyntaxException {
179177
twilioRestClient = mock(TwilioRestClient.class);
180178
when(twilioRestClient.getObjectMapper()).thenReturn(new ObjectMapper());
181179
when(twilioRestClient.request(any()))
@@ -206,19 +204,15 @@ void synchronousCall() throws URISyntaxException {
206204
.hasAttributes(Attributes.empty())
207205
.hasAttributesSatisfyingExactly(
208206
equalTo(
209-
AttributeKey.stringKey("twilio.type"),
210-
"com.twilio.rest.api.v2010.account.Call"),
211-
equalTo(
212-
AttributeKey.stringKey("twilio.account"),
213-
"ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"),
207+
stringKey("twilio.type"), "com.twilio.rest.api.v2010.account.Call"),
214208
equalTo(
215-
AttributeKey.stringKey("twilio.sid"),
216-
"CAXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"),
217-
equalTo(AttributeKey.stringKey("twilio.status"), "completed"))));
209+
stringKey("twilio.account"), "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"),
210+
equalTo(stringKey("twilio.sid"), "CAXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"),
211+
equalTo(stringKey("twilio.status"), "completed"))));
218212
}
219213

220214
@Test
221-
void httpClient() throws IOException {
215+
void httpClient() throws IOException {
222216
CloseableHttpClient httpClient = mock(CloseableHttpClient.class);
223217
CloseableHttpResponse response1 = mockResponse(MESSAGE_RESPONSE_BODY, 200);
224218
when(httpClient.execute(any())).thenReturn(response1);
@@ -254,15 +248,12 @@ void httpClient() throws IOException {
254248
.hasKind(CLIENT)
255249
.hasAttributesSatisfyingExactly(
256250
equalTo(
257-
AttributeKey.stringKey("twilio.type"),
251+
stringKey("twilio.type"),
258252
"com.twilio.rest.api.v2010.account.Message"),
259253
equalTo(
260-
AttributeKey.stringKey("twilio.account"),
261-
"AC14984e09e497506cf0d5eb59b1f6ace7"),
262-
equalTo(
263-
AttributeKey.stringKey("twilio.sid"),
264-
"MMXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"),
265-
equalTo(AttributeKey.stringKey("twilio.status"), "sent"))));
254+
stringKey("twilio.account"), "AC14984e09e497506cf0d5eb59b1f6ace7"),
255+
equalTo(stringKey("twilio.sid"), "MMXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"),
256+
equalTo(stringKey("twilio.status"), "sent"))));
266257
}
267258

268259
@SuppressWarnings("CannotMockMethod")
@@ -273,7 +264,7 @@ void httpClient() throws IOException {
273264
}
274265

275266
@Test
276-
void httpClientRetry() throws IOException {
267+
void httpClientRetry() throws IOException {
277268
CloseableHttpClient httpClient = mock(CloseableHttpClient.class);
278269
CloseableHttpResponse response1 = mockResponse(ERROR_RESPONSE_BODY, 500);
279270
CloseableHttpResponse response2 = mockResponse(MESSAGE_RESPONSE_BODY, 200);
@@ -310,19 +301,16 @@ void httpClientRetry() throws IOException {
310301
.hasKind(CLIENT)
311302
.hasAttributesSatisfyingExactly(
312303
equalTo(
313-
AttributeKey.stringKey("twilio.type"),
304+
stringKey("twilio.type"),
314305
"com.twilio.rest.api.v2010.account.Message"),
315306
equalTo(
316-
AttributeKey.stringKey("twilio.account"),
317-
"AC14984e09e497506cf0d5eb59b1f6ace7"),
318-
equalTo(
319-
AttributeKey.stringKey("twilio.sid"),
320-
"MMXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"),
321-
equalTo(AttributeKey.stringKey("twilio.status"), "sent"))));
307+
stringKey("twilio.account"), "AC14984e09e497506cf0d5eb59b1f6ace7"),
308+
equalTo(stringKey("twilio.sid"), "MMXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"),
309+
equalTo(stringKey("twilio.status"), "sent"))));
322310
}
323311

324312
@Test
325-
void httpClientRetryAsync() throws Exception {
313+
void httpClientRetryAsync() throws Exception {
326314
CloseableHttpClient httpClient = mock(CloseableHttpClient.class);
327315
CloseableHttpResponse response1 = mockResponse(ERROR_RESPONSE_BODY, 500);
328316
CloseableHttpResponse response2 = mockResponse(MESSAGE_RESPONSE_BODY, 200);
@@ -367,19 +355,16 @@ void httpClientRetryAsync() throws Exception {
367355
.hasKind(CLIENT)
368356
.hasAttributesSatisfyingExactly(
369357
equalTo(
370-
AttributeKey.stringKey("twilio.type"),
358+
stringKey("twilio.type"),
371359
"com.twilio.rest.api.v2010.account.Message"),
372360
equalTo(
373-
AttributeKey.stringKey("twilio.account"),
374-
"AC14984e09e497506cf0d5eb59b1f6ace7"),
375-
equalTo(
376-
AttributeKey.stringKey("twilio.sid"),
377-
"MMXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"),
378-
equalTo(AttributeKey.stringKey("twilio.status"), "sent"))));
361+
stringKey("twilio.account"), "AC14984e09e497506cf0d5eb59b1f6ace7"),
362+
equalTo(stringKey("twilio.sid"), "MMXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"),
363+
equalTo(stringKey("twilio.status"), "sent"))));
379364
}
380365

381366
@Test
382-
void syncFailure() {
367+
void syncFailure() {
383368
twilioRestClient = mock(TwilioRestClient.class);
384369
when(twilioRestClient.getObjectMapper()).thenReturn(new ObjectMapper());
385370
when(twilioRestClient.request(any()))
@@ -416,7 +401,7 @@ void syncFailure() {
416401
}
417402

418403
@Test
419-
void rootSpan() {
404+
void rootSpan() {
420405
twilioRestClient = mock(TwilioRestClient.class);
421406
when(twilioRestClient.getObjectMapper()).thenReturn(new ObjectMapper());
422407
when(twilioRestClient.request(any()))
@@ -442,19 +427,16 @@ void rootSpan() {
442427
.hasNoParent()
443428
.hasAttributesSatisfyingExactly(
444429
equalTo(
445-
AttributeKey.stringKey("twilio.type"),
430+
stringKey("twilio.type"),
446431
"com.twilio.rest.api.v2010.account.Message"),
447432
equalTo(
448-
AttributeKey.stringKey("twilio.account"),
449-
"AC14984e09e497506cf0d5eb59b1f6ace7"),
450-
equalTo(
451-
AttributeKey.stringKey("twilio.sid"),
452-
"MMXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"),
453-
equalTo(AttributeKey.stringKey("twilio.status"), "sent"))));
433+
stringKey("twilio.account"), "AC14984e09e497506cf0d5eb59b1f6ace7"),
434+
equalTo(stringKey("twilio.sid"), "MMXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"),
435+
equalTo(stringKey("twilio.status"), "sent"))));
454436
}
455437

456438
@Test
457-
void asynchronousCall() throws Exception {
439+
void asynchronousCall() throws Exception {
458440
twilioRestClient = mock(TwilioRestClient.class);
459441
when(twilioRestClient.getObjectMapper()).thenReturn(new ObjectMapper());
460442
when(twilioRestClient.request(any()))
@@ -493,19 +475,16 @@ void asynchronousCall() throws Exception {
493475
.hasKind(CLIENT)
494476
.hasAttributesSatisfyingExactly(
495477
equalTo(
496-
AttributeKey.stringKey("twilio.type"),
478+
stringKey("twilio.type"),
497479
"com.twilio.rest.api.v2010.account.Message"),
498480
equalTo(
499-
AttributeKey.stringKey("twilio.account"),
500-
"AC14984e09e497506cf0d5eb59b1f6ace7"),
501-
equalTo(
502-
AttributeKey.stringKey("twilio.sid"),
503-
"MMXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"),
504-
equalTo(AttributeKey.stringKey("twilio.status"), "sent"))));
481+
stringKey("twilio.account"), "AC14984e09e497506cf0d5eb59b1f6ace7"),
482+
equalTo(stringKey("twilio.sid"), "MMXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"),
483+
equalTo(stringKey("twilio.status"), "sent"))));
505484
}
506485

507486
@Test
508-
void asynchronousError() {
487+
void asynchronousError() {
509488
twilioRestClient = mock(TwilioRestClient.class);
510489
when(twilioRestClient.getObjectMapper()).thenReturn(new ObjectMapper());
511490
when(twilioRestClient.request(any()))

0 commit comments

Comments
 (0)