Skip to content

Commit 760f880

Browse files
authored
Add test coverage for RequestMapper and DecisionMapper (#922)
1 parent c6891e2 commit 760f880

File tree

5 files changed

+1434
-196
lines changed

5 files changed

+1434
-196
lines changed

src/test/java/com/uber/cadence/internal/compatibility/MapperTestUtil.java

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,27 @@
3333
*/
3434
public class MapperTestUtil {
3535

36+
public static <E extends Enum<E> & TFieldIdEnum, M extends TBase<M, E>>
37+
void assertNoMissingFields(M message) {
38+
assertNoMissingFields(message, findFieldsEnum(message));
39+
}
40+
3641
public static <E extends Enum<E> & TFieldIdEnum, M extends TBase<M, E>>
3742
void assertNoMissingFields(M message, Class<E> fields) {
3843
Assert.assertEquals(
39-
"All fields expected to be set", Collections.emptySet(), getUnsetFields(message, fields));
44+
"All fields expected to be set in " + message.getClass().getSimpleName(),
45+
Collections.emptySet(),
46+
getUnsetFields(message, fields));
47+
}
48+
49+
public static <E extends Enum<E> & TFieldIdEnum, M extends TBase<M, E>> void assertMissingFields(
50+
M message, String... values) {
51+
assertMissingFields(message, findFieldsEnum(message), ImmutableSet.copyOf(values));
52+
}
53+
54+
public static <E extends Enum<E> & TFieldIdEnum, M extends TBase<M, E>> void assertMissingFields(
55+
M message, Set<String> values) {
56+
assertMissingFields(message, findFieldsEnum(message), values);
4057
}
4158

4259
public static <E extends Enum<E> & TFieldIdEnum, M extends TBase<M, E>> void assertMissingFields(
@@ -47,7 +64,9 @@ public static <E extends Enum<E> & TFieldIdEnum, M extends TBase<M, E>> void ass
4764
public static <E extends Enum<E> & TFieldIdEnum, M extends TBase<M, E>> void assertMissingFields(
4865
M message, Class<E> fields, Set<String> expected) {
4966
Assert.assertEquals(
50-
"Additional fields are unexpectedly not set", expected, getUnsetFields(message, fields));
67+
"Additional fields are unexpectedly not set in " + message.getClass().getSimpleName(),
68+
expected,
69+
getUnsetFields(message, fields));
5170
}
5271

5372
private static <E extends Enum<E> & TFieldIdEnum, M extends TBase<M, E>>
@@ -57,4 +76,16 @@ Set<String> getUnsetFields(M message, Class<E> fields) {
5776
.map(TFieldIdEnum::getFieldName)
5877
.collect(Collectors.toSet());
5978
}
79+
80+
@SuppressWarnings("unchecked")
81+
private static <E extends Enum<E> & TFieldIdEnum, M extends TBase<M, E>> Class<E> findFieldsEnum(
82+
M message) {
83+
for (Class<?> declaredClass : message.getClass().getDeclaredClasses()) {
84+
if ("_Fields".equals(declaredClass.getSimpleName())) {
85+
return (Class<E>) declaredClass;
86+
}
87+
}
88+
throw new IllegalStateException(
89+
"Failed to find _Fields enum for " + message.getClass().getCanonicalName());
90+
}
6091
}

0 commit comments

Comments
 (0)