diff --git a/src/test/java/org/eclipse/yasson/adapters/AdaptersTest.java b/src/test/java/org/eclipse/yasson/adapters/AdaptersTest.java index ec929c71..54260a8d 100644 --- a/src/test/java/org/eclipse/yasson/adapters/AdaptersTest.java +++ b/src/test/java/org/eclipse/yasson/adapters/AdaptersTest.java @@ -632,14 +632,11 @@ public void testAdaptedRootType() throws Exception { } @Test - public void testCustomAdapterInEnum() throws Exception { - try (Jsonb jsonb = JsonbBuilder.create()) { + public void testCustomAdapterInEnum() { + Vegetables expected = Vegetables.TOMATO; - Vegetables expected = Vegetables.TOMATO; + String expectedJson = defaultJsonb.toJson(expected); - String expectedJson = jsonb.toJson(expected); - - assertEquals(expected, jsonb.fromJson(expectedJson, Vegetables.class)); - } + assertEquals(expected, defaultJsonb.fromJson(expectedJson, Vegetables.class)); } } diff --git a/src/test/java/org/eclipse/yasson/defaultmapping/generics/GenericsTest.java b/src/test/java/org/eclipse/yasson/defaultmapping/generics/GenericsTest.java index 3261c0c8..90c1f718 100644 --- a/src/test/java/org/eclipse/yasson/defaultmapping/generics/GenericsTest.java +++ b/src/test/java/org/eclipse/yasson/defaultmapping/generics/GenericsTest.java @@ -425,18 +425,16 @@ public void collectionWrapperTest() { } @Test - public void multipleGenericLevels() throws Exception { + public void multipleGenericLevels() { FinalMember member = new FinalMember(); member.setName("Jason"); FinalGenericWrapper concreteContainer = new FinalGenericWrapper(); concreteContainer.setMember(member); String expected = "{\"member\":{\"name\":\"Jason\"}}"; - try (Jsonb jsonb = JsonbBuilder.create()) { - assertEquals(expected, jsonb.toJson(concreteContainer)); - FinalGenericWrapper finalGenericWrapper = jsonb.fromJson(expected, FinalGenericWrapper.class); - assertEquals(concreteContainer, finalGenericWrapper); - } + assertEquals(expected, defaultJsonb.toJson(concreteContainer)); + FinalGenericWrapper finalGenericWrapper = defaultJsonb.fromJson(expected, FinalGenericWrapper.class); + assertEquals(concreteContainer, finalGenericWrapper); } @Test @@ -451,18 +449,16 @@ public void lowerBoundTypeVariableInCollectionAttribute() throws Exception { List> asList = List.of(anotherGenericTestClass); - try (Jsonb jsonb = JsonbBuilder.create()) { - String toJson = jsonb.toJson(asList); + String toJson = defaultJsonb.toJson(asList); - Field field = LowerBoundTypeVariableWithCollectionAttributeClass.class.getDeclaredField("value"); + Field field = LowerBoundTypeVariableWithCollectionAttributeClass.class.getDeclaredField("value"); - Type genericType = field.getGenericType(); + Type genericType = field.getGenericType(); - List> fromJson = jsonb.fromJson(toJson, genericType); + List> fromJson = defaultJsonb.fromJson(toJson, genericType); - assertEquals(5, fromJson.get(0).field2.getArea()); - assertEquals(6, fromJson.get(0).field1); - } + assertEquals(5, fromJson.get(0).field2.getArea()); + assertEquals(6, fromJson.get(0).field1); } public interface FunctionalInterface { diff --git a/src/test/java/org/eclipse/yasson/serializers/SerializersTest.java b/src/test/java/org/eclipse/yasson/serializers/SerializersTest.java index 18c2e057..5d63c138 100644 --- a/src/test/java/org/eclipse/yasson/serializers/SerializersTest.java +++ b/src/test/java/org/eclipse/yasson/serializers/SerializersTest.java @@ -541,18 +541,16 @@ public void testSerializeMapWithNullsForceArraySerializer() throws Exception { * Map shall be stored as a single JsonObject with keys as object properties names. */ @Test - public void testSerializeMapToJsonObject() throws Exception { + public void testSerializeMapToJsonObject() { Map map = new HashMap<>(); - try (Jsonb jsonb = JsonbBuilder.create(new JsonbConfig())) { - map.put("name", "John SMith"); - map.put("age", 35); - map.put("married", true); - String json = jsonb.toJson(map); - JsonObject jobj = Json.createReader(new StringReader(json)).read().asJsonObject(); - assertEquals("John SMith", jobj.getString("name")); - assertEquals(35, jobj.getInt("age")); - assertTrue(jobj.getBoolean("married")); - } + map.put("name", "John SMith"); + map.put("age", 35); + map.put("married", true); + String json = defaultJsonb.toJson(map); + JsonObject jobj = Json.createReader(new StringReader(json)).read().asJsonObject(); + assertEquals("John SMith", jobj.getString("name")); + assertEquals(35, jobj.getInt("age")); + assertTrue(jobj.getBoolean("married")); } @Test @@ -876,52 +874,40 @@ public void testBoxToArrayWithLambda() { } @Test - public void testCustomSerializersInContainer() throws Exception { - try (Jsonb jsonb = JsonbBuilder.create()) { - - Container expected = new Container(List.of(new Containee("k", "v"))); + public void testCustomSerializersInContainer() { + Container expected = new Container(List.of(new Containee("k", "v"))); - String expectedJson = jsonb.toJson(expected); - System.out.println(expectedJson); + String expectedJson = defaultJsonb.toJson(expected); + System.out.println(expectedJson); - assertEquals(expected, jsonb.fromJson(expectedJson, Container.class)); - } + assertEquals(expected, defaultJsonb.fromJson(expectedJson, Container.class)); } @Test - public void testCustomSerializersAndDeserializersInEnum() throws Exception { - try (Jsonb jsonb = JsonbBuilder.create()) { + public void testCustomSerializersAndDeserializersInEnum() { + Colors expected = Colors.GREEN; - Colors expected = Colors.GREEN; + String expectedJson = defaultJsonb.toJson(expected); - String expectedJson = jsonb.toJson(expected); - - assertEquals(expected, jsonb.fromJson(expectedJson, Colors.class)); - } + assertEquals(expected, defaultJsonb.fromJson(expectedJson, Colors.class)); } @Test - public void testJsonbPropertyInEnum() throws Exception { - try (Jsonb jsonb = JsonbBuilder.create()) { + public void testJsonbPropertyInEnum() { + Cars expected = Cars.FORD; - Cars expected = Cars.FORD; + String expectedJson = defaultJsonb.toJson(expected); - String expectedJson = jsonb.toJson(expected); - - assertEquals(expected, jsonb.fromJson(expectedJson, Cars.class)); - } + assertEquals(expected, defaultJsonb.fromJson(expectedJson, Cars.class)); } @Test - public void testNoJsonbPropertyInEnum() throws Exception { - try (Jsonb jsonb = JsonbBuilder.create()) { + public void testNoJsonbPropertyInEnum() { + Cars expected = Cars.FIAT; - Cars expected = Cars.FIAT; + String expectedJson = defaultJsonb.toJson(expected); - String expectedJson = jsonb.toJson(expected); - - assertEquals(expected, jsonb.fromJson(expectedJson, Cars.class)); - } + assertEquals(expected, defaultJsonb.fromJson(expectedJson, Cars.class)); } }