X Tutup
Skip to content

Commit ecdc9f8

Browse files
committed
bump dependencies
1 parent 064a01e commit ecdc9f8

File tree

3 files changed

+29
-17
lines changed

3 files changed

+29
-17
lines changed

lib/build.gradle

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,13 @@ compileJava {
3434
}
3535

3636
dependencies {
37-
compile 'com.fasterxml.jackson.core:jackson-databind:2.8.4'
38-
compile 'commons-codec:commons-codec:1.10'
37+
compile 'com.fasterxml.jackson.core:jackson-databind:2.9.2'
38+
compile 'commons-codec:commons-codec:1.11'
3939
testCompile 'org.bouncycastle:bcprov-jdk15on:1.58'
4040
testCompile 'junit:junit:4.12'
41-
testCompile 'net.jodah:concurrentunit:0.4.2'
41+
testCompile 'net.jodah:concurrentunit:0.4.3'
4242
testCompile 'org.hamcrest:java-hamcrest:2.0.0.0'
43-
testCompile 'org.mockito:mockito-core:2.2.8'
43+
testCompile 'org.mockito:mockito-core:2.11.0'
4444
}
4545

4646
jacocoTestReport {

lib/src/main/java/com/auth0/jwt/impl/JsonNodeClaim.java

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import com.auth0.jwt.exceptions.JWTDecodeException;
44
import com.auth0.jwt.interfaces.Claim;
5+
import com.fasterxml.jackson.core.JsonParser;
56
import com.fasterxml.jackson.core.JsonProcessingException;
67
import com.fasterxml.jackson.core.type.TypeReference;
78
import com.fasterxml.jackson.databind.JsonNode;
@@ -66,11 +67,10 @@ public <T> T[] asArray(Class<T> tClazz) throws JWTDecodeException {
6667
return null;
6768
}
6869

69-
ObjectMapper mapper = new ObjectMapper();
7070
T[] arr = (T[]) Array.newInstance(tClazz, data.size());
7171
for (int i = 0; i < data.size(); i++) {
7272
try {
73-
arr[i] = mapper.treeToValue(data.get(i), tClazz);
73+
arr[i] = getObjectMapper().treeToValue(data.get(i), tClazz);
7474
} catch (JsonProcessingException e) {
7575
throw new JWTDecodeException("Couldn't map the Claim's array contents to " + tClazz.getSimpleName(), e);
7676
}
@@ -84,11 +84,10 @@ public <T> List<T> asList(Class<T> tClazz) throws JWTDecodeException {
8484
return null;
8585
}
8686

87-
ObjectMapper mapper = new ObjectMapper();
8887
List<T> list = new ArrayList<>();
8988
for (int i = 0; i < data.size(); i++) {
9089
try {
91-
list.add(mapper.treeToValue(data.get(i), tClazz));
90+
list.add(getObjectMapper().treeToValue(data.get(i), tClazz));
9291
} catch (JsonProcessingException e) {
9392
throw new JWTDecodeException("Couldn't map the Claim's array contents to " + tClazz.getSimpleName(), e);
9493
}
@@ -102,21 +101,21 @@ public Map<String, Object> asMap() throws JWTDecodeException {
102101
return null;
103102
}
104103

105-
ObjectMapper mapper = new ObjectMapper();
106104
try {
107105
TypeReference<Map<String, Object>> mapType = new TypeReference<Map<String, Object>>() {
108106
};
109-
return mapper.treeAsTokens(data).readValueAs(mapType);
107+
ObjectMapper thisMapper = getObjectMapper();
108+
JsonParser thisParser = thisMapper.treeAsTokens(data);
109+
return thisParser.readValueAs(mapType);
110110
} catch (IOException e) {
111111
throw new JWTDecodeException("Couldn't map the Claim value to Map", e);
112112
}
113113
}
114114

115115
@Override
116116
public <T> T as(Class<T> tClazz) throws JWTDecodeException {
117-
ObjectMapper mapper = new ObjectMapper();
118117
try {
119-
return mapper.treeAsTokens(data).readValueAs(tClazz);
118+
return getObjectMapper().treeAsTokens(data).readValueAs(tClazz);
120119
} catch (IOException e) {
121120
throw new JWTDecodeException("Couldn't map the Claim value to " + tClazz.getSimpleName(), e);
122121
}
@@ -151,4 +150,9 @@ static Claim claimFromNode(JsonNode node) {
151150
}
152151
return new JsonNodeClaim(node);
153152
}
153+
154+
//Visible for testing
155+
ObjectMapper getObjectMapper() {
156+
return new ObjectMapper();
157+
}
154158
}

lib/src/test/java/com/auth0/jwt/impl/JsonNodeClaimTest.java

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
import com.auth0.jwt.UserPojo;
44
import com.auth0.jwt.exceptions.JWTDecodeException;
55
import com.auth0.jwt.interfaces.Claim;
6+
import com.fasterxml.jackson.core.JsonParser;
7+
import com.fasterxml.jackson.core.type.TypeReference;
68
import com.fasterxml.jackson.databind.JsonNode;
79
import com.fasterxml.jackson.databind.ObjectMapper;
810
import com.fasterxml.jackson.databind.node.JsonNodeType;
@@ -14,6 +16,7 @@
1416
import org.junit.Rule;
1517
import org.junit.Test;
1618
import org.junit.rules.ExpectedException;
19+
import org.mockito.ArgumentMatchers;
1720

1821
import java.io.IOException;
1922
import java.util.*;
@@ -24,8 +27,7 @@
2427
import static org.hamcrest.core.IsNull.notNullValue;
2528
import static org.hamcrest.core.IsNull.nullValue;
2629
import static org.junit.Assert.assertThat;
27-
import static org.mockito.Mockito.mock;
28-
import static org.mockito.Mockito.when;
30+
import static org.mockito.Mockito.*;
2931

3032
public class JsonNodeClaimTest {
3133

@@ -267,11 +269,17 @@ public void shouldGetMapValue() throws Exception {
267269
public void shouldThrowIfAnExtraordinaryExceptionHappensWhenParsingAsGenericMap() throws Exception {
268270
JsonNode value = mock(ObjectNode.class);
269271
when(value.getNodeType()).thenReturn(JsonNodeType.OBJECT);
270-
when(value.fields()).thenThrow(IOException.class);
271-
Claim claim = claimFromNode(value);
272+
273+
JsonNodeClaim claim = (JsonNodeClaim) claimFromNode(value);
274+
JsonNodeClaim spiedClaim = spy(claim);
275+
ObjectMapper mockedMapper = mock(ObjectMapper.class);
276+
when(spiedClaim.getObjectMapper()).thenReturn(mockedMapper);
277+
JsonParser mockedParser = mock(JsonParser.class);
278+
when(mockedMapper.treeAsTokens(value)).thenReturn(mockedParser);
279+
when(mockedParser.readValueAs(ArgumentMatchers.any(TypeReference.class))).thenThrow(IOException.class);
272280

273281
exception.expect(JWTDecodeException.class);
274-
claim.asMap();
282+
spiedClaim.asMap();
275283
}
276284

277285
@Test

0 commit comments

Comments
 (0)
X Tutup