Avoid using Java 8 ZoneId class

Issue: SPR-12594
This commit is contained in:
Sebastien Deleuze
2015-01-20 15:24:55 +01:00
parent b89e62e5f6
commit bf7a9754d5
3 changed files with 15 additions and 13 deletions

View File

@@ -17,8 +17,6 @@
package org.springframework.http.converter.json;
import java.text.SimpleDateFormat;
import java.time.ZoneId;
import java.time.zone.ZoneRulesException;
import java.util.Arrays;
import java.util.Collections;
import java.util.Date;
@@ -179,7 +177,7 @@ public class Jackson2ObjectMapperBuilderTests {
@Test
public void timeZoneSetter() {
TimeZone timeZone = TimeZone.getTimeZone(ZoneId.of("Europe/Paris"));
TimeZone timeZone = TimeZone.getTimeZone("Europe/Paris");
ObjectMapper objectMapper = Jackson2ObjectMapperBuilder.json().timeZone(timeZone).build();
assertEquals(timeZone, objectMapper.getSerializationConfig().getTimeZone());
assertEquals(timeZone, objectMapper.getDeserializationConfig().getTimeZone());
@@ -189,15 +187,18 @@ public class Jackson2ObjectMapperBuilderTests {
public void timeZoneStringSetter() {
String zoneId = "Europe/Paris";
ObjectMapper objectMapper = Jackson2ObjectMapperBuilder.json().timeZone(zoneId).build();
TimeZone timeZone = TimeZone.getTimeZone(ZoneId.of(zoneId));
TimeZone timeZone = TimeZone.getTimeZone(zoneId);
assertEquals(timeZone, objectMapper.getSerializationConfig().getTimeZone());
assertEquals(timeZone, objectMapper.getDeserializationConfig().getTimeZone());
}
@Test(expected = ZoneRulesException.class)
@Test
public void wrongTimeZoneStringSetter() {
String zoneId = "foo";
Jackson2ObjectMapperBuilder.json().timeZone(zoneId).build();
ObjectMapper objectMapper = Jackson2ObjectMapperBuilder.json().timeZone(zoneId).build();
TimeZone timeZone = TimeZone.getTimeZone("GMT");
assertEquals(timeZone, objectMapper.getSerializationConfig().getTimeZone());
assertEquals(timeZone, objectMapper.getDeserializationConfig().getTimeZone());
}
@Test

View File

@@ -17,8 +17,6 @@
package org.springframework.http.converter.json;
import java.text.SimpleDateFormat;
import java.time.ZoneId;
import java.time.zone.ZoneRulesException;
import java.util.Arrays;
import java.util.Collections;
import java.util.Date;
@@ -176,7 +174,7 @@ public class Jackson2ObjectMapperFactoryBeanTests {
@Test
public void timeZoneSetter() {
TimeZone timeZone = TimeZone.getTimeZone(ZoneId.of("Europe/Paris"));
TimeZone timeZone = TimeZone.getTimeZone("Europe/Paris");
this.factory.setTimeZone(timeZone);
this.factory.afterPropertiesSet();
@@ -192,17 +190,21 @@ public class Jackson2ObjectMapperFactoryBeanTests {
this.factory.setTimeZone(zoneId);
this.factory.afterPropertiesSet();
TimeZone timeZone = TimeZone.getTimeZone(ZoneId.of(zoneId));
TimeZone timeZone = TimeZone.getTimeZone(zoneId);
assertEquals(timeZone, this.factory.getObject().getSerializationConfig().getTimeZone());
assertEquals(timeZone, this.factory.getObject().getDeserializationConfig().getTimeZone());
}
@Test(expected = ZoneRulesException.class)
@Test
public void wrongTimeZoneStringSetter() {
String zoneId = "foo";
this.factory.setTimeZone(zoneId);
this.factory.afterPropertiesSet();
TimeZone timeZone = TimeZone.getTimeZone("GMT");
assertEquals(timeZone, this.factory.getObject().getSerializationConfig().getTimeZone());
assertEquals(timeZone, this.factory.getObject().getDeserializationConfig().getTimeZone());
}
@Test