Skip to content

Commit 7838aea

Browse files
committed
Polish contribution 58b2a7a
* Update year in license headers * Refactor test
1 parent 09c03ad commit 7838aea

File tree

2 files changed

+16
-14
lines changed

2 files changed

+16
-14
lines changed

spring-batch-core/src/main/java/org/springframework/batch/core/repository/dao/Jackson2ExecutionContextStringSerializer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2008-2020 the original author or authors.
2+
* Copyright 2008-2021 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.

spring-batch-core/src/test/java/org/springframework/batch/core/repository/dao/Jackson2ExecutionContextStringSerializerTests.java

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2008-2020 the original author or authors.
2+
* Copyright 2008-2021 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -167,20 +167,22 @@ public static class UnmappedDomesticNumber extends UnmappedPhoneNumber{}
167167

168168
@Test
169169
public void arrayAsListSerializationTest() throws IOException {
170-
171-
Jackson2ExecutionContextStringSerializer j = new Jackson2ExecutionContextStringSerializer();
170+
//given
171+
List<String> list = Arrays.asList("foo", "bar");
172+
String key = "Arrays.asList";
173+
Jackson2ExecutionContextStringSerializer serializer = new Jackson2ExecutionContextStringSerializer();
172174
Map<String, Object> context = new HashMap<>(1);
173-
context.put("Arrays.asList", Arrays.asList("foo", "bar"));
174-
175-
ByteArrayOutputStream os = new ByteArrayOutputStream();
176-
j.serialize(context, os);
175+
context.put(key, list);
177176

178-
InputStream in = new ByteArrayInputStream(os.toByteArray());
177+
// when
178+
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
179+
serializer.serialize(context, outputStream);
180+
InputStream inputStream = new ByteArrayInputStream(outputStream.toByteArray());
181+
Map<String, Object> deserializedContext = serializer.deserialize(inputStream);
179182

180-
context = j.deserialize(in);
181-
182-
String[] expectedValue = { "foo", "bar" };
183-
List<String> deserializedValue = (List<String>) context.get("Arrays.asList");
184-
Assert.assertArrayEquals(expectedValue, deserializedValue.toArray(new String[0]));
183+
// then
184+
Object deserializedValue = deserializedContext.get(key);
185+
Assert.assertTrue(List.class.isAssignableFrom(deserializedValue.getClass()));
186+
Assert.assertTrue(((List<String>)deserializedValue).containsAll(list));
185187
}
186188
}

0 commit comments

Comments
 (0)