-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add locale conversion format configuration property
- Loading branch information
Showing
9 changed files
with
125 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
...piter-params/src/main/java/org/junit/jupiter/params/converter/LocaleConversionFormat.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/* | ||
* Copyright 2015-2023 the original author or authors. | ||
* | ||
* All rights reserved. This program and the accompanying materials are | ||
* made available under the terms of the Eclipse Public License v2.0 which | ||
* accompanies this distribution and is available at | ||
* | ||
* https://www.eclipse.org/legal/epl-v20.html | ||
*/ | ||
|
||
package org.junit.jupiter.params.converter; | ||
|
||
import static org.apiguardian.api.API.Status.INTERNAL; | ||
|
||
import org.apiguardian.api.API; | ||
|
||
/** | ||
* Enumeration of {@link java.util.Locale} conversion formats. | ||
* | ||
* @since 5.11 | ||
*/ | ||
@API(status = INTERNAL, since = "5.11") | ||
public enum LocaleConversionFormat { | ||
|
||
/** | ||
* The ISO 639 alpha-2 or alpha-3 language code format. | ||
* | ||
* @see java.util.Locale#Locale(String) | ||
*/ | ||
ISO_639, | ||
|
||
/** | ||
* The IETF BCP 47 language tag format. | ||
* | ||
* @see java.util.Locale#forLanguageTag(String) | ||
*/ | ||
BCP_47 | ||
|
||
} |
37 changes: 37 additions & 0 deletions
37
...iter-params/src/main/java/org/junit/jupiter/params/converter/StringToLocaleConverter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/* | ||
* Copyright 2015-2023 the original author or authors. | ||
* | ||
* All rights reserved. This program and the accompanying materials are | ||
* made available under the terms of the Eclipse Public License v2.0 which | ||
* accompanies this distribution and is available at | ||
* | ||
* https://www.eclipse.org/legal/epl-v20.html | ||
*/ | ||
|
||
package org.junit.jupiter.params.converter; | ||
|
||
import java.util.Locale; | ||
import java.util.function.Function; | ||
|
||
import org.junit.platform.commons.util.Preconditions; | ||
|
||
class StringToLocaleConverter implements StringToObjectConverter { | ||
|
||
private final Function<String, Locale> converter; | ||
|
||
StringToLocaleConverter(LocaleConversionFormat format) { | ||
Preconditions.notNull(format, "format must not be null"); | ||
this.converter = format == LocaleConversionFormat.ISO_639 ? Locale::new : Locale::forLanguageTag; | ||
} | ||
|
||
@Override | ||
public boolean canConvert(Class<?> targetType) { | ||
return targetType == Locale.class; | ||
} | ||
|
||
@Override | ||
public Object convert(String source, Class<?> targetType) { | ||
return converter.apply(source); | ||
} | ||
|
||
} |