3333 */
3434public 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