Skip to content

Package: JsonbAdapterTest$1

JsonbAdapterTest$1

nameinstructionbranchcomplexitylinemethod
{...}
M: 12 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 3 C: 0
0%
M: 1 C: 0
0%

Coverage

1: /*
2: * Copyright (c) 2017, 2022 Oracle and/or its affiliates. All rights reserved.
3: *
4: * This program and the accompanying materials are made available under the
5: * terms of the Eclipse Public License v. 2.0, which is available at
6: * http://www.eclipse.org/legal/epl-2.0.
7: *
8: * This Source Code may also be made available under the following Secondary
9: * Licenses when the conditions for such availability set forth in the
10: * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
11: * version 2 with the GNU Classpath Exception, which is available at
12: * https://www.gnu.org/software/classpath/license.html.
13: *
14: * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
15: */
16:
17: /*
18: * $Id$
19: */
20:
21: package ee.jakarta.tck.json.bind.api.jsonbadapter;
22:
23: import jakarta.json.bind.Jsonb;
24: import jakarta.json.bind.JsonbBuilder;
25: import jakarta.json.bind.JsonbConfig;
26:
27: import ee.jakarta.tck.json.bind.api.model.SimpleContainer;
28: import ee.jakarta.tck.json.bind.api.model.SimpleContainerContainer;
29: import ee.jakarta.tck.json.bind.api.model.SimpleStringAdapter;
30: import org.junit.jupiter.api.Test;
31:
32: import static org.hamcrest.MatcherAssert.assertThat;
33: import static org.hamcrest.Matchers.is;
34: import static org.hamcrest.Matchers.matchesPattern;
35:
36: /**
37: * @test
38: * @sources JsonbAdapterTest.java
39: * @executeClass com.sun.ts.tests.jsonb.api.JsonbAdapterTest
40: **/
41: public class JsonbAdapterTest {
42:
43: /*
44: * @testName: testAdaptFromJson
45: *
46: * @assertion_ids: JSONB:JAVADOC:53
47: *
48: * @test_Strategy: Assert that JsonbAdapter.adaptFromJson method can be
49: * configured during object deserialization to provide conversion logic from
50: * adapted object to original
51: */
52: @Test
53: public void testAdaptFromJson() {
54: Jsonb jsonb = JsonbBuilder.create(new JsonbConfig().withAdapters(new SimpleStringAdapter()));
55: SimpleContainerContainer unmarshalledObject = jsonb
56: .fromJson("{ \"instance\" : { \"instance\" : \"Test String Adapted\" } }",
57: SimpleContainerContainer.class);
58: assertThat("Failed to use JsonbAdapter.adaptFromJson method to provide conversion logic from "
59: + "adapted object to original during object deserialization.",
60: unmarshalledObject.getInstance().getInstance(), is("Test String"));
61: }
62:
63: /*
64: * @testName: testAdaptToJson
65: *
66: * @assertion_ids: JSONB:JAVADOC:55
67: *
68: * @test_Strategy: Assert that JsonbAdapter.adaptToJson method can be
69: * configured during object serialization to provide conversion logic from
70: * original object to adapted
71: */
72: @Test
73: public void testAdaptToJson() {
74: Jsonb jsonb = JsonbBuilder.create(new JsonbConfig().withAdapters(new SimpleStringAdapter()));
75: String jsonString = jsonb.toJson(new SimpleContainerContainer() {
76: {
77: setInstance(new SimpleContainer() {
78: {
79: setInstance("Test String");
80: }
81: });
82: }
83: });
84: assertThat("Failed to use JsonbAdapter.adaptToJson method to provide conversion "
85: + "logic from original object to adapted during object serialization.",
86: jsonString,
87: matchesPattern("\\{\\s*\"instance\"\\s*:\\s*\\{\\s*\"instance\"\\s*:\\s*\"Test String Adapted\"\\s*}\\s*}"));
88: }
89: }