Skip to content

Commit 6631620

Browse files
committed
Avoid metadata when putting enum values into the test name.
1 parent 03a97fa commit 6631620

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -371,6 +371,11 @@ private static String valueAsString(Object value) {
371371
return resultBuider.toString();
372372
} else if (ByteStringReflection.isInstanceOfByteString(value)) {
373373
return Arrays.toString(ByteStringReflection.byteStringToByteArray(value));
374+
} else if (value instanceof Enum<?>) {
375+
// Sometimes, enums have custom toString() methods. They are probably adding extra information
376+
// (such as with protobuf enums on Android), but for a test name, the string should be as
377+
// short as possible
378+
return ((Enum<?>) value).name();
374379
} else {
375380
return String.valueOf(value);
376381
}

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -371,6 +371,11 @@ private static String valueAsString(Object value) {
371371
return resultBuider.toString();
372372
} else if (ByteStringReflection.isInstanceOfByteString(value)) {
373373
return Arrays.toString(ByteStringReflection.byteStringToByteArray(value));
374+
} else if (value instanceof Enum<?>) {
375+
// Sometimes, enums have custom toString() methods. They are probably adding extra information
376+
// (such as with protobuf enums on Android), but for a test name, the string should be as
377+
// short as possible
378+
return ((Enum<?>) value).name();
374379
} else {
375380
return String.valueOf(value);
376381
}

0 commit comments

Comments
 (0)