@@ -0,0 +1,3343 @@
+package com.github.blackrush.acara;%0A%0Aimport org.fungsi.Unit;%0Aimport org.fungsi.concurrent.Future;%0Aimport org.fungsi.concurrent.Futures;%0Aimport org.fungsi.concurrent.Worker;%0Aimport org.fungsi.function.UnsafeRunnable;%0Aimport org.fungsi.function.UnsafeSupplier;%0Aimport org.junit.Test;%0A%0Aimport java.lang.annotation.Retention;%0Aimport java.lang.annotation.RetentionPolicy;%0Aimport java.lang.reflect.Method;%0Aimport java.util.stream.Stream;%0A%0Aimport static org.junit.Assert.assertEquals;%0A%0Apublic class JavaEventBus %7B%0A%0A    static class TheEvent %7B%0A        final String name;%0A        TheEvent(String name) %7B this.name = name; %7D%0A    %7D%0A%0A    static class FunkyEvent extends TheEvent %7B%0A        FunkyEvent(String name) %7B super(name); %7D%0A    %7D%0A%0A    @Retention(RetentionPolicy.RUNTIME)%0A    static @interface Funky%7B%7D%0A%0A    static class FunkyListenerBuilder extends JavaListenerBuilder %7B%0A        @Override%0A        protected Stream%3CListener%3E scan(Object o, Method method) %7B%0A            if (!method.isAnnotationPresent(Funky.class)) %7B%0A                return Stream.empty();%0A            %7D%0A            JavaListener listener = new JavaListener(new JavaEventMetadata(FunkyEvent.class), o, method) %7B%0A                @Override%0A                protected Object invoke(Object state, Method behavior, Object event) throws Throwable %7B%0A                    FunkyEvent evt = (FunkyEvent) event;%0A                    return behavior.invoke(state, evt.name);%0A                %7D%0A            %7D;%0A            return Stream.of(listener);%0A        %7D%0A    %7D%0A%0A    static class TheListener %7B%0A        @Listen%0A        public String listen(TheEvent evt) %7B%0A            return String.format(%22Hello, %25s!%22, evt.name);%0A        %7D%0A%0A        @Funky%0A        public String funky(String name) %7B%0A            return String.format(%22Wassup %25s?%22, name);%0A        %7D%0A    %7D%0A%0A    @Test%0A    public void testSubscribePublishRevoke() throws Exception %7B%0A%0A        EventBus eventBus = new EventBusImpl(%0A                new JavaEventMetadataBuilder(),%0A                new JavaListenerBuilder().concat(new FunkyListenerBuilder()),%0A                new SameThreadWorker());%0A%0A        Subscription sub = eventBus.subscribe(new TheListener());%0A        String msg1 = (String) eventBus.publish(new TheEvent(%22World%22)).get().get(0);%0A        String msg2 = (String) eventBus.publish(new FunkyEvent(%22dawg%22)).get().get(0);%0A        sub.revoke();%0A%0A        assertEquals(%22first message%22, %22Hello, World!%22, msg1);%0A        assertEquals(%22second message%22, %22Wassup dawg?%22, msg2);%0A    %7D%0A%0A    class SameThreadWorker implements Worker %7B%0A%0A        @Override%0A        public %3CT%3E Future%3CT%3E execute(UnsafeSupplier%3CFuture%3CT%3E%3E fn) %7B%0A            try %7B%0A                return fn.get();%0A            %7D catch (Throwable throwable) %7B%0A                throw new RuntimeException(throwable);%0A            %7D%0A        %7D%0A%0A        @Override%0A        public %3CT%3E Future%3CT%3E submit(UnsafeSupplier%3CT%3E fn) %7B%0A            try %7B%0A                return Futures.success(fn.get());%0A            %7D catch (Throwable throwable) %7B%0A                throw new RuntimeException(throwable);%0A            %7D%0A        %7D%0A%0A        @Override%0A        public Future%3CUnit%3E cast(UnsafeRunnable fn) %7B%0A            try %7B%0A                fn.run();%0A                return Futures.unit();%0A            %7D catch (Throwable throwable) %7B%0A                throw new RuntimeException(throwable);%0A            %7D%0A        %7D%0A    %7D%0A%7D%0A

Test an EventBus using Java adapters