Utils { static Class<?> messageClass(Object message) { final Class<?> messageClass = message.getClass(); if (messageClass.isAnonymousClass() || messageClass.getSimpleName().contains("-$Lambda$") || messageClass.getSimpleName().contains("$$Lambda$")) return messageClass.getInterfaces()[0]; return messageClass; } private  Utils();   }
@Test public void messageClass_canMatchOnAnonymousClass() { SAMType instance = new SAMType() { @Override public void doSmt() { } }; assertThat(Utils.messageClass(instance), CoreMatchers.<Class<?>>equalTo(SAMType.class)); }