Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public RequestMetricSummary getTotals() {
MutableDouble averageDatabaseQueryTime = new MutableDouble(0);
MutableLong databaseIntolerableQueryCount = new MutableLong(0);
MutableDouble averageDatabaseIntolerableQueryTime = new MutableDouble(0);
statistics.forEach((key, summary) -> {
statistics.forEach((_, summary) -> {
averageTime.set(addAverages(count.get(),
averageTime.get(),
summary.getCount(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,23 +47,23 @@ void addAverages() {
@Test
void mutableLong() {
MetricsUtil.MutableLong mlong = new MetricsUtil.MutableLong(1);
assertThat(mlong.get()).isEqualTo(1L);
assertThat(mlong.get()).isOne();
mlong.add(1L);
assertThat(mlong.get()).isEqualTo(2L);
mlong.set(1L);
assertThat(mlong.get()).isEqualTo(1L);
assertThat(mlong.toString()).isEqualTo("1");
assertThat(mlong.get()).isOne();
assertThat(mlong).hasToString("1");
}

@Test
void mutableDouble() {
MetricsUtil.MutableDouble mlong = new MetricsUtil.MutableDouble(1.0);
assertThat(mlong.get()).isEqualTo(1.0d);
assertThat(mlong.get()).isOne();
mlong.add(1.5d);
assertThat(mlong.get()).isEqualTo(2.5d);
mlong.set(1.0d);
assertThat(mlong.get()).isEqualTo(1.0d);
assertThat(mlong.toString()).isEqualTo("1.0");
assertThat(mlong.get()).isOne();
assertThat(mlong).hasToString("1.0");
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import org.junit.jupiter.api.Test;

import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;

class StatusCodeGroupTest {

Expand All @@ -17,14 +17,10 @@ void getName() {

@Test
void throwsWhenInvalid() {
IllegalArgumentException exception = assertThrows(IllegalArgumentException.class,
() -> StatusCodeGroup.valueOf("INVALID GROUP")
);
IllegalArgumentException exception = assertThatExceptionOfType(IllegalArgumentException.class).isThrownBy(() -> StatusCodeGroup.valueOf("INVALID GROUP")).actual();
assertThat(exception.getMessage()).startsWith("No enum constant org.cloudfoundry.identity.uaa.metrics.StatusCodeGroup.INVALID GROUP");

exception = assertThrows(IllegalArgumentException.class,
() -> StatusCodeGroup.valueOf(606)
);
exception = assertThatExceptionOfType(IllegalArgumentException.class).isThrownBy(() -> StatusCodeGroup.valueOf(606)).actual();
assertThat(exception.getMessage()).startsWith("No matching constant for [" + 606 + "]");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,19 @@ void setup() {
@Test
void getMap() {

assertThat(map.get("group")).isEqualTo("group");
assertThat(map.get("category")).isEqualTo("category");
assertThat(map.get("limit")).isEqualTo(1L);
assertThat(map.get("pattern")).isEqualTo("/**");
assertThat(map)
.containsEntry("group", "group")
.containsEntry("category", "category")
.containsEntry("limit", 1L)
.containsEntry("pattern", "/**");
}

@Test
void from() {
group = UrlGroup.from(map);
assertThat(group.getGroup()).isEqualTo("group");
assertThat(group.getCategory()).isEqualTo("category");
assertThat(group.getLimit()).isEqualTo(1L);
assertThat(group.getLimit()).isOne();
assertThat(group.getPattern()).isEqualTo("/**");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,14 @@
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;
import tools.jackson.core.JacksonException;
import tools.jackson.databind.ValueDeserializer;

import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.util.List;
import java.util.Map;

import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
import static org.assertj.core.api.Assertions.fail;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.assertj.core.api.Assertions.*;

class JsonUtilsTest {
private static final String JSON_TEST_OBJECT_STRING = "{\"pattern\":\"/pattern\",\"group\":\"group\",\"limit\":1000,\"category\":\"category\"}";
Expand Down Expand Up @@ -68,8 +64,7 @@ void readValueAsMap() {
@ParameterizedTest
@ValueSource(strings = {"{", "}", "{\"prop1\":\"abc\","})
void readValueAsMapInvalid(final String input) {
assertThatExceptionOfType(JsonUtils.JsonUtilException.class)
.isThrownBy(() -> JsonUtils.readValueAsMap(input));
assertThatThrownBy(() -> JsonUtils.readValueAsMap(input)).isInstanceOf(JsonUtils.JsonUtilException.class);
}

@Test
Expand Down Expand Up @@ -105,8 +100,7 @@ void serializeExcludingProperties() {
void serializeExcludingPropertiesInnerCallFails() {
Map<String, String> groupProperties = JsonUtils.readValue(JSON_TEST_OBJECT_STRING, new TypeReference<>() {
});
assertThatExceptionOfType(JsonUtils.JsonUtilException.class).isThrownBy(() ->
JsonUtils.serializeExcludingProperties(groupProperties, "limit.unknown"));
assertThatThrownBy(() -> JsonUtils.serializeExcludingProperties(groupProperties, "limit.unknown")).isInstanceOf(JsonUtils.JsonUtilException.class);
}

@Test
Expand Down Expand Up @@ -139,82 +133,64 @@ void cannotInstantiate() {
}

@Test
void throwsException_writeValueAsString() throws JacksonException {
JsonUtils.JsonUtilException exception = assertThrows(JsonUtils.JsonUtilException.class,
() -> JsonUtils.writeValueAsString(new Object())
);
void throwsException_writeValueAsString() throws Exception {
JsonUtils.JsonUtilException exception = assertThatExceptionOfType(JsonUtils.JsonUtilException.class).isThrownBy(() -> JsonUtils.writeValueAsString(new Object())).actual();
assertThat(exception.getMessage()).startsWith("tools.jackson.databind.exc.InvalidDefinitionException: No serializer found for class java.lang.Object");
}

@Test
void throwsException_writeValueAsBytes() throws JacksonException {
JsonUtils.JsonUtilException exception = assertThrows(JsonUtils.JsonUtilException.class,
() -> JsonUtils.writeValueAsBytes(new Object())
);
void throwsException_writeValueAsBytes() throws Exception {
JsonUtils.JsonUtilException exception = assertThatExceptionOfType(JsonUtils.JsonUtilException.class).isThrownBy(() -> JsonUtils.writeValueAsBytes(new Object())).actual();
assertThat(exception.getMessage()).startsWith("tools.jackson.databind.exc.InvalidDefinitionException: No serializer found for class java.lang.Object");
}

@Test
void throwsException_readValue() throws JacksonException {
JsonUtils.JsonUtilException exception = assertThrows(JsonUtils.JsonUtilException.class,
() -> JsonUtils.readValue("invalid json", String.class)
);
void throwsException_readValue() throws Exception {
JsonUtils.JsonUtilException exception = assertThatExceptionOfType(JsonUtils.JsonUtilException.class).isThrownBy(() -> JsonUtils.readValue("invalid json", String.class)).actual();
assertThat(exception.getMessage()).startsWith("tools.jackson.core.exc.StreamReadException: Unrecognized token 'invalid'");

exception = assertThrows(JsonUtils.JsonUtilException.class,
() -> JsonUtils.readValue("invalid json".getBytes(), String.class)
);
exception = assertThatExceptionOfType(JsonUtils.JsonUtilException.class).isThrownBy(() -> JsonUtils.readValue("invalid json".getBytes(), String.class)).actual();
assertThat(exception.getMessage()).startsWith("tools.jackson.core.exc.StreamReadException: Unrecognized token 'invalid'");

exception = assertThrows(JsonUtils.JsonUtilException.class,
() -> JsonUtils.readValue("invalid json", new TypeReference<String>() {})
);
exception = assertThatExceptionOfType(JsonUtils.JsonUtilException.class).isThrownBy(() -> JsonUtils.readValue("invalid json", new TypeReference<String>() {
})).actual();
assertThat(exception.getMessage()).startsWith("tools.jackson.core.exc.StreamReadException: Unrecognized token 'invalid'");

exception = assertThrows(JsonUtils.JsonUtilException.class,
() -> JsonUtils.readValue("invalid json".getBytes(), new TypeReference<String>() {})
);
exception = assertThatExceptionOfType(JsonUtils.JsonUtilException.class).isThrownBy(() -> JsonUtils.readValue("invalid json".getBytes(), new TypeReference<String>() {
})).actual();
assertThat(exception.getMessage()).startsWith("tools.jackson.core.exc.StreamReadException: Unrecognized token 'invalid'");
}

@Test
void throwsException_readValueAsMap() throws JacksonException {
JsonUtils.JsonUtilException exception = assertThrows(JsonUtils.JsonUtilException.class,
() -> JsonUtils.readValueAsMap("invalid json")
);
void throwsException_readValueAsMap() throws Exception {
JsonUtils.JsonUtilException exception = assertThatExceptionOfType(JsonUtils.JsonUtilException.class).isThrownBy(() -> JsonUtils.readValueAsMap("invalid json")).actual();
assertThat(exception.getMessage()).startsWith("tools.jackson.core.exc.StreamReadException: Unrecognized token 'invalid'");
}

@Test
void throwsException_convertValue() throws JacksonException {
JsonUtils.JsonUtilException exception = assertThrows(JsonUtils.JsonUtilException.class,
() -> JsonUtils.convertValue(Boolean.TRUE, Integer.class)
);
void throwsException_convertValue() throws Exception {
JsonUtils.JsonUtilException exception = assertThatExceptionOfType(JsonUtils.JsonUtilException.class).isThrownBy(() -> JsonUtils.convertValue(Boolean.TRUE, Integer.class)).actual();
assertThat(exception.getMessage()).startsWith("tools.jackson.databind.exc.MismatchedInputException: Cannot deserialize value of type `java.lang.Integer` from Boolean value");
}

@Test
void throwsException_readTree() throws JacksonException {
void throwsException_readTree() throws Exception {
assertThat(JsonUtils.readTree((String)null)).isNull();

JsonUtils.JsonUtilException exception = assertThrows(JsonUtils.JsonUtilException.class,
() -> JsonUtils.readTree("invalid json")
);
JsonUtils.JsonUtilException exception = assertThatExceptionOfType(JsonUtils.JsonUtilException.class).isThrownBy(() -> JsonUtils.readTree("invalid json")).actual();
assertThat(exception.getMessage()).startsWith("tools.jackson.core.exc.StreamReadException: Unrecognized token 'invalid'");
}

@Test
void throwsException_readTreeWithParserArg() throws JacksonException {
void throwsException_readTreeWithParserArg() throws Exception {


JsonUtils.JsonUtilException exception = assertThrows(JsonUtils.JsonUtilException.class,
() -> JsonUtils.readValue("{'valid':'json'}", SerializerTestObject.class)
);
JsonUtils.JsonUtilException exception = assertThatExceptionOfType(JsonUtils.JsonUtilException.class).isThrownBy(() -> JsonUtils.readValue("{'valid':'json'}", SerializerTestObject.class)).actual();
assertThat(exception.getMessage()).startsWith("tools.jackson.core.exc.StreamReadException: Unexpected character");
}

@Test
void readNodes() throws JacksonException {
void readNodes() throws Exception {
JsonUtils.readValue("""
{
"date": "1320105600000",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ protected <T> T doExecute(URI url, String uriTemplate, HttpMethod method, Reques
catch (AccessTokenRequiredException | OAuth2AccessDeniedException e) {
rethrow = e;
}
catch (InvalidTokenException e) {
catch (InvalidTokenException _) {
// Don't reveal the token value in case it is logged
rethrow = new OAuth2AccessDeniedException("Invalid token for client=" + getClientId());
}
Expand All @@ -148,7 +148,7 @@ protected <T> T doExecute(URI url, String uriTemplate, HttpMethod method, Reques
try {
return super.doExecute(url, uriTemplate, method, requestCallback, responseExtractor);
}
catch (InvalidTokenException e) {
catch (InvalidTokenException _) {
// Don't reveal the token value in case it is logged
rethrow = new OAuth2AccessDeniedException("Invalid token for client=" + getClientId());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ public OAuth2AccessToken refreshAccessToken(OAuth2ProtectedResourceDetails resou
try {
return retrieveToken(request, resource, form, getHeadersForTokenRequest());
}
catch (OAuth2AccessDeniedException e) {
catch (OAuth2AccessDeniedException _) {
throw getRedirectForAuthorization((AuthorizationCodeResourceDetails) resource, request);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,10 +126,10 @@ public int getRawStatusCode() throws IOException {
throw oauth2Exception;
}
}
catch (RestClientException e) {
catch (RestClientException _) {
// ignore
}
catch (HttpMessageConversionException e) {
catch (HttpMessageConversionException _) {
// ignore
}

Expand All @@ -145,7 +145,7 @@ public int getRawStatusCode() throws IOException {
// then delegate to the custom handler
errorHandler.handleError(url, method, bufferedResponse);
}
catch (InvalidTokenException ex) {
catch (InvalidTokenException _) {
// Special case: an invalid token can be renewed so tell the caller what to do
throw new AccessTokenRequiredException(resource);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ public static OAuth2AccessToken valueOf(Map<String, String> tokenParams) {
// Convert to string before parseLong, tokenParams is not always a Map<String, String> might contain Integer
expiration = Long.parseLong(String.valueOf(tokenParams.get(EXPIRES_IN)));
}
catch (NumberFormatException e) {
catch (NumberFormatException _) {
// fall through...
}
token.setExpiration(new Date(System.currentTimeMillis() + (expiration * 1000L)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public OAuth2AccessToken deserialize(JsonParser jp, DeserializationContext ctxt)
} else if (OAuth2AccessToken.EXPIRES_IN.equals(name)) {
try {
expiresIn = jp.getLongValue();
} catch (StreamReadException e) {
} catch (StreamReadException _) {
expiresIn = Long.valueOf(jp.getString());
}
} else if (OAuth2AccessToken.SCOPE.equals(name)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ public void handleError(URI url, HttpMethod method, ClientHttpResponse response)
try {
ex = ((HttpMessageConverter<OAuth2Exception>) converter).read(OAuth2Exception.class, response);
}
catch (Exception e) {
catch (Exception _) {
// ignore
continue;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ public static MetadataLocation getType(String urlOrXmlData) {
// Check if it is a valid URL
new URL(trimmedValue);
return MetadataLocation.URL;
} catch (MalformedURLException e) {
} catch (MalformedURLException _) {
//invalid URL
}
}
Expand All @@ -128,7 +128,7 @@ private static boolean validateXml(String xml) {
try {
DocumentBuilder builder = ObjectUtils.getDocumentBuilder();
builder.parse(new InputSource(new StringReader(xml)));
} catch (ParserConfigurationException | SAXException | IOException e) {
} catch (ParserConfigurationException | SAXException | IOException _) {
return false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ public static String getHostIfArgIsURL(String arg) {
try {
URL uri = new URL(arg);
return uri.getHost();
} catch (MalformedURLException ignored) {
} catch (MalformedURLException _) {
}
return arg;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public void setIssuer(String issuer) {
try {
new URL(issuer);
this.issuer = issuer;
} catch (MalformedURLException e) {
} catch (MalformedURLException _) {
throw new IllegalArgumentException("Invalid issuer format. Must be valid URL.");
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,9 @@ public void setEntityID(String entityID) {
@JsonProperty("certificate")
public void setCertificate(String certificate) {
if (hasText(certificate)) {
keys.computeIfAbsent(LEGACY_KEY_ID, k -> new SamlKey());
keys.computeIfAbsent(LEGACY_KEY_ID, _ -> new SamlKey());
}
keys.computeIfPresent(LEGACY_KEY_ID, (k, v) -> {
keys.computeIfPresent(LEGACY_KEY_ID, (_, v) -> {
v.setCertificate(certificate);
return v;
});
Expand All @@ -76,9 +76,9 @@ public void setCertificate(String certificate) {
@JsonProperty("privateKey")
public void setPrivateKey(String privateKey) {
if (hasText(privateKey)) {
keys.computeIfAbsent(LEGACY_KEY_ID, k -> new SamlKey());
keys.computeIfAbsent(LEGACY_KEY_ID, _ -> new SamlKey());
}
keys.computeIfPresent(LEGACY_KEY_ID, (k, v) -> {
keys.computeIfPresent(LEGACY_KEY_ID, (_, v) -> {
v.setKey(privateKey);
return v;
});
Expand All @@ -87,9 +87,9 @@ public void setPrivateKey(String privateKey) {
@JsonProperty("privateKeyPassword")
public void setPrivateKeyPassword(String privateKeyPassword) {
if (hasText(privateKeyPassword)) {
keys.computeIfAbsent(LEGACY_KEY_ID, k -> new SamlKey());
keys.computeIfAbsent(LEGACY_KEY_ID, _ -> new SamlKey());
}
keys.computeIfPresent(LEGACY_KEY_ID, (k, v) -> {
keys.computeIfPresent(LEGACY_KEY_ID, (_, v) -> {
v.setPassphrase(privateKeyPassword);
return v;
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.json.BasicJsonTester;
import org.springframework.test.util.ReflectionTestUtils;
import tools.jackson.core.JacksonException;

import java.lang.reflect.Field;

Expand Down Expand Up @@ -51,7 +50,7 @@ void defaultClaims() {
}

@Test
void allNulls() throws JacksonException {
void allNulls() throws Exception {
OpenIdConfiguration openIdConfiguration = new OpenIdConfiguration(null, null);

for (Field field : OpenIdConfiguration.class.getDeclaredFields()) {
Expand Down
Loading
Loading