Skip to content

Commit

Permalink
IDE automated cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
nicmunroe committed Sep 12, 2024
1 parent 6d966da commit 84cebd3
Show file tree
Hide file tree
Showing 56 changed files with 196 additions and 199 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public ApiErrorBase(String name, String errorCode, String message, int httpStatu
}

this.metadata = (metadata.isEmpty())
? Collections.<String, Object>emptyMap()
? Collections.emptyMap()
: Collections.unmodifiableMap(new HashMap<>(metadata));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ public List<Integer> getStatusCodePriorityOrder() {
* the possibility of null being returned and have a strategy for picking a winner.
*/
public Integer determineHighestPriorityHttpStatusCode(Collection<ApiError> apiErrors) {
if (apiErrors == null || apiErrors.size() == 0) {
if (apiErrors == null || apiErrors.isEmpty()) {
return null;
}

Expand Down Expand Up @@ -368,7 +368,7 @@ public Integer determineHighestPriorityHttpStatusCode(Collection<ApiError> apiEr
logger.error(
"None of the HTTP status codes in the ApiErrors passed to determineHighestPriorityHttpStatusCode() were"
+ " found in the getStatusCodePriorityOrder() list. Offending set of http status codes (these should be "
+ "added to the getStatusCodePriorityOrder() list for this project): " + validStatusCodePossibilities
+ "added to the getStatusCodePriorityOrder() list for this project): {}", validStatusCodePossibilities
);

return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

/**
* A sample/example of some core errors that many APIs are likely to need. Any given {@link ProjectApiErrors} could
* return these as its {@link ProjectApiErrors#getCoreApiErrors()} if the error codes and messages associated with these
* return these as its {@code ProjectApiErrors#getCoreApiErrors()} if the error codes and messages associated with these
* are fine for your project (see {@link SampleProjectApiErrorsBase} for a base implementation that does exactly that).
*
* <p>In practice most organizations should copy/paste this class and customize the error codes and messages for their
Expand Down Expand Up @@ -64,7 +64,7 @@ public enum SampleCoreApiError implements ApiError {

SampleCoreApiError(int errorCode, String message, int httpStatusCode) {
this(new ApiErrorBase(
"delegated-to-enum-wrapper-" + UUID.randomUUID().toString(), errorCode, message, httpStatusCode
"delegated-to-enum-wrapper-" + UUID.randomUUID(), errorCode, message, httpStatusCode
));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
public abstract class SampleProjectApiErrorsBase extends ProjectApiErrors {

private static final List<ApiError> SAMPLE_CORE_API_ERRORS_AS_LIST =
Arrays.<ApiError>asList(SampleCoreApiError.values());
Arrays.asList(SampleCoreApiError.values());

@Override
protected List<ApiError> getCoreApiErrors() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -253,9 +253,9 @@ public StackTraceLoggingBehavior getStackTraceLoggingBehavior() {
*/
@SuppressWarnings("WeakerAccess")
public static class Builder {
private List<ApiError> apiErrors = new ArrayList<>();
private List<Pair<String, String>> extraDetailsForLogging = new ArrayList<>();
private List<Pair<String, List<String>>> extraResponseHeaders = new ArrayList<>();
private final List<ApiError> apiErrors = new ArrayList<>();
private final List<Pair<String, String>> extraDetailsForLogging = new ArrayList<>();
private final List<Pair<String, List<String>>> extraResponseHeaders = new ArrayList<>();
private String message;
private Throwable cause;
private StackTraceLoggingBehavior stackTraceLoggingBehavior;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -280,8 +280,7 @@ protected ErrorResponseInfo<T> doHandleApiException(
// Add connection type to our extra logging data if appropriate. This particular log message is here so it can
// be done in one spot rather than trying to track down all the different places we're handling
// NetworkExceptionBase subclasses (and possibly missing some by accident).
if (coreException instanceof NetworkExceptionBase) {
NetworkExceptionBase neb = ((NetworkExceptionBase)coreException);
if (coreException instanceof NetworkExceptionBase neb) {
extraDetailsForLogging.add(Pair.of("connection_type", neb.getConnectionType()));
}

Expand All @@ -306,7 +305,7 @@ protected ErrorResponseInfo<T> doHandleApiException(
+ "investigated and fixed. Search for %s=%s in the logs to find the log message that contains the "
+ "details of the request along with the full stack trace of the original exception. "
+ "unfiltered_api_errors=%s",
trackingLogKey, trackingUuid.toString(), utils.concatenateErrorCollection(clientErrors)
trackingLogKey, trackingUuid, utils.concatenateErrorCollection(clientErrors)
));
filteredClientErrors = Collections.singletonList(genericServiceError);
highestPriorityStatusCode = genericServiceError.getHttpStatusCode();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,9 @@ public class GenericApiExceptionHandlerListener implements ApiExceptionHandlerLi
@Override
public ApiExceptionHandlerListenerResult shouldHandleException(Throwable ex) {
// We only care about ApiExceptions.
if (!(ex instanceof ApiException))
if (!(ex instanceof ApiException apiException))
return ApiExceptionHandlerListenerResult.ignoreResponse();

ApiException apiException = ((ApiException)ex);

// Add all the ApiErrors from the exception.
SortedApiErrorSet errors = new SortedApiErrorSet();
errors.addAll(apiException.getApiErrors());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public DefaultErrorDTO(String code, String message, Map<String, Object> metadata
if (metadata == null)
metadata = Collections.emptyMap();
this.metadata = (metadata.isEmpty())
? Collections.<String, Object>emptyMap()
? Collections.emptyMap()
: Collections.unmodifiableMap(new HashMap<>(metadata));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ public static int generateApiErrorHashCode(ApiError apiError) {
public static boolean isApiErrorEqual(ApiError apiError, Object o) {
if (apiError == o) return true;
if (apiError == null) return false;
if (o == null || !(o instanceof ApiError)) return false;
ApiError that = (ApiError) o;
if (o == null || !(o instanceof ApiError that)) return false;
return apiError.getHttpStatusCode() == that.getHttpStatusCode() &&
Objects.equals(apiError.getName(), that.getName()) &&
Objects.equals(apiError.getErrorCode(), that.getErrorCode()) &&
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public void noMetadataStringErrorCodeConstructor_creates_as_expected() {

// then
assertThat(aeb.getName()).isEqualTo(name);
assertThat(aeb.getErrorCode()).isEqualTo(String.valueOf(errorCode));
assertThat(aeb.getErrorCode()).isEqualTo(errorCode);
assertThat(aeb.getMessage()).isEqualTo(message);
assertThat(aeb.getHttpStatusCode()).isEqualTo(httpStatusCode);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
* Tests the functionality of {@link com.nike.backstopper.apierror.ApiErrorComparator}
*/
public class ApiErrorComparatorTest {
private ApiErrorComparator comparator = new ApiErrorComparator();
private final ApiErrorComparator comparator = new ApiErrorComparator();

@Test
public void should_return_0_for_reference_equality() {
Expand Down Expand Up @@ -109,7 +109,7 @@ public void should_return_0_if_names_and_metadata_are_equal() {
public void should_use_hashCode_comparison_when_names_are_equal_and_metadata_is_different() {
// given
ApiError apiError = new ApiErrorBase(UUID.randomUUID().toString(), 42, "foo", 400);
ApiError errorWithMetadata = new ApiErrorWithMetadata(apiError, Pair.of("bar", (Object)UUID.randomUUID().toString()));
ApiError errorWithMetadata = new ApiErrorWithMetadata(apiError, Pair.of("bar", UUID.randomUUID().toString()));
assertThat(apiError.hashCode()).isNotEqualTo(errorWithMetadata.hashCode());

// when
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public void constructor_throws_IllegalArgumentException_if_delegate_is_null() {
@Test
public void convenience_constructor_throws_IllegalArgumentException_if_delegate_is_null() {
// when
Throwable ex = catchThrowable(() -> new ApiErrorWithMetadata(null, Pair.of("foo", (Object)"bar")));
Throwable ex = catchThrowable(() -> new ApiErrorWithMetadata(null, Pair.of("foo", "bar")));

// then
assertThat(ex)
Expand Down Expand Up @@ -152,7 +152,7 @@ public void convenience_constructor_supports_delegate_with_null_or_empty_metadat
@Test
public void constructor_supports_null_or_empty_extra_metadata(boolean useNull) {
// given
Map<String, Object> extraMetadataToUse = (useNull) ? null : Collections.<String, Object>emptyMap();
Map<String, Object> extraMetadataToUse = (useNull) ? null : Collections.emptyMap();

// when
ApiErrorWithMetadata awm = new ApiErrorWithMetadata(delegateWithMetadata, extraMetadataToUse);
Expand Down Expand Up @@ -270,7 +270,7 @@ public void equals_returns_expected_result(boolean changeName, boolean changeErr
changeMetadata? metadata2 : metadata);

ApiErrorWithMetadata awm = new ApiErrorWithMetadata(aeb, extraMetadata);
ApiErrorWithMetadata awm2 = new ApiErrorWithMetadata(aeb2, hasExtraMetadata? extraMetadata : Collections.<String, Object>emptyMap());
ApiErrorWithMetadata awm2 = new ApiErrorWithMetadata(aeb2, hasExtraMetadata? extraMetadata : Collections.emptyMap());

// then
assertThat(awm.equals(awm2)).isEqualTo(isEqual);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public void default_constructor_uses_ApiErrorComparator() {
assertThat(set).isEmpty();
}

private Random random = new Random();
private final Random random = new Random();
private ApiError generateRandomApiError() {
return new ApiErrorBase(UUID.randomUUID().toString(), random.nextInt(),
UUID.randomUUID().toString(), random.nextInt());
Expand Down Expand Up @@ -128,8 +128,8 @@ public void singletonSortedSetOf_returns_singleton_set_with_supplied_arg_and_def
public void default_config_supports_multiple_errors_that_differ_only_by_metadata() {
// given
ApiError baseError = new ApiErrorBase(UUID.randomUUID().toString(), 42, "foo", 400);
ApiError errorWithMetadata1 = new ApiErrorWithMetadata(baseError, Pair.of("foo", (Object)"bar"));
ApiError errorWithMetadata2 = new ApiErrorWithMetadata(baseError, Pair.of("foo", (Object)"notbar"));
ApiError errorWithMetadata1 = new ApiErrorWithMetadata(baseError, Pair.of("foo", "bar"));
ApiError errorWithMetadata2 = new ApiErrorWithMetadata(baseError, Pair.of("foo", "notbar"));

SortedApiErrorSet set = new SortedApiErrorSet();
assertThat(set).isEmpty();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public void determineHighestPriorityHttpStatusCodeShouldReturnNullForNullErrorCo

@Test
public void determineHighestPriorityHttpStatusCodeShouldReturnNullForEmptyErrorCollection() {
assertThat(getProjectApiErrors().determineHighestPriorityHttpStatusCode(Collections.<ApiError>emptyList()), nullValue());
assertThat(getProjectApiErrors().determineHighestPriorityHttpStatusCode(Collections.emptyList()), nullValue());
}

@Test
Expand Down Expand Up @@ -200,7 +200,7 @@ public void convertToApiErrorShouldUseFallbackOnInvalidValue() {

@Test(expected = IllegalStateException.class)
public void verifyErrorsAreInRangeShouldThrowExceptionIfListIncludesNonCoreApiErrorAndRangeIsNull() {
ProjectApiErrorsForTesting.withProjectSpecificData(Collections.<ApiError>singletonList(new ApiErrorBase("blah", 99001, "stuff", 400)), null);
ProjectApiErrorsForTesting.withProjectSpecificData(Collections.singletonList(new ApiErrorBase("blah", 99001, "stuff", 400)), null);
}

@Test
Expand All @@ -224,7 +224,7 @@ public void verifyErrorsAreInRangeShouldNotThrowExceptionIfListIncludesCoreApiEr
@Test(expected = IllegalStateException.class)
public void verifyErrorsAreInRangeShouldThrowExceptionIfListIncludesErrorOutOfRange() {
ProjectApiErrorsForTesting.withProjectSpecificData(
Collections.<ApiError>singletonList(new ApiErrorBase("blah", 1, "stuff", 400)),
Collections.singletonList(new ApiErrorBase("blah", 1, "stuff", 400)),
new ProjectSpecificErrorCodeRange() {
@Override
public boolean isInRange(ApiError error) {
Expand Down Expand Up @@ -305,11 +305,7 @@ private boolean areWrappersOfEachOther(ApiError error1, ApiError error2) {
boolean errorCodeMatches = Objects.equals(error1.getErrorCode(), error2.getErrorCode());
boolean messageMatches = Objects.equals(error1.getMessage(), error2.getMessage());
boolean httpStatusCodeMatches = error1.getHttpStatusCode() == error2.getHttpStatusCode();
if (errorCodeMatches && messageMatches && httpStatusCodeMatches) {
return true;
}

return false;
return errorCodeMatches && messageMatches && httpStatusCodeMatches;
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
@RunWith(DataProviderRunner.class)
public class IntegerRangeTest {

private IntegerRange rangeOfOneToFour = IntegerRange.of(1, 4);
private final IntegerRange rangeOfOneToFour = IntegerRange.of(1, 4);

@Test
public void constructor_throws_exception_if_upper_range_less_than_lower_range() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public enum BarebonesCoreApiErrorForTesting implements ApiError {
}

BarebonesCoreApiErrorForTesting(int errorCode, String message, int httpStatusCode) {
this(new ApiErrorBase("delegated-to-enum-wrapper-" + UUID.randomUUID().toString(), errorCode, message, httpStatusCode));
this(new ApiErrorBase("delegated-to-enum-wrapper-" + UUID.randomUUID(), errorCode, message, httpStatusCode));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
*/
public abstract class ProjectApiErrorsForTesting extends ProjectApiErrors {

private static final List<ApiError> BAREBONES_CORE_API_ERRORS_AS_LIST = Arrays.<ApiError>asList(BarebonesCoreApiErrorForTesting.values());
private static final List<ApiError> BAREBONES_CORE_API_ERRORS_AS_LIST = Arrays.asList(BarebonesCoreApiErrorForTesting.values());

public static ProjectApiErrorsForTesting withProjectSpecificData(final List<ApiError> projectSpecificErrors,
final ProjectSpecificErrorCodeRange projectSpecificErrorCodeRange) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,23 +27,23 @@
@RunWith(DataProviderRunner.class)
public class ApiExceptionTest {

private ApiError apiError1 = BarebonesCoreApiErrorForTesting.GENERIC_SERVICE_ERROR;
private ApiError apiError2 = BarebonesCoreApiErrorForTesting.SERVERSIDE_VALIDATION_ERROR;
private ApiError apiError3 = BarebonesCoreApiErrorForTesting.TYPE_CONVERSION_ERROR;
private ApiError apiError4 = BarebonesCoreApiErrorForTesting.OUTSIDE_DEPENDENCY_RETURNED_AN_UNRECOVERABLE_ERROR;
private final ApiError apiError1 = BarebonesCoreApiErrorForTesting.GENERIC_SERVICE_ERROR;
private final ApiError apiError2 = BarebonesCoreApiErrorForTesting.SERVERSIDE_VALIDATION_ERROR;
private final ApiError apiError3 = BarebonesCoreApiErrorForTesting.TYPE_CONVERSION_ERROR;
private final ApiError apiError4 = BarebonesCoreApiErrorForTesting.OUTSIDE_DEPENDENCY_RETURNED_AN_UNRECOVERABLE_ERROR;

private Pair<String, String> logPair1 = Pair.of("key1", "val1");
private Pair<String, String> logPair2 = Pair.of("key2", "val2");
private Pair<String, String> logPair3 = Pair.of("key3", "val3");
private Pair<String, String> logPair4 = Pair.of("key4", "val4");
private final Pair<String, String> logPair1 = Pair.of("key1", "val1");
private final Pair<String, String> logPair2 = Pair.of("key2", "val2");
private final Pair<String, String> logPair3 = Pair.of("key3", "val3");
private final Pair<String, String> logPair4 = Pair.of("key4", "val4");

private Pair<String, List<String>> headerPair1 = Pair.of("h1", singletonList("v1"));
private Pair<String, List<String>> headerPair2 = Pair.of("h2", Arrays.asList("v2.1", "v2.2"));
private Pair<String, List<String>> headerPair3 = Pair.of("h3", singletonList("v3"));
private Pair<String, List<String>> headerPair4 = Pair.of("h4", Arrays.asList("v4.1", "v4.2"));
private final Pair<String, List<String>> headerPair1 = Pair.of("h1", singletonList("v1"));
private final Pair<String, List<String>> headerPair2 = Pair.of("h2", Arrays.asList("v2.1", "v2.2"));
private final Pair<String, List<String>> headerPair3 = Pair.of("h3", singletonList("v3"));
private final Pair<String, List<String>> headerPair4 = Pair.of("h4", Arrays.asList("v4.1", "v4.2"));

private String exceptionMessage = "some ex msg";
private Exception cause = new Exception("intentional test exception");
private final String exceptionMessage = "some ex msg";
private final Exception cause = new Exception("intentional test exception");

@DataProvider(value = {
"true | FORCE_STACK_TRACE",
Expand Down Expand Up @@ -188,7 +188,7 @@ public void no_cause_constructors_fail_when_passed_null_or_empty_apiErrors_list(
// given
List<Pair<String, String>> logInfoList = Collections.emptyList();
List<Pair<String, List<String>>> responseHeaders = Collections.emptyList();
List<ApiError> apiErrors = (useNull) ? null : Collections.<ApiError>emptyList();
List<ApiError> apiErrors = (useNull) ? null : Collections.emptyList();

// expect
if (useConstructorWithResponseHeaders)
Expand All @@ -210,7 +210,7 @@ public void with_cause_constructors_fail_when_passed_null_or_empty_apiErrors_lis
// given
List<Pair<String, String>> logInfoList = Collections.emptyList();
List<Pair<String, List<String>>> responseHeaders = Collections.emptyList();
List<ApiError> apiErrors = (useNull) ? null : Collections.<ApiError>emptyList();
List<ApiError> apiErrors = (useNull) ? null : Collections.emptyList();

// expect
if (useConstructorWithResponseHeaders)
Expand Down
Loading

0 comments on commit 84cebd3

Please sign in to comment.