HHH-11484 - Fix LocaleTypeDescriptor to handle Locale.ROOT
This commit is contained in:
parent
3adb0d76be
commit
3c2939f0e5
|
@ -43,10 +43,14 @@ public class LocaleTypeDescriptor extends AbstractTypeDescriptor<Locale> {
|
||||||
public Locale fromString(String string) {
|
public Locale fromString(String string) {
|
||||||
// TODO : Ultimately switch to Locale.Builder for this. However, Locale.Builder is Java 7
|
// TODO : Ultimately switch to Locale.Builder for this. However, Locale.Builder is Java 7
|
||||||
|
|
||||||
if ( string == null || string.isEmpty() ) {
|
if ( string == null ) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if( string.isEmpty() ) {
|
||||||
|
return Locale.ROOT;
|
||||||
|
}
|
||||||
|
|
||||||
boolean separatorFound = false;
|
boolean separatorFound = false;
|
||||||
int position = 0;
|
int position = 0;
|
||||||
char[] chars = string.toCharArray();
|
char[] chars = string.toCharArray();
|
||||||
|
|
|
@ -32,6 +32,8 @@ public class LocaleTypeDescriptorTest extends BaseUnitTestCase {
|
||||||
assertEquals( toLocale( null, "DE", "ch123" ), LocaleTypeDescriptor.INSTANCE.fromString( "_DE_ch123" ) );
|
assertEquals( toLocale( null, "DE", "ch123" ), LocaleTypeDescriptor.INSTANCE.fromString( "_DE_ch123" ) );
|
||||||
assertEquals( toLocale( "de", null, "ch123" ), LocaleTypeDescriptor.INSTANCE.fromString( "de__ch123" ) );
|
assertEquals( toLocale( "de", null, "ch123" ), LocaleTypeDescriptor.INSTANCE.fromString( "de__ch123" ) );
|
||||||
assertEquals( toLocale( "de", "DE", "ch123" ), LocaleTypeDescriptor.INSTANCE.fromString( "de_DE_ch123" ) );
|
assertEquals( toLocale( "de", "DE", "ch123" ), LocaleTypeDescriptor.INSTANCE.fromString( "de_DE_ch123" ) );
|
||||||
|
assertEquals( toLocale( "", "", "" ), LocaleTypeDescriptor.INSTANCE.fromString( "" ) );
|
||||||
|
assertEquals( Locale.ROOT, LocaleTypeDescriptor.INSTANCE.fromString( "" ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
public Locale toLocale(String lang, String region, String variant) {
|
public Locale toLocale(String lang, String region, String variant) {
|
||||||
|
|
Loading…
Reference in New Issue