Skip to content

Commit 37bf5a9

Browse files
committed
Applying PR review suggestions
1 parent d94ff62 commit 37bf5a9

File tree

2 files changed

+15
-22
lines changed

2 files changed

+15
-22
lines changed

opamp-client/src/main/java/io/opentelemetry/opamp/client/internal/connectivity/http/HttpErrorException.java

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,28 +5,13 @@
55

66
package io.opentelemetry.opamp.client.internal.connectivity.http;
77

8-
import java.util.Objects;
9-
108
public class HttpErrorException extends Exception {
119
private final int errorCode;
1210

1311
private static final long serialVersionUID = 1L;
1412

15-
@Override
16-
public boolean equals(Object o) {
17-
if (this == o) {
18-
return true;
19-
}
20-
if (!(o instanceof HttpErrorException)) {
21-
return false;
22-
}
23-
HttpErrorException that = (HttpErrorException) o;
24-
return errorCode == that.errorCode && Objects.equals(getMessage(), that.getMessage());
25-
}
26-
27-
@Override
28-
public int hashCode() {
29-
return Objects.hash(errorCode, getMessage());
13+
public int getErrorCode() {
14+
return errorCode;
3015
}
3116

3217
/**

opamp-client/src/test/java/io/opentelemetry/opamp/client/internal/request/service/HttpRequestServiceTest.java

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
import org.junit.jupiter.api.BeforeEach;
4141
import org.junit.jupiter.api.Test;
4242
import org.junit.jupiter.api.extension.ExtendWith;
43+
import org.mockito.ArgumentCaptor;
4344
import org.mockito.InOrder;
4445
import org.mockito.Mock;
4546
import org.mockito.junit.jupiter.MockitoExtension;
@@ -181,7 +182,7 @@ void verifySendingRequest_whenThereIsAGenericHttpError() {
181182

182183
httpRequestService.run();
183184

184-
verify(callback).onRequestFailed(new HttpErrorException(500, "Error message"));
185+
verifyRequestFailedCallback(500);
185186
verifyNoInteractions(executor);
186187
}
187188

@@ -195,7 +196,7 @@ void verifySendingRequest_whenThereIsATooManyRequestsError() {
195196

196197
httpRequestService.run();
197198

198-
verify(callback).onRequestFailed(new HttpErrorException(429, "Error message"));
199+
verifyRequestFailedCallback(429);
199200
verify(executor).setPeriodicDelay(periodicRetryDelay);
200201
verify(periodicRetryDelay, never()).suggestDelay(any());
201202
}
@@ -211,7 +212,7 @@ void verifySendingRequest_whenThereIsATooManyRequestsError_withSuggestedDelay()
211212

212213
httpRequestService.run();
213214

214-
verify(callback).onRequestFailed(new HttpErrorException(429, "Error message"));
215+
verifyRequestFailedCallback(429);
215216
verify(executor).setPeriodicDelay(periodicRetryDelay);
216217
verify(periodicRetryDelay).suggestDelay(Duration.ofSeconds(5));
217218
}
@@ -267,7 +268,7 @@ void verifySendingRequest_whenThereIsAServiceUnavailableError() {
267268

268269
httpRequestService.run();
269270

270-
verify(callback).onRequestFailed(new HttpErrorException(503, "Error message"));
271+
verifyRequestFailedCallback(503);
271272
verify(executor).setPeriodicDelay(periodicRetryDelay);
272273
verify(periodicRetryDelay, never()).suggestDelay(any());
273274
}
@@ -283,11 +284,18 @@ void verifySendingRequest_whenThereIsAServiceUnavailableError_withSuggestedDelay
283284

284285
httpRequestService.run();
285286

286-
verify(callback).onRequestFailed(new HttpErrorException(503, "Error message"));
287+
verifyRequestFailedCallback(503);
287288
verify(executor).setPeriodicDelay(periodicRetryDelay);
288289
verify(periodicRetryDelay).suggestDelay(Duration.ofSeconds(2));
289290
}
290291

292+
private void verifyRequestFailedCallback(int errorCode) {
293+
ArgumentCaptor<HttpErrorException> captor = ArgumentCaptor.forClass(HttpErrorException.class);
294+
verify(callback).onRequestFailed(captor.capture());
295+
assertThat(captor.getValue().getErrorCode()).isEqualTo(errorCode);
296+
assertThat(captor.getValue().getMessage()).isEqualTo("Error message");
297+
}
298+
291299
@Test
292300
void verifySendingRequest_duringRegularMode() {
293301
httpRequestService.sendRequest();

0 commit comments

Comments
 (0)