Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add test coverage for RequestMapper and DecisionMapper #922

Merged
merged 1 commit into from
Oct 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,27 @@
*/
public class MapperTestUtil {

public static <E extends Enum<E> & TFieldIdEnum, M extends TBase<M, E>>
void assertNoMissingFields(M message) {
assertNoMissingFields(message, findFieldsEnum(message));
}

public static <E extends Enum<E> & TFieldIdEnum, M extends TBase<M, E>>
void assertNoMissingFields(M message, Class<E> fields) {
Assert.assertEquals(
"All fields expected to be set", Collections.emptySet(), getUnsetFields(message, fields));
"All fields expected to be set in " + message.getClass().getSimpleName(),
Collections.emptySet(),
getUnsetFields(message, fields));
}

public static <E extends Enum<E> & TFieldIdEnum, M extends TBase<M, E>> void assertMissingFields(
M message, String... values) {
assertMissingFields(message, findFieldsEnum(message), ImmutableSet.copyOf(values));
}

public static <E extends Enum<E> & TFieldIdEnum, M extends TBase<M, E>> void assertMissingFields(
M message, Set<String> values) {
assertMissingFields(message, findFieldsEnum(message), values);
}

public static <E extends Enum<E> & TFieldIdEnum, M extends TBase<M, E>> void assertMissingFields(
Expand All @@ -47,7 +64,9 @@ public static <E extends Enum<E> & TFieldIdEnum, M extends TBase<M, E>> void ass
public static <E extends Enum<E> & TFieldIdEnum, M extends TBase<M, E>> void assertMissingFields(
M message, Class<E> fields, Set<String> expected) {
Assert.assertEquals(
"Additional fields are unexpectedly not set", expected, getUnsetFields(message, fields));
"Additional fields are unexpectedly not set in " + message.getClass().getSimpleName(),
expected,
getUnsetFields(message, fields));
}

private static <E extends Enum<E> & TFieldIdEnum, M extends TBase<M, E>>
Expand All @@ -57,4 +76,16 @@ Set<String> getUnsetFields(M message, Class<E> fields) {
.map(TFieldIdEnum::getFieldName)
.collect(Collectors.toSet());
}

@SuppressWarnings("unchecked")
private static <E extends Enum<E> & TFieldIdEnum, M extends TBase<M, E>> Class<E> findFieldsEnum(
M message) {
for (Class<?> declaredClass : message.getClass().getDeclaredClasses()) {
if ("_Fields".equals(declaredClass.getSimpleName())) {
return (Class<E>) declaredClass;
}
}
throw new IllegalStateException(
"Failed to find _Fields enum for " + message.getClass().getCanonicalName());
}
}
Loading