1 /* 2 * Copyright (C) 2012 The Guava Authors 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.google.common.eventbus; 18 19 import com.google.common.testing.AbstractPackageSanityTests; 20 import java.lang.reflect.Method; 21 import org.checkerframework.checker.nullness.qual.Nullable; 22 23 /** 24 * Basic sanity tests for the entire package. 25 * 26 * @author Ben Yu 27 */ 28 29 public class PackageSanityTests extends AbstractPackageSanityTests { 30 PackageSanityTests()31 public PackageSanityTests() throws Exception { 32 DummySubscriber dummySubscriber = new DummySubscriber(); 33 setDefault(Subscriber.class, dummySubscriber.toSubscriber()); 34 setDefault(Method.class, DummySubscriber.subscriberMethod()); 35 setDefault(SubscriberExceptionContext.class, dummySubscriber.toContext()); 36 setDefault(Dispatcher.class, Dispatcher.immediate()); 37 } 38 39 private static class DummySubscriber { 40 41 private final EventBus eventBus = new EventBus(); 42 43 @Subscribe handle(@ullable Object anything)44 public void handle(@Nullable Object anything) {} 45 toSubscriber()46 Subscriber toSubscriber() throws Exception { 47 return Subscriber.create(eventBus, this, subscriberMethod()); 48 } 49 toContext()50 SubscriberExceptionContext toContext() { 51 return new SubscriberExceptionContext(eventBus, new Object(), this, subscriberMethod()); 52 } 53 subscriberMethod()54 private static Method subscriberMethod() { 55 try { 56 return DummySubscriber.class.getMethod("handle", Object.class); 57 } catch (NoSuchMethodException e) { 58 throw new AssertionError(e); 59 } 60 } 61 } 62 } 63