forked from simdjson/simdjson-java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJsonValueAssert.java
More file actions
72 lines (63 loc) · 2.16 KB
/
JsonValueAssert.java
File metadata and controls
72 lines (63 loc) · 2.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
package org.simdjson;
import org.assertj.core.api.AbstractAssert;
import org.assertj.core.api.Assertions;
class JsonValueAssert extends AbstractAssert<JsonValueAssert, JsonValue> {
JsonValueAssert(JsonValue actual) {
super(actual, JsonValueAssert.class);
}
static JsonValueAssert assertThat(JsonValue actual) {
return new JsonValueAssert(actual);
}
JsonValueAssert isEqualTo(long expected) {
Assertions.assertThat(actual.isLong())
.withFailMessage("Expecting value to be long but was " + getActualType())
.isTrue();
Assertions.assertThat(actual.asLong()).isEqualTo(expected);
return this;
}
JsonValueAssert isEqualTo(Double expected) {
Assertions.assertThat(actual.isDouble())
.withFailMessage("Expecting value to be double but was " + getActualType())
.isTrue();
Assertions.assertThat(actual.asDouble()).isEqualTo(expected);
return this;
}
JsonValueAssert isEqualTo(String expected) {
Assertions.assertThat(actual.isString())
.withFailMessage("Expecting value to be string but was " + getActualType())
.isTrue();
Assertions.assertThat(actual.asString()).isEqualTo(expected);
return this;
}
JsonValueAssert isEqualTo(boolean expected) {
Assertions.assertThat(actual.isBoolean())
.withFailMessage("Expecting value to be boolean but was " + getActualType())
.isTrue();
Assertions.assertThat(actual.asBoolean()).isEqualTo(expected);
return this;
}
private String getActualType() {
if (actual.isArray()) {
return "array";
}
if (actual.isString()) {
return "string";
}
if (actual.isLong()) {
return "long";
}
if (actual.isBoolean()) {
return "boolean";
}
if (actual.isDouble()) {
return "double";
}
if (actual.isNull()) {
return "null";
}
if (actual.isObject()) {
return "object";
}
return "unknown type";
}
}