Polishing
This commit is contained in:
parent
ef2e16912d
commit
637e09f995
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2017 the original author or authors.
|
* Copyright 2002-2018 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -336,6 +336,7 @@ public class ScheduledTaskRegistrar implements ScheduledTaskHolder, Initializing
|
||||||
* Schedule all registered tasks against the underlying
|
* Schedule all registered tasks against the underlying
|
||||||
* {@linkplain #setTaskScheduler(TaskScheduler) task scheduler}.
|
* {@linkplain #setTaskScheduler(TaskScheduler) task scheduler}.
|
||||||
*/
|
*/
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
protected void scheduleTasks() {
|
protected void scheduleTasks() {
|
||||||
if (this.taskScheduler == null) {
|
if (this.taskScheduler == null) {
|
||||||
this.localExecutor = Executors.newSingleThreadScheduledExecutor();
|
this.localExecutor = Executors.newSingleThreadScheduledExecutor();
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2016 the original author or authors.
|
* Copyright 2002-2018 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -46,7 +46,7 @@ public class DateFormatterTests {
|
||||||
private static final TimeZone UTC = TimeZone.getTimeZone("UTC");
|
private static final TimeZone UTC = TimeZone.getTimeZone("UTC");
|
||||||
|
|
||||||
@Rule
|
@Rule
|
||||||
public ExpectedException thown = ExpectedException.none();
|
public ExpectedException thrown = ExpectedException.none();
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -175,8 +175,8 @@ public class DateFormatterTests {
|
||||||
public void shouldThrowOnUnsupportedStylePattern() throws Exception {
|
public void shouldThrowOnUnsupportedStylePattern() throws Exception {
|
||||||
DateFormatter formatter = new DateFormatter();
|
DateFormatter formatter = new DateFormatter();
|
||||||
formatter.setStylePattern("OO");
|
formatter.setStylePattern("OO");
|
||||||
thown.expect(IllegalStateException.class);
|
thrown.expect(IllegalStateException.class);
|
||||||
thown.expectMessage("Unsupported style pattern 'OO'");
|
thrown.expectMessage("Unsupported style pattern 'OO'");
|
||||||
formatter.parse("2009", Locale.US);
|
formatter.parse("2009", Locale.US);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2016 the original author or authors.
|
* Copyright 2002-2018 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -52,12 +52,12 @@ public class DateFormattingTests {
|
||||||
|
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() {
|
public void setup() {
|
||||||
DateFormatterRegistrar registrar = new DateFormatterRegistrar();
|
DateFormatterRegistrar registrar = new DateFormatterRegistrar();
|
||||||
setUp(registrar);
|
setup(registrar);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setUp(DateFormatterRegistrar registrar) {
|
private void setup(DateFormatterRegistrar registrar) {
|
||||||
DefaultConversionService.addDefaultConverters(conversionService);
|
DefaultConversionService.addDefaultConverters(conversionService);
|
||||||
registrar.registerFormatters(conversionService);
|
registrar.registerFormatters(conversionService);
|
||||||
|
|
||||||
|
@ -193,7 +193,7 @@ public class DateFormattingTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void dateToStringWithoutGlobalFormat() throws Exception {
|
public void dateToStringWithoutGlobalFormat() {
|
||||||
Date date = new Date();
|
Date date = new Date();
|
||||||
Object actual = this.conversionService.convert(date, TypeDescriptor.valueOf(Date.class), TypeDescriptor.valueOf(String.class));
|
Object actual = this.conversionService.convert(date, TypeDescriptor.valueOf(Date.class), TypeDescriptor.valueOf(String.class));
|
||||||
String expected = date.toString();
|
String expected = date.toString();
|
||||||
|
@ -201,33 +201,31 @@ public class DateFormattingTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void dateToStringWithGlobalFormat() throws Exception {
|
public void dateToStringWithGlobalFormat() {
|
||||||
DateFormatterRegistrar registrar = new DateFormatterRegistrar();
|
DateFormatterRegistrar registrar = new DateFormatterRegistrar();
|
||||||
registrar.setFormatter(new DateFormatter());
|
registrar.setFormatter(new DateFormatter());
|
||||||
setUp(registrar);
|
setup(registrar);
|
||||||
Date date = new Date();
|
Date date = new Date();
|
||||||
Object actual = this.conversionService.convert(date, TypeDescriptor.valueOf(Date.class), TypeDescriptor.valueOf(String.class));
|
Object actual = this.conversionService.convert(date, TypeDescriptor.valueOf(Date.class), TypeDescriptor.valueOf(String.class));
|
||||||
String expected = new DateFormatter().print(date, Locale.US);
|
String expected = new DateFormatter().print(date, Locale.US);
|
||||||
assertEquals(expected, actual);
|
assertEquals(expected, actual);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test // SPR-10105
|
||||||
@SuppressWarnings("deprecation")
|
@SuppressWarnings("deprecation")
|
||||||
public void stringToDateWithoutGlobalFormat() throws Exception {
|
public void stringToDateWithoutGlobalFormat() {
|
||||||
// SPR-10105
|
|
||||||
String string = "Sat, 12 Aug 1995 13:30:00 GM";
|
String string = "Sat, 12 Aug 1995 13:30:00 GM";
|
||||||
Date date = this.conversionService.convert(string, Date.class);
|
Date date = this.conversionService.convert(string, Date.class);
|
||||||
assertThat(date, equalTo(new Date(string)));
|
assertThat(date, equalTo(new Date(string)));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test // SPR-10105
|
||||||
public void stringToDateWithGlobalFormat() throws Exception {
|
public void stringToDateWithGlobalFormat() {
|
||||||
// SPR-10105
|
|
||||||
DateFormatterRegistrar registrar = new DateFormatterRegistrar();
|
DateFormatterRegistrar registrar = new DateFormatterRegistrar();
|
||||||
DateFormatter dateFormatter = new DateFormatter();
|
DateFormatter dateFormatter = new DateFormatter();
|
||||||
dateFormatter.setIso(ISO.DATE_TIME);
|
dateFormatter.setIso(ISO.DATE_TIME);
|
||||||
registrar.setFormatter(dateFormatter);
|
registrar.setFormatter(dateFormatter);
|
||||||
setUp(registrar);
|
setup(registrar);
|
||||||
// This is a format that cannot be parsed by new Date(String)
|
// This is a format that cannot be parsed by new Date(String)
|
||||||
String string = "2009-06-01T14:23:05.003+00:00";
|
String string = "2009-06-01T14:23:05.003+00:00";
|
||||||
Date date = this.conversionService.convert(string, Date.class);
|
Date date = this.conversionService.convert(string, Date.class);
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2012 the original author or authors.
|
* Copyright 2002-2018 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -29,27 +29,28 @@ import static org.junit.Assert.*;
|
||||||
*/
|
*/
|
||||||
public class DateTimeFormatterFactoryBeanTests {
|
public class DateTimeFormatterFactoryBeanTests {
|
||||||
|
|
||||||
private DateTimeFormatterFactoryBean factory = new DateTimeFormatterFactoryBean();
|
private final DateTimeFormatterFactoryBean factory = new DateTimeFormatterFactoryBean();
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void isSingleton() throws Exception {
|
public void isSingleton() {
|
||||||
assertThat(factory.isSingleton(), is(true));
|
assertThat(factory.isSingleton(), is(true));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@SuppressWarnings("rawtypes")
|
@SuppressWarnings("rawtypes")
|
||||||
public void getObjectType() throws Exception {
|
public void getObjectType() {
|
||||||
assertThat(factory.getObjectType(), is(equalTo((Class) DateTimeFormatter.class)));
|
assertThat(factory.getObjectType(), is(equalTo((Class) DateTimeFormatter.class)));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getObject() throws Exception {
|
public void getObject() {
|
||||||
factory.afterPropertiesSet();
|
factory.afterPropertiesSet();
|
||||||
assertThat(factory.getObject(), is(equalTo(DateTimeFormat.mediumDateTime())));
|
assertThat(factory.getObject(), is(equalTo(DateTimeFormat.mediumDateTime())));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getObjectIsAlwaysSingleton() throws Exception {
|
public void getObjectIsAlwaysSingleton() {
|
||||||
factory.afterPropertiesSet();
|
factory.afterPropertiesSet();
|
||||||
DateTimeFormatter formatter = factory.getObject();
|
DateTimeFormatter formatter = factory.getObject();
|
||||||
assertThat(formatter, is(equalTo(DateTimeFormat.mediumDateTime())));
|
assertThat(formatter, is(equalTo(DateTimeFormat.mediumDateTime())));
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2015 the original author or authors.
|
* Copyright 2002-2018 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -50,32 +50,32 @@ public class DateTimeFormatterFactoryTests {
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void createDateTimeFormatter() throws Exception {
|
public void createDateTimeFormatter() {
|
||||||
assertThat(factory.createDateTimeFormatter(), is(equalTo(DateTimeFormat.mediumDateTime())));
|
assertThat(factory.createDateTimeFormatter(), is(equalTo(DateTimeFormat.mediumDateTime())));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void createDateTimeFormatterWithPattern() throws Exception {
|
public void createDateTimeFormatterWithPattern() {
|
||||||
factory = new DateTimeFormatterFactory("yyyyMMddHHmmss");
|
factory = new DateTimeFormatterFactory("yyyyMMddHHmmss");
|
||||||
DateTimeFormatter formatter = factory.createDateTimeFormatter();
|
DateTimeFormatter formatter = factory.createDateTimeFormatter();
|
||||||
assertThat(formatter.print(dateTime), is("20091021121000"));
|
assertThat(formatter.print(dateTime), is("20091021121000"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void createDateTimeFormatterWithNullFallback() throws Exception {
|
public void createDateTimeFormatterWithNullFallback() {
|
||||||
DateTimeFormatter formatter = factory.createDateTimeFormatter(null);
|
DateTimeFormatter formatter = factory.createDateTimeFormatter(null);
|
||||||
assertThat(formatter, is(nullValue()));
|
assertThat(formatter, is(nullValue()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void createDateTimeFormatterWithFallback() throws Exception {
|
public void createDateTimeFormatterWithFallback() {
|
||||||
DateTimeFormatter fallback = DateTimeFormat.forStyle("LL");
|
DateTimeFormatter fallback = DateTimeFormat.forStyle("LL");
|
||||||
DateTimeFormatter formatter = factory.createDateTimeFormatter(fallback);
|
DateTimeFormatter formatter = factory.createDateTimeFormatter(fallback);
|
||||||
assertThat(formatter, is(sameInstance(fallback)));
|
assertThat(formatter, is(sameInstance(fallback)));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void createDateTimeFormatterInOrderOfPropertyPriority() throws Exception {
|
public void createDateTimeFormatterInOrderOfPropertyPriority() {
|
||||||
factory.setStyle("SS");
|
factory.setStyle("SS");
|
||||||
String value = applyLocale(factory.createDateTimeFormatter()).print(dateTime);
|
String value = applyLocale(factory.createDateTimeFormatter()).print(dateTime);
|
||||||
assertTrue(value.startsWith("10/21/09"));
|
assertTrue(value.startsWith("10/21/09"));
|
||||||
|
@ -89,7 +89,7 @@ public class DateTimeFormatterFactoryTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void createDateTimeFormatterWithTimeZone() throws Exception {
|
public void createDateTimeFormatterWithTimeZone() {
|
||||||
factory.setPattern("yyyyMMddHHmmss Z");
|
factory.setPattern("yyyyMMddHHmmss Z");
|
||||||
factory.setTimeZone(TEST_TIMEZONE);
|
factory.setTimeZone(TEST_TIMEZONE);
|
||||||
DateTimeZone dateTimeZone = DateTimeZone.forTimeZone(TEST_TIMEZONE);
|
DateTimeZone dateTimeZone = DateTimeZone.forTimeZone(TEST_TIMEZONE);
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2016 the original author or authors.
|
* Copyright 2002-2018 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -62,12 +62,12 @@ public class JodaTimeFormattingTests {
|
||||||
|
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() {
|
public void setup() {
|
||||||
JodaTimeFormatterRegistrar registrar = new JodaTimeFormatterRegistrar();
|
JodaTimeFormatterRegistrar registrar = new JodaTimeFormatterRegistrar();
|
||||||
setUp(registrar);
|
setup(registrar);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setUp(JodaTimeFormatterRegistrar registrar) {
|
private void setup(JodaTimeFormatterRegistrar registrar) {
|
||||||
conversionService = new FormattingConversionService();
|
conversionService = new FormattingConversionService();
|
||||||
DefaultConversionService.addDefaultConverters(conversionService);
|
DefaultConversionService.addDefaultConverters(conversionService);
|
||||||
registrar.registerFormatters(conversionService);
|
registrar.registerFormatters(conversionService);
|
||||||
|
@ -84,7 +84,7 @@ public class JodaTimeFormattingTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@After
|
@After
|
||||||
public void tearDown() {
|
public void cleanup() {
|
||||||
LocaleContextHolder.setLocale(null);
|
LocaleContextHolder.setLocale(null);
|
||||||
JodaTimeContextHolder.setJodaTimeContext(null);
|
JodaTimeContextHolder.setJodaTimeContext(null);
|
||||||
}
|
}
|
||||||
|
@ -108,10 +108,10 @@ public class JodaTimeFormattingTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testBindLocalDateWithSpecificStyle() throws Exception {
|
public void testBindLocalDateWithSpecificStyle() {
|
||||||
JodaTimeFormatterRegistrar registrar = new JodaTimeFormatterRegistrar();
|
JodaTimeFormatterRegistrar registrar = new JodaTimeFormatterRegistrar();
|
||||||
registrar.setDateStyle("L");
|
registrar.setDateStyle("L");
|
||||||
setUp(registrar);
|
setup(registrar);
|
||||||
MutablePropertyValues propertyValues = new MutablePropertyValues();
|
MutablePropertyValues propertyValues = new MutablePropertyValues();
|
||||||
propertyValues.add("localDate", "October 31, 2009");
|
propertyValues.add("localDate", "October 31, 2009");
|
||||||
binder.bind(propertyValues);
|
binder.bind(propertyValues);
|
||||||
|
@ -120,10 +120,10 @@ public class JodaTimeFormattingTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testBindLocalDateWithSpecificFormatter() throws Exception {
|
public void testBindLocalDateWithSpecificFormatter() {
|
||||||
JodaTimeFormatterRegistrar registrar = new JodaTimeFormatterRegistrar();
|
JodaTimeFormatterRegistrar registrar = new JodaTimeFormatterRegistrar();
|
||||||
registrar.setDateFormatter(org.joda.time.format.DateTimeFormat.forPattern("yyyyMMdd"));
|
registrar.setDateFormatter(org.joda.time.format.DateTimeFormat.forPattern("yyyyMMdd"));
|
||||||
setUp(registrar);
|
setup(registrar);
|
||||||
MutablePropertyValues propertyValues = new MutablePropertyValues();
|
MutablePropertyValues propertyValues = new MutablePropertyValues();
|
||||||
propertyValues.add("localDate", "20091031");
|
propertyValues.add("localDate", "20091031");
|
||||||
binder.bind(propertyValues);
|
binder.bind(propertyValues);
|
||||||
|
@ -196,10 +196,10 @@ public class JodaTimeFormattingTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testBindLocalTimeWithSpecificStyle() throws Exception {
|
public void testBindLocalTimeWithSpecificStyle() {
|
||||||
JodaTimeFormatterRegistrar registrar = new JodaTimeFormatterRegistrar();
|
JodaTimeFormatterRegistrar registrar = new JodaTimeFormatterRegistrar();
|
||||||
registrar.setTimeStyle("M");
|
registrar.setTimeStyle("M");
|
||||||
setUp(registrar);
|
setup(registrar);
|
||||||
MutablePropertyValues propertyValues = new MutablePropertyValues();
|
MutablePropertyValues propertyValues = new MutablePropertyValues();
|
||||||
propertyValues.add("localTime", "12:00:00 PM");
|
propertyValues.add("localTime", "12:00:00 PM");
|
||||||
binder.bind(propertyValues);
|
binder.bind(propertyValues);
|
||||||
|
@ -208,10 +208,10 @@ public class JodaTimeFormattingTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testBindLocalTimeWithSpecificFormatter() throws Exception {
|
public void testBindLocalTimeWithSpecificFormatter() {
|
||||||
JodaTimeFormatterRegistrar registrar = new JodaTimeFormatterRegistrar();
|
JodaTimeFormatterRegistrar registrar = new JodaTimeFormatterRegistrar();
|
||||||
registrar.setTimeFormatter(org.joda.time.format.DateTimeFormat.forPattern("HHmmss"));
|
registrar.setTimeFormatter(org.joda.time.format.DateTimeFormat.forPattern("HHmmss"));
|
||||||
setUp(registrar);
|
setup(registrar);
|
||||||
MutablePropertyValues propertyValues = new MutablePropertyValues();
|
MutablePropertyValues propertyValues = new MutablePropertyValues();
|
||||||
propertyValues.add("localTime", "130000");
|
propertyValues.add("localTime", "130000");
|
||||||
binder.bind(propertyValues);
|
binder.bind(propertyValues);
|
||||||
|
@ -261,10 +261,10 @@ public class JodaTimeFormattingTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testBindDateTimeWithSpecificStyle() throws Exception {
|
public void testBindDateTimeWithSpecificStyle() {
|
||||||
JodaTimeFormatterRegistrar registrar = new JodaTimeFormatterRegistrar();
|
JodaTimeFormatterRegistrar registrar = new JodaTimeFormatterRegistrar();
|
||||||
registrar.setDateTimeStyle("MM");
|
registrar.setDateTimeStyle("MM");
|
||||||
setUp(registrar);
|
setup(registrar);
|
||||||
MutablePropertyValues propertyValues = new MutablePropertyValues();
|
MutablePropertyValues propertyValues = new MutablePropertyValues();
|
||||||
propertyValues.add("localDateTime", new LocalDateTime(2009, 10, 31, 12, 0));
|
propertyValues.add("localDateTime", new LocalDateTime(2009, 10, 31, 12, 0));
|
||||||
binder.bind(propertyValues);
|
binder.bind(propertyValues);
|
||||||
|
@ -275,10 +275,10 @@ public class JodaTimeFormattingTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testBindDateTimeISO() throws Exception {
|
public void testBindDateTimeISO() {
|
||||||
JodaTimeFormatterRegistrar registrar = new JodaTimeFormatterRegistrar();
|
JodaTimeFormatterRegistrar registrar = new JodaTimeFormatterRegistrar();
|
||||||
registrar.setUseIsoFormat(true);
|
registrar.setUseIsoFormat(true);
|
||||||
setUp(registrar);
|
setup(registrar);
|
||||||
MutablePropertyValues propertyValues = new MutablePropertyValues();
|
MutablePropertyValues propertyValues = new MutablePropertyValues();
|
||||||
propertyValues.add("dateTime", "2009-10-31T12:00:00.000Z");
|
propertyValues.add("dateTime", "2009-10-31T12:00:00.000Z");
|
||||||
binder.bind(propertyValues);
|
binder.bind(propertyValues);
|
||||||
|
@ -287,10 +287,10 @@ public class JodaTimeFormattingTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testBindDateTimeWithSpecificFormatter() throws Exception {
|
public void testBindDateTimeWithSpecificFormatter() {
|
||||||
JodaTimeFormatterRegistrar registrar = new JodaTimeFormatterRegistrar();
|
JodaTimeFormatterRegistrar registrar = new JodaTimeFormatterRegistrar();
|
||||||
registrar.setDateTimeFormatter(org.joda.time.format.DateTimeFormat.forPattern("yyyyMMddHHmmss"));
|
registrar.setDateTimeFormatter(org.joda.time.format.DateTimeFormat.forPattern("yyyyMMddHHmmss"));
|
||||||
setUp(registrar);
|
setup(registrar);
|
||||||
MutablePropertyValues propertyValues = new MutablePropertyValues();
|
MutablePropertyValues propertyValues = new MutablePropertyValues();
|
||||||
propertyValues.add("dateTime", "20091031130000");
|
propertyValues.add("dateTime", "20091031130000");
|
||||||
binder.bind(propertyValues);
|
binder.bind(propertyValues);
|
||||||
|
@ -435,33 +435,31 @@ public class JodaTimeFormattingTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void dateToStringWithFormat() throws Exception {
|
public void dateToStringWithFormat() {
|
||||||
JodaTimeFormatterRegistrar registrar = new JodaTimeFormatterRegistrar();
|
JodaTimeFormatterRegistrar registrar = new JodaTimeFormatterRegistrar();
|
||||||
registrar.setDateTimeFormatter(org.joda.time.format.DateTimeFormat.shortDateTime());
|
registrar.setDateTimeFormatter(org.joda.time.format.DateTimeFormat.shortDateTime());
|
||||||
setUp(registrar);
|
setup(registrar);
|
||||||
Date date = new Date();
|
Date date = new Date();
|
||||||
Object actual = this.conversionService.convert(date, TypeDescriptor.valueOf(Date.class), TypeDescriptor.valueOf(String.class));
|
Object actual = this.conversionService.convert(date, TypeDescriptor.valueOf(Date.class), TypeDescriptor.valueOf(String.class));
|
||||||
String expected = JodaTimeContextHolder.getFormatter(org.joda.time.format.DateTimeFormat.shortDateTime(), Locale.US).print(new DateTime(date));
|
String expected = JodaTimeContextHolder.getFormatter(org.joda.time.format.DateTimeFormat.shortDateTime(), Locale.US).print(new DateTime(date));
|
||||||
assertEquals(expected, actual);
|
assertEquals(expected, actual);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test // SPR-10105
|
||||||
@SuppressWarnings("deprecation")
|
@SuppressWarnings("deprecation")
|
||||||
public void stringToDateWithoutGlobalFormat() throws Exception {
|
public void stringToDateWithoutGlobalFormat() {
|
||||||
// SPR-10105
|
|
||||||
String string = "Sat, 12 Aug 1995 13:30:00 GM";
|
String string = "Sat, 12 Aug 1995 13:30:00 GM";
|
||||||
Date date = this.conversionService.convert(string, Date.class);
|
Date date = this.conversionService.convert(string, Date.class);
|
||||||
assertThat(date, equalTo(new Date(string)));
|
assertThat(date, equalTo(new Date(string)));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test // SPR-10105
|
||||||
public void stringToDateWithGlobalFormat() throws Exception {
|
public void stringToDateWithGlobalFormat() {
|
||||||
// SPR-10105
|
|
||||||
JodaTimeFormatterRegistrar registrar = new JodaTimeFormatterRegistrar();
|
JodaTimeFormatterRegistrar registrar = new JodaTimeFormatterRegistrar();
|
||||||
DateTimeFormatterFactory factory = new DateTimeFormatterFactory();
|
DateTimeFormatterFactory factory = new DateTimeFormatterFactory();
|
||||||
factory.setIso(ISO.DATE_TIME);
|
factory.setIso(ISO.DATE_TIME);
|
||||||
registrar.setDateTimeFormatter(factory.createDateTimeFormatter());
|
registrar.setDateTimeFormatter(factory.createDateTimeFormatter());
|
||||||
setUp(registrar);
|
setup(registrar);
|
||||||
// This is a format that cannot be parsed by new Date(String)
|
// This is a format that cannot be parsed by new Date(String)
|
||||||
String string = "2009-10-31T07:00:00.000-05:00";
|
String string = "2009-10-31T07:00:00.000-05:00";
|
||||||
Date date = this.conversionService.convert(string, Date.class);
|
Date date = this.conversionService.convert(string, Date.class);
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2012 the original author or authors.
|
* Copyright 2002-2018 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -30,31 +30,32 @@ import static org.junit.Assert.*;
|
||||||
*/
|
*/
|
||||||
public class DateTimeFormatterFactoryBeanTests {
|
public class DateTimeFormatterFactoryBeanTests {
|
||||||
|
|
||||||
private DateTimeFormatterFactoryBean factory = new DateTimeFormatterFactoryBean();
|
private final DateTimeFormatterFactoryBean factory = new DateTimeFormatterFactoryBean();
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void isSingleton() throws Exception {
|
public void isSingleton() {
|
||||||
assertThat(factory.isSingleton(), is(true));
|
assertThat(factory.isSingleton(), is(true));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@SuppressWarnings("rawtypes")
|
public void getObjectType() {
|
||||||
public void getObjectType() throws Exception {
|
assertThat(factory.getObjectType(), is(equalTo(DateTimeFormatter.class)));
|
||||||
assertThat(factory.getObjectType(), is(equalTo((Class) DateTimeFormatter.class)));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getObject() throws Exception {
|
public void getObject() {
|
||||||
factory.afterPropertiesSet();
|
factory.afterPropertiesSet();
|
||||||
assertThat(factory.getObject().toString(), is(equalTo(DateTimeFormatter.ofLocalizedDateTime(FormatStyle.MEDIUM).toString())));
|
assertThat(factory.getObject().toString(), is(equalTo(DateTimeFormatter.ofLocalizedDateTime(FormatStyle.MEDIUM).toString())));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getObjectIsAlwaysSingleton() throws Exception {
|
public void getObjectIsAlwaysSingleton() {
|
||||||
factory.afterPropertiesSet();
|
factory.afterPropertiesSet();
|
||||||
DateTimeFormatter formatter = factory.getObject();
|
DateTimeFormatter formatter = factory.getObject();
|
||||||
assertThat(formatter.toString(), is(equalTo(DateTimeFormatter.ofLocalizedDateTime(FormatStyle.MEDIUM).toString())));
|
assertThat(formatter.toString(), is(equalTo(DateTimeFormatter.ofLocalizedDateTime(FormatStyle.MEDIUM).toString())));
|
||||||
factory.setStylePattern("LL");
|
factory.setStylePattern("LL");
|
||||||
assertThat(factory.getObject(), is(sameInstance(formatter)));
|
assertThat(factory.getObject(), is(sameInstance(formatter)));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2015 the original author or authors.
|
* Copyright 2002-2018 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -51,32 +51,32 @@ public class DateTimeFormatterFactoryTests {
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void createDateTimeFormatter() throws Exception {
|
public void createDateTimeFormatter() {
|
||||||
assertThat(factory.createDateTimeFormatter().toString(), is(equalTo(DateTimeFormatter.ofLocalizedDateTime(FormatStyle.MEDIUM).toString())));
|
assertThat(factory.createDateTimeFormatter().toString(), is(equalTo(DateTimeFormatter.ofLocalizedDateTime(FormatStyle.MEDIUM).toString())));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void createDateTimeFormatterWithPattern() throws Exception {
|
public void createDateTimeFormatterWithPattern() {
|
||||||
factory = new DateTimeFormatterFactory("yyyyMMddHHmmss");
|
factory = new DateTimeFormatterFactory("yyyyMMddHHmmss");
|
||||||
DateTimeFormatter formatter = factory.createDateTimeFormatter();
|
DateTimeFormatter formatter = factory.createDateTimeFormatter();
|
||||||
assertThat(formatter.format(dateTime), is("20091021121000"));
|
assertThat(formatter.format(dateTime), is("20091021121000"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void createDateTimeFormatterWithNullFallback() throws Exception {
|
public void createDateTimeFormatterWithNullFallback() {
|
||||||
DateTimeFormatter formatter = factory.createDateTimeFormatter(null);
|
DateTimeFormatter formatter = factory.createDateTimeFormatter(null);
|
||||||
assertThat(formatter, is(nullValue()));
|
assertThat(formatter, is(nullValue()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void createDateTimeFormatterWithFallback() throws Exception {
|
public void createDateTimeFormatterWithFallback() {
|
||||||
DateTimeFormatter fallback = DateTimeFormatter.ofLocalizedDateTime(FormatStyle.LONG);
|
DateTimeFormatter fallback = DateTimeFormatter.ofLocalizedDateTime(FormatStyle.LONG);
|
||||||
DateTimeFormatter formatter = factory.createDateTimeFormatter(fallback);
|
DateTimeFormatter formatter = factory.createDateTimeFormatter(fallback);
|
||||||
assertThat(formatter, is(sameInstance(fallback)));
|
assertThat(formatter, is(sameInstance(fallback)));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void createDateTimeFormatterInOrderOfPropertyPriority() throws Exception {
|
public void createDateTimeFormatterInOrderOfPropertyPriority() {
|
||||||
factory.setStylePattern("SS");
|
factory.setStylePattern("SS");
|
||||||
String value = applyLocale(factory.createDateTimeFormatter()).format(dateTime);
|
String value = applyLocale(factory.createDateTimeFormatter()).format(dateTime);
|
||||||
assertTrue(value.startsWith("10/21/09"));
|
assertTrue(value.startsWith("10/21/09"));
|
||||||
|
@ -90,7 +90,7 @@ public class DateTimeFormatterFactoryTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void createDateTimeFormatterWithTimeZone() throws Exception {
|
public void createDateTimeFormatterWithTimeZone() {
|
||||||
factory.setPattern("yyyyMMddHHmmss Z");
|
factory.setPattern("yyyyMMddHHmmss Z");
|
||||||
factory.setTimeZone(TEST_TIMEZONE);
|
factory.setTimeZone(TEST_TIMEZONE);
|
||||||
ZoneId dateTimeZone = TEST_TIMEZONE.toZoneId();
|
ZoneId dateTimeZone = TEST_TIMEZONE.toZoneId();
|
||||||
|
|
Loading…
Reference in New Issue