Skip to content

Commit f3ba2d9

Browse files
committed
Minor test refactoring
1 parent 7237441 commit f3ba2d9

File tree

4 files changed

+31
-55
lines changed

4 files changed

+31
-55
lines changed

src/test/java/com/fasterxml/jackson/databind/BaseTest.java

+31
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,37 @@ protected JsonParser createParserUsingStream(JsonFactory f,
310310
return f.createParser(is);
311311
}
312312

313+
/*
314+
/**********************************************************
315+
/* JDK ser/deser
316+
/**********************************************************
317+
*/
318+
319+
protected final static byte[] jdkSerialize(Object o)
320+
{
321+
ByteArrayOutputStream bytes = new ByteArrayOutputStream(2000);
322+
try (ObjectOutputStream obOut = new ObjectOutputStream(bytes)) {
323+
obOut.writeObject(o);
324+
obOut.close();
325+
return bytes.toByteArray();
326+
} catch (IOException e) {
327+
throw new UncheckedIOException(e);
328+
}
329+
}
330+
331+
@SuppressWarnings("unchecked")
332+
protected final static <T> T jdkDeserialize(byte[] raw)
333+
{
334+
try (ObjectInputStream objIn = new ObjectInputStream(new ByteArrayInputStream(raw))) {
335+
return (T) objIn.readObject();
336+
} catch (ClassNotFoundException e) {
337+
fail("Missing class: "+e.getMessage());
338+
return null;
339+
} catch (IOException e) {
340+
throw new UncheckedIOException(e);
341+
}
342+
}
343+
313344
/*
314345
/**********************************************************
315346
/* Additional assertion methods

src/test/java/com/fasterxml/jackson/databind/TestJDKSerialization.java

-29
Original file line numberDiff line numberDiff line change
@@ -191,33 +191,4 @@ public void testTypeFactory() throws Exception
191191
t = orig.constructType(JavaType.class);
192192
assertEquals(JavaType.class, t.getRawClass());
193193
}
194-
195-
/*
196-
/**********************************************************
197-
/* Helper methods
198-
/**********************************************************
199-
*/
200-
201-
public static byte[] jdkSerialize(Object o) throws IOException
202-
{
203-
ByteArrayOutputStream bytes = new ByteArrayOutputStream(2000);
204-
ObjectOutputStream obOut = new ObjectOutputStream(bytes);
205-
obOut.writeObject(o);
206-
obOut.close();
207-
return bytes.toByteArray();
208-
}
209-
210-
@SuppressWarnings("unchecked")
211-
public static <T> T jdkDeserialize(byte[] raw) throws IOException
212-
{
213-
ObjectInputStream objIn = new ObjectInputStream(new ByteArrayInputStream(raw));
214-
try {
215-
return (T) objIn.readObject();
216-
} catch (ClassNotFoundException e) {
217-
fail("Missing class: "+e.getMessage());
218-
return null;
219-
} finally {
220-
objIn.close();
221-
}
222-
}
223194
}

src/test/java/com/fasterxml/jackson/databind/node/NodeJDKSerializationTest.java

-23
Original file line numberDiff line numberDiff line change
@@ -101,27 +101,4 @@ protected void testNodeRoundtrip(JsonNode input) throws Exception
101101
JsonNode result = jdkDeserialize(ser);
102102
assertEquals(input, result);
103103
}
104-
105-
protected byte[] jdkSerialize(Object o) throws IOException
106-
{
107-
ByteArrayOutputStream bytes = new ByteArrayOutputStream(1000);
108-
ObjectOutputStream obOut = new ObjectOutputStream(bytes);
109-
obOut.writeObject(o);
110-
obOut.close();
111-
return bytes.toByteArray();
112-
}
113-
114-
@SuppressWarnings("unchecked")
115-
protected <T> T jdkDeserialize(byte[] raw) throws IOException
116-
{
117-
ObjectInputStream objIn = new ObjectInputStream(new ByteArrayInputStream(raw));
118-
try {
119-
return (T) objIn.readObject();
120-
} catch (ClassNotFoundException e) {
121-
fail("Missing class: "+e.getMessage());
122-
return null;
123-
} finally {
124-
objIn.close();
125-
}
126-
}
127104
}

src/test/java/com/fasterxml/jackson/databind/util/LRUMapTest.java

-3
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,6 @@
22

33
import com.fasterxml.jackson.databind.BaseTest;
44

5-
import static com.fasterxml.jackson.databind.TestJDKSerialization.jdkDeserialize;
6-
import static com.fasterxml.jackson.databind.TestJDKSerialization.jdkSerialize;
7-
85
public class LRUMapTest extends BaseTest {
96

107
public void testPutGet() {

0 commit comments

Comments
 (0)