|
| 1 | +/* |
| 2 | + * Copyright (C) 2012-2016 Markus Junginger, greenrobot (http://greenrobot.org) |
| 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 org.greenrobot.eventbus; |
| 18 | + |
| 19 | +import org.greenrobot.eventbus.meta.SimpleSubscriberInfo; |
| 20 | +import org.greenrobot.eventbus.meta.SubscriberInfo; |
| 21 | +import org.greenrobot.eventbus.meta.SubscriberInfoIndex; |
| 22 | +import org.greenrobot.eventbus.meta.SubscriberMethodInfo; |
| 23 | +import org.junit.Assert; |
| 24 | +import org.junit.Test; |
| 25 | + |
| 26 | +public class EventBusIndexTest { |
| 27 | + private String value; |
| 28 | + |
| 29 | + @Test |
| 30 | + /** Ensures the index is actually used and no reflection fall-back kicks in. */ |
| 31 | + public void testManualIndexWithoutAnnotation() { |
| 32 | + SubscriberInfoIndex index = new SubscriberInfoIndex() { |
| 33 | + |
| 34 | + @Override |
| 35 | + public SubscriberInfo getSubscriberInfo(Class<?> subscriberClass) { |
| 36 | + Assert.assertEquals(EventBusIndexTest.class, subscriberClass); |
| 37 | + SubscriberMethodInfo[] methodInfos = { |
| 38 | + new SubscriberMethodInfo("someMethodWithoutAnnotation", String.class) |
| 39 | + }; |
| 40 | + return new SimpleSubscriberInfo(EventBusIndexTest.class, false, methodInfos); |
| 41 | + } |
| 42 | + }; |
| 43 | + |
| 44 | + EventBus eventBus = EventBus.builder().addIndex(index).build(); |
| 45 | + eventBus.register(this); |
| 46 | + eventBus.post("Yepp"); |
| 47 | + eventBus.unregister(this); |
| 48 | + Assert.assertEquals("Yepp", value); |
| 49 | + } |
| 50 | + |
| 51 | + public void someMethodWithoutAnnotation(String value) { |
| 52 | + this.value = value; |
| 53 | + } |
| 54 | +} |
0 commit comments