Skip to content

Commit ca06e77

Browse files
authored
Use locally-scoped HALMapper in tests to ensure they can safely run concurrently. (#41)
1 parent d24e59d commit ca06e77

File tree

2 files changed

+37
-34
lines changed

2 files changed

+37
-34
lines changed

src/test/java/io/openapitoools/jackson/dataformat/hal/deser/HALBeanDeserializerJsonViewIT.java

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,21 @@
11
package io.openapitoools.jackson.dataformat.hal.deser;
22

3+
import static org.junit.jupiter.api.Assertions.assertNotNull;
4+
import static org.junit.jupiter.api.Assertions.assertNull;
5+
6+
import java.io.IOException;
7+
import java.io.StringReader;
8+
9+
import org.junit.jupiter.api.Test;
10+
311
import com.fasterxml.jackson.annotation.JsonView;
412
import com.fasterxml.jackson.databind.MapperFeature;
5-
import com.fasterxml.jackson.databind.ObjectMapper;
13+
614
import io.openapitools.jackson.dataformat.hal.HALLink;
715
import io.openapitools.jackson.dataformat.hal.HALMapper;
816
import io.openapitools.jackson.dataformat.hal.annotation.EmbeddedResource;
917
import io.openapitools.jackson.dataformat.hal.annotation.Link;
1018
import io.openapitools.jackson.dataformat.hal.annotation.Resource;
11-
import org.junit.jupiter.api.Test;
12-
13-
import java.io.StringReader;
14-
import java.net.URI;
15-
16-
import static org.junit.jupiter.api.Assertions.*;
1719

1820

1921
public class HALBeanDeserializerJsonViewIT {
@@ -101,12 +103,12 @@ public class HALBeanDeserializerJsonViewIT {
101103
",\"stateWithView2\":\"stateWithView2\"" +
102104
"}";
103105

104-
ObjectMapper om = new HALMapper();
105-
106106
@Test
107-
public void testDeserializationOfView() throws Exception {
108-
om.configure(MapperFeature.DEFAULT_VIEW_INCLUSION, false);
109-
TopResource tr = om.readerWithView(ResourceView1.class).readValue(new StringReader(HAL_DOC_VIEW), TopResource.class);
107+
public void testDeserializationOfView() throws IOException {
108+
TopResource tr = new HALMapper()
109+
.configure(MapperFeature.DEFAULT_VIEW_INCLUSION, false)
110+
.readerWithView(ResourceView1.class)
111+
.readValue(new StringReader(HAL_DOC_VIEW), TopResource.class);
110112

111113
assertNull(tr.childWithoutView);
112114
assertNull(tr.linkWithoutView);
@@ -123,9 +125,11 @@ public void testDeserializationOfView() throws Exception {
123125
}
124126

125127
@Test
126-
public void testDeserializationOfViewWithInclusion() throws Exception {
127-
om.configure(MapperFeature.DEFAULT_VIEW_INCLUSION, true);
128-
TopResource tr = om.readerWithView(ResourceView1.class).readValue(new StringReader(HAL_DOC_INCLUSIVE_VIEW), TopResource.class);
128+
public void testDeserializationOfViewWithInclusion() throws IOException {
129+
TopResource tr = new HALMapper()
130+
.configure(MapperFeature.DEFAULT_VIEW_INCLUSION, true)
131+
.readerWithView(ResourceView1.class)
132+
.readValue(new StringReader(HAL_DOC_INCLUSIVE_VIEW), TopResource.class);
129133

130134
assertNotNull(tr.childWithoutView);
131135
assertNotNull(tr.linkWithoutView);
@@ -141,8 +145,8 @@ public void testDeserializationOfViewWithInclusion() throws Exception {
141145
}
142146

143147
@Test
144-
public void testDeserializationOfNoView() throws Exception {
145-
TopResource tr = om.readValue(new StringReader(HAL_DOC_NO_VIEW), TopResource.class);
148+
public void testDeserializationOfNoView() throws IOException {
149+
TopResource tr = new HALMapper().readValue(new StringReader(HAL_DOC_NO_VIEW), TopResource.class);
146150

147151
assertNotNull(tr.childWithoutView);
148152
assertNotNull(tr.linkWithoutView);

src/test/java/io/openapitoools/jackson/dataformat/hal/ser/HALBeanSerializerJsonViewIT.java

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,29 @@
11
package io.openapitoools.jackson.dataformat.hal.ser;
22

3+
import static org.junit.jupiter.api.Assertions.assertEquals;
4+
5+
import java.net.URI;
6+
7+
import org.junit.jupiter.api.Test;
8+
39
import com.fasterxml.jackson.annotation.JsonView;
410
import com.fasterxml.jackson.databind.MapperFeature;
5-
import com.fasterxml.jackson.databind.ObjectMapper;
11+
612
import io.openapitools.jackson.dataformat.hal.HALLink;
713
import io.openapitools.jackson.dataformat.hal.HALMapper;
814
import io.openapitools.jackson.dataformat.hal.annotation.EmbeddedResource;
915
import io.openapitools.jackson.dataformat.hal.annotation.Link;
1016
import io.openapitools.jackson.dataformat.hal.annotation.Resource;
11-
import org.junit.jupiter.api.Test;
12-
13-
import java.net.URI;
14-
15-
import static org.junit.jupiter.api.Assertions.assertEquals;
1617

1718

1819
public class HALBeanSerializerJsonViewIT {
19-
20-
ObjectMapper om = new HALMapper();
21-
2220
@Test
2321
public void testSerializationOfView() throws Exception {
2422
TopResource res1 = new TopResource();
25-
26-
om.configure(MapperFeature.DEFAULT_VIEW_INCLUSION, false);
27-
String json = om.writerWithView(ResourceView1.class).writeValueAsString(res1);
23+
String json = new HALMapper()
24+
.configure(MapperFeature.DEFAULT_VIEW_INCLUSION, false)
25+
.writerWithView(ResourceView1.class)
26+
.writeValueAsString(res1);
2827
assertEquals("{" +
2928
"\"_links\":{" +
3029
"\"linkWithView1\":{" +
@@ -47,9 +46,10 @@ public void testSerializationOfView() throws Exception {
4746
@Test
4847
public void testSerializationOfViewWithInclusion() throws Exception {
4948
TopResource res1 = new TopResource();
50-
51-
om.configure(MapperFeature.DEFAULT_VIEW_INCLUSION, true);
52-
String json = om.writerWithView(ResourceView1.class).writeValueAsString(res1);
49+
String json = new HALMapper()
50+
.configure(MapperFeature.DEFAULT_VIEW_INCLUSION, true)
51+
.writerWithView(ResourceView1.class)
52+
.writeValueAsString(res1);
5353
assertEquals("{\"_links\":{" +
5454
"\"linkWithView1\":{" +
5555
"\"href\":\"/link/with/view/1\"," +
@@ -83,8 +83,7 @@ public void testSerializationOfViewWithInclusion() throws Exception {
8383
@Test
8484
public void testSerializationOfNoView() throws Exception {
8585
TopResource res1 = new TopResource();
86-
87-
String json = om.writeValueAsString(res1);
86+
String json = new HALMapper().writeValueAsString(res1);
8887
assertEquals("{\"_links\":{" +
8988
"\"linkWithView1\":{" +
9089
"\"href\":\"/link/with/view/1\"," +

0 commit comments

Comments
 (0)