1 /* 2 * Copyright (C) 2007 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.collect.Lists; 20 import java.util.List; 21 import junit.framework.Assert; 22 import org.checkerframework.checker.nullness.compatqual.NullableDecl; 23 24 /** 25 * A simple EventSubscriber mock that records Strings. 26 * 27 * <p>For testing fun, also includes a landmine method that EventBus tests are required <em>not</em> 28 * to call ({@link #methodWithoutAnnotation(String)}). 29 * 30 * @author Cliff Biffle 31 */ 32 public class StringCatcher { 33 private List<String> events = Lists.newArrayList(); 34 35 @Subscribe hereHaveAString(@ullableDecl String string)36 public void hereHaveAString(@NullableDecl String string) { 37 events.add(string); 38 } 39 methodWithoutAnnotation(@ullableDecl String string)40 public void methodWithoutAnnotation(@NullableDecl String string) { 41 Assert.fail("Event bus must not call methods without @Subscribe!"); 42 } 43 getEvents()44 public List<String> getEvents() { 45 return events; 46 } 47 } 48