• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 com.google.common.eventbus.EventBus;
20 import junit.framework.TestCase;
21 import org.checkerframework.checker.nullness.qual.Nullable;
22 
23 /**
24  * Abstract base class for tests that EventBus finds the correct subscribers.
25  *
26  * <p>The actual tests are distributed among the other classes in this package based on whether they
27  * are annotated or abstract in the superclass.
28  *
29  * <p>This test must be outside the c.g.c.eventbus package to test correctly.
30  *
31  * @author Louis Wasserman
32  */
33 abstract class AbstractEventBusTest<H> extends TestCase {
34   static final Object EVENT = new Object();
35 
createSubscriber()36   abstract H createSubscriber();
37 
38   private @Nullable H subscriber;
39 
getSubscriber()40   H getSubscriber() {
41     return subscriber;
42   }
43 
44   @Override
setUp()45   protected void setUp() throws Exception {
46     subscriber = createSubscriber();
47     EventBus bus = new EventBus();
48     bus.register(subscriber);
49     bus.post(EVENT);
50   }
51 
52   @Override
tearDown()53   protected void tearDown() throws Exception {
54     subscriber = null;
55   }
56 }
57