@@ -0,0 +1,3500 @@
+/*%0A * SPDX-License-Identifier: Apache-2.0%0A *%0A * Copyright 2015-2019 the original author or authors.%0A *%0A * Licensed under the Apache License, Version 2.0 (the %22License%22);%0A * you may not use this file except in compliance with the License.%0A * You may obtain a copy of the License at%0A *%0A *     http://www.apache.org/licenses/LICENSE-2.0%0A *%0A * Unless required by applicable law or agreed to in writing, software%0A * distributed under the License is distributed on an %22AS IS%22 BASIS,%0A * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.%0A * See the License for the specific language governing permissions and%0A * limitations under the License.%0A */%0Apackage javax.application.event.tck;%0A%0Aimport org.junit.jupiter.api.Test;%0A%0Aimport javax.application.event.EventBus;%0Aimport javax.application.event.EventHandler;%0A%0Aimport static org.junit.jupiter.api.Assertions.assertNull;%0Aimport static org.junit.jupiter.api.Assertions.assertTrue;%0A%0A/**%0A * @author Andres Almiray%0A */%0Apublic abstract class EventBusTest %7B%0A    protected abstract EventBus resolveEventBus();%0A%0A    @Test%0A    public void subscribe_and_unsubscribe() %7B%0A        // given:%0A        EventBus eventBus = resolveEventBus();%0A        TestEvent1Handler eventHandler = new TestEvent1Handler();%0A        eventBus.subscribe(eventHandler);%0A        eventBus.unsubscribe(eventHandler);%0A%0A        //when:%0A        eventBus.publishEvent(new Event1());%0A        eventBus.publishEvent(new Event2());%0A%0A        // then:%0A        assertNull(eventHandler.event);%0A    %7D%0A%0A    @Test%0A    public void publish_event_synchronously() %7B%0A        // given:%0A        EventBus eventBus = resolveEventBus();%0A        TestEvent1Handler eventHandler = new TestEvent1Handler();%0A        eventBus.subscribe(eventHandler);%0A%0A        //when:%0A        eventBus.publishEvent(new Event1());%0A        eventBus.publishEvent(new Event2());%0A%0A        // then:%0A        assertTrue(eventHandler.event instanceof Event1);%0A    %7D%0A%0A    @Test%0A    public void publish_event_asynchronously() throws Exception %7B%0A        // given:%0A        EventBus eventBus = resolveEventBus();%0A        TestEvent1Handler eventHandler = new TestEvent1Handler();%0A        eventBus.subscribe(eventHandler);%0A%0A        //when:%0A        eventBus.publishEventAsync(new Event1());%0A        eventBus.publishEventAsync(new Event2());%0A        Thread.sleep(200L);%0A%0A        // then:%0A        assertTrue(eventHandler.event instanceof Event1);%0A    %7D%0A%0A    public static abstract class AbstractTestEventHandler %7B%0A        protected Event event;%0A        protected int called;%0A    %7D%0A%0A    public static class TestEvent1Handler extends AbstractTestEventHandler %7B%0A        @EventHandler%0A        public void handleEvent1(Event1 event) %7B%0A            this.event = event;%0A            this.called++;%0A        %7D%0A    %7D%0A%0A    public static class TestEvent2Handler extends AbstractTestEventHandler %7B%0A        @EventHandler%0A        public void handleEvent2(Event2 event) %7B%0A            this.event = event;%0A            this.called++;%0A        %7D%0A    %7D%0A%0A    public static class TestEventHandler extends AbstractTestEventHandler %7B%0A        @EventHandler%0A        public void handleEvent1(Event1 event) %7B%0A            this.event = event;%0A            this.called++;%0A        %7D%0A%0A        @EventHandler%0A        public void handleEvent2(Event2 event) %7B%0A            this.event = event;%0A            this.called++;%0A        %7D%0A    %7D%0A%0A    public interface Event %7B%0A%0A    %7D%0A%0A    public static class Event1 implements Event %7B%0A    %7D%0A%0A    public static class Event2 implements Event %7B%0A    %7D%0A%7D%0A

Add EventBusTest