test(json-service): increase coverage to 100%
All checks were successful
Build, test and publish the Quarkus libraries / build (push) Successful in 2m1s

This commit is contained in:
Jorge Bornhausen 2024-12-10 17:09:35 +01:00
parent 483c5b1b57
commit fa1578f667
Signed by: jorge.bornhausen
SSH key fingerprint: SHA256:X2ootOwvCeP4FoNfmVUFIKIbhq95tAgnt7Oqg3x+lfs
2 changed files with 21 additions and 1 deletions

View file

@ -42,7 +42,7 @@
<limit>
<counter>INSTRUCTION</counter>
<value>COVEREDRATIO</value>
<minimum>0.83</minimum>
<minimum>1</minimum>
</limit>
</limits>
</rule>

View file

@ -17,6 +17,15 @@ class JsonServiceImplTest {
record TestRecord(String name, int age) {}
static class CircularReference {
CircularReference reference;
@Override
public String toString() {
return "CircularReference";
}
}
@Inject
JsonServiceImpl jsonService;
@ -29,6 +38,17 @@ class JsonServiceImplTest {
assertThat(actual).as("Json should match expected value").isEqualTo(expected);
}
@Test
void toJsonWithCircularReference() {
var circularReference = new CircularReference();
circularReference.reference = circularReference;
assertThatThrownBy(() -> jsonService.toJson(circularReference))
.as("Should throw IllegalArgumentException when input is invalid")
.isInstanceOf(IllegalArgumentException.class)
.hasMessage("Unable to write object as json String: CircularReference");
}
@Test
void fromJsonWithClass() {
var json = "{\"name\":\"John Doe\",\"age\":30}";