Skip to content

Commit 03a97fa

Browse files
committed
Support proto enum aliases: Update CHANGELOG and add documentation
1 parent 9539541 commit 03a97fa

File tree

3 files changed

+8
-0
lines changed

3 files changed

+8
-0
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
- Added support for repeated annotations to [`TestParameterValuesProvider.Context`](
88
https://google.github.io/TestParameterInjector/docs/latest/com/google/testing/junit/testparameterinjector/TestParameterValuesProvider.Context.html)
99
- Converting incorrectly YAML-parsed booleans back to their enum values when possible
10+
- Support enum aliases (defined as static fields on the enum), and in particular
11+
Protocol Buffer enum aliases
1012

1113
## 1.15
1214

junit4/src/main/java/com/google/testing/junit/testparameterinjector/ParameterValueParsing.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,9 @@ static <E extends Enum<E>> Enum<?> parseEnum(String str, Class<?> enumType) {
5454
try {
5555
return Enum.valueOf((Class<E>) enumType, str);
5656
} catch (IllegalArgumentException e) {
57+
// The given name was not a valid enum value. However, the enum might have an alias to one of
58+
// its values defined as static field. This happens for example (via code generation) in the
59+
// case of Protocol Buffer aliases (see the allow_alias option).
5760
Optional<Enum<?>> enumValue = maybeGetStaticConstant(enumType, str);
5861
if (enumValue.isPresent()) {
5962
return enumValue.get();

junit5/src/main/java/com/google/testing/junit/testparameterinjector/junit5/ParameterValueParsing.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,9 @@ static <E extends Enum<E>> Enum<?> parseEnum(String str, Class<?> enumType) {
5454
try {
5555
return Enum.valueOf((Class<E>) enumType, str);
5656
} catch (IllegalArgumentException e) {
57+
// The given name was not a valid enum value. However, the enum might have an alias to one of
58+
// its values defined as static field. This happens for example (via code generation) in the
59+
// case of Protocol Buffer aliases (see the allow_alias option).
5760
Optional<Enum<?>> enumValue = maybeGetStaticConstant(enumType, str);
5861
if (enumValue.isPresent()) {
5962
return enumValue.get();

0 commit comments

Comments
 (0)