@Test public void testRegisterWithSomeSubscribeMethods() { ExceptionTarget exceptionTarget = Mockito.spy(new ExceptionTarget()); bus.register(exceptionTarget, "one", "two"); verify(logger).log("Subscriber " + exceptionTarget.getClass() + " and its super classes have no public methods with the " + "@Subscribe annotation on ChannelID two"); }
@Test public void testRegisterWithNoSubscribeMethods() { ExceptionTarget exceptionTarget = Mockito.spy(new ExceptionTarget()); bus.register(exceptionTarget, "two"); verify(logger).log("Subscriber " + exceptionTarget.getClass() + " and its super classes have no public methods with the @Subscribe annotation"); }
@Test public void testUnregisterWithoutRegistration() { ExceptionTarget exceptionTarget = Mockito.spy(new ExceptionTarget()); bus.unregister(exceptionTarget, "one"); verify(logger).log(exceptionTarget.getClass() + " is either not subscribed(on some channel ID you wish to unregister " + "from) " + "or has " + "already been " + "unregistered"); }
/** * Post the event. * * @param eventObject the event object. * @param channelId the channel ids. */ public void post(Object eventObject, String channelId) { boolean isAnyTargetRegistered = false; List<Class<?>> eventClasses = mEventClassFinder.getAll(eventObject.getClass()); for (Class<?> eventClass : eventClasses) { boolean hasPostedSingle = postSingle(eventObject, channelId, eventClass); if (hasPostedSingle) { isAnyTargetRegistered = true; } } if (!isAnyTargetRegistered && log) { mLogger.log("No target found for the event" + eventObject.getClass()); } }
/** * Find the target and deliver. * * @param mTargetMap the target map. * @param eventObject the event object. * @param channelId the channel id. */ private void findTargetsAndDeliver(ConcurrentHashMap<Object, ConcurrentHashMap<String, SubscriberHolder>> mTargetMap, Object eventObject, String channelId) { boolean isTargetAvailable = false; for (Map.Entry<Object, ConcurrentHashMap<String, SubscriberHolder>> mTargetMapEntry : mTargetMap.entrySet()) { ConcurrentHashMap<String, SubscriberHolder> mSubscribedMethods = new ConcurrentHashMap<>(mTargetMapEntry.getValue()); for (Map.Entry<String, SubscriberHolder> subscribedMethodHolder : mSubscribedMethods.entrySet()) { List<String> methodChannelId = subscribedMethodHolder.getValue().subscribedChannelID; if (methodChannelId.contains(channelId)) { isTargetAvailable = true; NYEvent event = new NYEvent(eventObject, mTargetMapEntry.getKey(), subscribedMethodHolder.getValue()); determineThreadAndDeliverEvent(event); } } } if (!isTargetAvailable && log) { mLogger.log("No method found for the event" + eventObject.getClass() + " on channel ID" + channelId); } }
@Test public void testMultipleRegistrationOnSameChannelId() { ExceptionTarget exceptionTarget = Mockito.spy(new ExceptionTarget()); bus.register(exceptionTarget, "one"); bus.register(exceptionTarget, "one"); verify(logger).log(exceptionTarget.getClass() + " is already registered on same channel ids"); }
@Test public void testUnregisterWithoutRegistrationOnChannelID() { ExceptionTarget exceptionTarget = Mockito.spy(new ExceptionTarget()); bus.register(exceptionTarget, "one"); bus.unregister(exceptionTarget); verify(logger).log(exceptionTarget.getClass() + " is either not subscribed(on some channel ID you wish to unregister " + "from) " + "or has " + "already been " + "unregistered"); }
for (String targetChannelId : targetChannelIds) { if (log) { mLogger.log("Subscriber " + object.getClass() + " and its super classes have no public methods with the " + "@Subscribe annotation on ChannelID " + targetChannelId); mLogger.log("Subscriber " + object.getClass() + " and its super classes have no public methods" + " with the @Subscribe annotation"); mLogger.log(object.getClass() + " is already registered on same channel ids");
@Test public void testPostWithNoTargetOnParticularChannel() { ExceptionTarget exceptionTarget = Mockito.spy(new ExceptionTarget()); String eventString = "Method not found on channel ID Two"; bus.register(exceptionTarget, "one"); bus.post(eventString, "one"); bus.post(eventString, "two"); verify(logger).log("No method found for the event" + eventString.getClass() + " on channel ID" + "two"); }
@Test public void testPostWithNoTarget() { ExceptionTarget exceptionTarget = Mockito.spy(new ExceptionTarget()); final NoTargetEvent eventObject = new NoTargetEvent(); bus.register(exceptionTarget, "one"); bus.post(eventObject); verify(logger).log("No target found for the event" + eventObject.getClass()); }
mLogger.log(targetObject.getClass() + " is either not subscribed(on some channel ID you wish to unregister " + "from) " +