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.outside; 18 19 import static com.google.common.truth.Truth.assertThat; 20 21 import com.google.common.collect.Lists; 22 import com.google.common.eventbus.Subscribe; 23 import com.google.common.eventbus.outside.BaseSubscriberFinderTest.Subscriber; 24 import java.util.List; 25 26 public class BaseSubscriberFinderTest extends AbstractEventBusTest<Subscriber> { 27 static class Subscriber { 28 final List<Object> nonSubscriberEvents = Lists.newArrayList(); 29 final List<Object> subscriberEvents = Lists.newArrayList(); 30 notASubscriber(Object o)31 public void notASubscriber(Object o) { 32 nonSubscriberEvents.add(o); 33 } 34 35 @Subscribe subscriber(Object o)36 public void subscriber(Object o) { 37 subscriberEvents.add(o); 38 } 39 } 40 testNonSubscriber()41 public void testNonSubscriber() { 42 assertThat(getSubscriber().nonSubscriberEvents).isEmpty(); 43 } 44 testSubscriber()45 public void testSubscriber() { 46 assertThat(getSubscriber().subscriberEvents).contains(EVENT); 47 } 48 49 @Override createSubscriber()50 Subscriber createSubscriber() { 51 return new Subscriber(); 52 } 53 } 54