Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,11 @@
<artifactId>junit-jupiter</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit-pioneer</groupId>
<artifactId>junit-pioneer</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ protected DateFormat getFormat(final Locale locale, final TimeZone timeZone) {
* @return The DateFormat
*/
private DateFormat getFormat(final String pattern) {
final DateFormat format = new SimpleDateFormat(pattern);
final DateFormat format = locale == null ? new SimpleDateFormat(pattern) : new SimpleDateFormat(pattern, locale);
if (timeZone != null) {
format.setTimeZone(timeZone);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
import org.apache.commons.beanutils2.ConversionException;
import org.apache.commons.beanutils2.Converter;
import org.junit.jupiter.api.Test;
import org.junitpioneer.jupiter.DefaultLocale;

/**
* Abstract base for &lt;Date&gt;Converter classes.
Expand Down Expand Up @@ -268,6 +269,22 @@ public void testLocale() {
Locale.setDefault(defaultLocale);
}

/**
* Test that a configured Locale is honored when a pattern is also set.
*/
@Test

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use JUnit Pioneer to set a temporary Locale.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done, switched the test to Pioneer's @DefaultLocale and dropped the manual save/restore. Added junit-pioneer as a test dependency since it wasn't in the pom yet (version comes from commons-parent). All 9 subclass runs still pass.

@DefaultLocale(language = "en", country = "US")
void testLocaleWithPattern() {
// The default Locale's month names differ from the configured Locale's.
final String pattern = "dd MMMM yyyy"; // month name is Locale-sensitive
final DateTimeConverter<T> converter = makeConverter();
converter.setLocale(Locale.GERMANY);
converter.setPattern(pattern);
final String testString = "28 Oktober 2006";
final Object expected = toType(testString, pattern, Locale.GERMANY);
validConversion(converter, expected, testString);
}

/**
* Test Converter with multiple patterns
*/
Expand Down
Loading