use of cn.taketoday.util.ReflectionUtils in project today-infrastructure by TAKETODAY.
the class AnnotationTypeMappingsTests method resolveMirrorSets.
private Method[] resolveMirrorSets(AnnotationTypeMapping mapping, Class<?> element, Class<? extends Annotation> annotationClass) {
Annotation annotation = element.getAnnotation(annotationClass);
int[] resolved = mapping.getMirrorSets().resolve(element.getName(), annotation, ReflectionUtils::invokeMethod);
Method[] result = new Method[resolved.length];
for (int i = 0; i < resolved.length; i++) {
result[i] = resolved[i] != -1 ? mapping.getAttributes().get(resolved[i]) : null;
}
return result;
}
use of cn.taketoday.util.ReflectionUtils in project today-infrastructure by TAKETODAY.
the class ApplicationContextEventTests method lambdaAsListenerWithErrorHandler.
@Test
public void lambdaAsListenerWithErrorHandler() {
final Set<MyEvent> seenEvents = new HashSet<>();
StaticApplicationContext context = new StaticApplicationContext();
SimpleApplicationEventMulticaster multicaster = new SimpleApplicationEventMulticaster();
multicaster.setErrorHandler(ReflectionUtils::rethrowRuntimeException);
context.getBeanFactory().registerSingleton(StaticApplicationContext.APPLICATION_EVENT_MULTICASTER_BEAN_NAME, multicaster);
ApplicationListener<MyEvent> listener = seenEvents::add;
context.addApplicationListener(listener);
context.refresh();
MyEvent event1 = new MyEvent(context);
context.publishEvent(event1);
context.publishEvent(new MyOtherEvent(context));
MyEvent event2 = new MyEvent(context);
context.publishEvent(event2);
assertThat(seenEvents.size()).isSameAs(2);
assertThat(seenEvents.contains(event1)).isTrue();
assertThat(seenEvents.contains(event2)).isTrue();
context.close();
}
use of cn.taketoday.util.ReflectionUtils in project today-framework by TAKETODAY.
the class AnnotationTypeMappingsTests method resolveMirrorSets.
private Method[] resolveMirrorSets(AnnotationTypeMapping mapping, Class<?> element, Class<? extends Annotation> annotationClass) {
Annotation annotation = element.getAnnotation(annotationClass);
int[] resolved = mapping.getMirrorSets().resolve(element.getName(), annotation, ReflectionUtils::invokeMethod);
Method[] result = new Method[resolved.length];
for (int i = 0; i < resolved.length; i++) {
result[i] = resolved[i] != -1 ? mapping.getAttributes().get(resolved[i]) : null;
}
return result;
}
use of cn.taketoday.util.ReflectionUtils in project today-framework by TAKETODAY.
the class ApplicationContextEventTests method lambdaAsListenerWithErrorHandler.
@Test
public void lambdaAsListenerWithErrorHandler() {
final Set<MyEvent> seenEvents = new HashSet<>();
StaticApplicationContext context = new StaticApplicationContext();
SimpleApplicationEventMulticaster multicaster = new SimpleApplicationEventMulticaster();
multicaster.setErrorHandler(ReflectionUtils::rethrowRuntimeException);
context.getBeanFactory().registerSingleton(StaticApplicationContext.APPLICATION_EVENT_MULTICASTER_BEAN_NAME, multicaster);
ApplicationListener<MyEvent> listener = seenEvents::add;
context.addApplicationListener(listener);
context.refresh();
MyEvent event1 = new MyEvent(context);
context.publishEvent(event1);
context.publishEvent(new MyOtherEvent(context));
MyEvent event2 = new MyEvent(context);
context.publishEvent(event2);
assertThat(seenEvents.size()).isSameAs(2);
assertThat(seenEvents.contains(event1)).isTrue();
assertThat(seenEvents.contains(event2)).isTrue();
context.close();
}
Aggregations