From 08f8c75ee6632719d15bc2d13ccfb7fcf609cdcb Mon Sep 17 00:00:00 2001 From: Mahmoud Ben Hassine Date: Thu, 2 Jun 2022 10:40:20 +0200 Subject: [PATCH] Add test to serialize/deserialize records in the execution context --- .../AbstractExecutionContextSerializerTests.java | 16 +++++++++++++++- ...on2ExecutionContextStringSerializerTests.java | 5 +++-- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/repository/dao/AbstractExecutionContextSerializerTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/repository/dao/AbstractExecutionContextSerializerTests.java index 268374df7..9fd16840f 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/repository/dao/AbstractExecutionContextSerializerTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/repository/dao/AbstractExecutionContextSerializerTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2021 the original author or authors. + * Copyright 2012-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -151,6 +151,17 @@ public abstract class AbstractExecutionContextSerializerTests { compareContexts(m1, m2); } + @Test + public void testSerializeRecords() throws IOException { + Map m1 = new HashMap<>(); + m1.put("foo", new Person(1, "foo")); + m1.put("bar", new Person(2, "bar")); + + Map m2 = serializationRoundTrip(m1); + + compareContexts(m1, m2); + } + @Test(expected = IllegalArgumentException.class) public void testNullSerialization() throws Exception { getSerializer().serialize(null, null); @@ -263,4 +274,7 @@ public abstract class AbstractExecutionContextSerializerTests { } + public static record Person(int id, String name) implements Serializable { + } + } diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/repository/dao/Jackson2ExecutionContextStringSerializerTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/repository/dao/Jackson2ExecutionContextStringSerializerTests.java index 6263008e6..2dc4df9a3 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/repository/dao/Jackson2ExecutionContextStringSerializerTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/repository/dao/Jackson2ExecutionContextStringSerializerTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2008-2021 the original author or authors. + * Copyright 2008-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -47,7 +47,8 @@ public class Jackson2ExecutionContextStringSerializerTests extends AbstractExecu @Before public void onSetUp() throws Exception { - Jackson2ExecutionContextStringSerializer serializerDeserializer = new Jackson2ExecutionContextStringSerializer(); + Jackson2ExecutionContextStringSerializer serializerDeserializer = new Jackson2ExecutionContextStringSerializer( + AbstractExecutionContextSerializerTests.Person.class.getName()); serializer = serializerDeserializer; }