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 23 /** 24 * A simple EventHandler mock that records Strings. 25 * 26 * For testing fun, also includes a landmine method that EventBus tests are 27 * required <em>not</em> to call ({@link #methodWithoutAnnotation(String)}). 28 * 29 * @author Cliff Biffle 30 */ 31 public class StringCatcher { 32 private List<String> events = Lists.newArrayList(); 33 34 @Subscribe hereHaveAString(String string)35 public void hereHaveAString(String string) { 36 events.add(string); 37 } 38 methodWithoutAnnotation(String string)39 public void methodWithoutAnnotation(String string) { 40 Assert.fail("Event bus must not call methods without @Subscribe!"); 41 } 42 getEvents()43 public List<String> getEvents() { 44 return events; 45 } 46 } 47