From a0773cac9bb2a33ba00369586871bf5719f0da28 Mon Sep 17 00:00:00 2001 From: Mahmoud Ben Hassine Date: Thu, 4 Jan 2018 18:34:41 +0100 Subject: [PATCH] BATCH-2668: Fixed failing test on CET timezone In order to convert a String value to a Date, The `DefaultConversionService` uses the constructor `java.util.Date(java.lang.String)` behind the scene (from `org.springframework.core.convert.support.ObjectToObjectConverter.convert`). This constructor throws a `java.lang.IllegalArgumentException` for values in CET timezone, for example: "Thu Jan 04 09:05:50 CET 2018". This commit updates the failing test to use a fixed timezone (UTC). Resolves BATCH-2668 --- .../mapping/BeanWrapperFieldSetMapperTests.java | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/file/mapping/BeanWrapperFieldSetMapperTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/file/mapping/BeanWrapperFieldSetMapperTests.java index 3839a0942..081f45f41 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/file/mapping/BeanWrapperFieldSetMapperTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/file/mapping/BeanWrapperFieldSetMapperTests.java @@ -27,7 +27,10 @@ import java.util.List; import java.util.Locale; import java.util.Map; import java.util.Properties; +import java.util.TimeZone; +import org.junit.After; +import org.junit.Before; import org.junit.Test; import org.springframework.batch.item.file.transform.DefaultFieldSet; @@ -54,6 +57,20 @@ import static org.junit.Assert.fail; public class BeanWrapperFieldSetMapperTests { + private static final TimeZone UTC_TIME_ZONE = TimeZone.getTimeZone("UTC"); + + private TimeZone defaultTimeZone = TimeZone.getDefault(); + + @Before + public void setUp() { + TimeZone.setDefault(UTC_TIME_ZONE); + } + + @After + public void tearDown() { + TimeZone.setDefault(defaultTimeZone); + } + @Test public void testNameAndTypeSpecified() throws Exception { boolean errorCaught = false;