Skip to content

Commit 79c284f

Browse files
author
rroces
committed
Fix bug : when checking a value which is a number in json, it produces a NullPointerException. Fix this.
Set version to release.
1 parent 1d5ef05 commit 79c284f

File tree

3 files changed

+10
-3
lines changed

3 files changed

+10
-3
lines changed

pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
<groupId>com.firone</groupId>
99
<artifactId>test-utils</artifactId>
10-
<version>1.9.4-SNAPSHOT</version>
10+
<version>1.9.4</version>
1111

1212
<packaging>jar</packaging>
1313
<name>test-utils</name>
@@ -24,7 +24,7 @@
2424
<developer>
2525
<id>firone</id>
2626
<name>Romain Roces</name>
27-
<email>romain.roces@gmail.com</email>
27+
<email>romain.roces+github.testutils@gmail.com</email>
2828
</developer>
2929
</developers>
3030

src/main/java/com/firone/hamcrest/json/JsonHasKeyWithValueMatcher.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ protected boolean matchesSafely(String jsonString) {
3131
}
3232
jsonNode = jsonNode.get(keyPart);
3333
}
34-
return jsonNode == null ? value == null : jsonNode.textValue().equals(value);
34+
return jsonNode == null ? value == null : jsonNode.asText().equals(value);
3535
} catch (IOException e) {
3636
return false;
3737
}

src/test/java/com/firone/hamcrest/json/JsonHasKeyWithValueMatcherTest.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,13 @@ public void can_assert_key_with_value_are_valid() {
1515
"}", jsonHasKeyWithValue("key1", "value1"));
1616
}
1717

18+
@Test
19+
public void can_assert_numbers_are_valid() {
20+
assertThat("{" +
21+
"\"key1\":555" +
22+
"}", jsonHasKeyWithValue("key1", "555"));
23+
}
24+
1825
@Test
1926
public void can_assert_multi_level_key_with_value_are_valid() {
2027
assertThat("{" +

0 commit comments

Comments
 (0)