Skip to content

Commit

Permalink
Add tests for to/fromJson methods in PublicKeyCredentialCreationOptio…
Browse files Browse the repository at this point in the history
…ns and AssertionRequest
  • Loading branch information
emlun committed Sep 28, 2021
1 parent 08ca029 commit 84a80f8
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,14 @@ public String toCredentialsGetJson() throws JsonProcessingException {
return publicKeyCredentialRequestOptions.toCredentialsGetJson();
}

public String toJson() throws JsonProcessingException {
return "";
}

public static AssertionRequest fromJson(String json) throws JsonProcessingException {
return null;
}

public static AssertionRequestBuilder.MandatoryStages builder() {
return new AssertionRequestBuilder.MandatoryStages();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,14 @@ public String toCredentialsCreateJson() throws JsonProcessingException {
return json.writeValueAsString(result);
}

public String toJson() throws JsonProcessingException {
return "";
}

public static PublicKeyCredentialCreationOptions fromJson(String json) throws JsonProcessingException {
return null;
}

public Optional<Long> getTimeout() {
return Optional.ofNullable(timeout);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,38 @@ class JsonIoSpec
) should equal(pkcco)
}
}

describe("has a toJson() method and a fromJson(String) factory method") {
it("which behave like a Jackson ObjectMapper.") {
forAll { req: PublicKeyCredentialCreationOptions =>
println(req)
val json1 = req.toJson
val json2 = JacksonCodecs.json.writeValueAsString(req)
json1 should equal(json2)

val parsed1 = PublicKeyCredentialCreationOptions.fromJson(json1)
val parsed2 = JacksonCodecs.json.readValue(
json2,
classOf[PublicKeyCredentialCreationOptions],
)
parsed1 should equal(parsed2)
}
}

it("which are stable over multiple serialization round-trips.") {
forAll { req: PublicKeyCredentialCreationOptions =>
println(req)
val encoded = req.toJson
val decoded = PublicKeyCredentialCreationOptions.fromJson(encoded)
val reencoded = decoded.toJson
val redecoded = PublicKeyCredentialCreationOptions.fromJson(reencoded)

decoded should equal(req)
redecoded should equal(req)
encoded should equal(reencoded)
}
}
}
}

describe("The class PublicKeyCredentialRequestOptions") {
Expand Down Expand Up @@ -413,6 +445,36 @@ class JsonIoSpec
) should equal(req.getPublicKeyCredentialRequestOptions)
}
}

describe("has a toJson() method and a fromJson(String) factory method") {
it("which behave like a Jackson ObjectMapper.") {
forAll { req: AssertionRequest =>
println(req)
val json1 = req.toJson
val json2 = JacksonCodecs.json.writeValueAsString(req)

val parsed1 = AssertionRequest.fromJson(json1)
val parsed2 =
JacksonCodecs.json.readValue(json2, classOf[AssertionRequest])
json1 should equal(json2)
parsed1 should equal(parsed2)
}
}

it("which are stable over multiple serialization round-trips.") {
forAll { req: AssertionRequest =>
println(req)
val encoded = req.toJson
val decoded = AssertionRequest.fromJson(encoded)
val reencoded = decoded.toJson
val redecoded = AssertionRequest.fromJson(reencoded)

decoded should equal(req)
redecoded should equal(req)
encoded should equal(reencoded)
}
}
}
}

}

0 comments on commit 84a80f8

Please sign in to comment.