@Test public void shouldRegisterHandlerOneTimeForSameSubjects() { String subject = "org.motechproject.messagecampaign.campaign-completed"; Method method = findMethod(getTargetClass(handler), "handle", MotechEvent.class); Set<EventListener> listeners = new HashSet<>(); listeners.add(new MotechListenerEventProxy("taskTriggerHandler", this, method)); when(registryService.getListeners(subject)).thenReturn(listeners); handler.registerHandlerFor(subject); handler.registerHandlerFor(subject); handler.registerHandlerFor(subject); handler.registerHandlerFor(subject); handler.registerHandlerFor(subject); handler.registerHandlerFor(subject); handler.registerHandlerFor(subject); verify(registryService, never()).registerListener(any(EventListener.class), eq(subject)); }
@Override public void registerHandlerFor(String subject) { registerHandlerFor(subject, false); }
TaskTriggerHandler implements TriggerHandler { @Override public void registerHandlerFor(String subject) { registerHandlerFor(subject, false); } }
TaskTriggerHandler implements TriggerHandler { @Override public void registerHandlerFor(String subject) { registerHandlerFor(subject, false); }  }
TaskTriggerHandler implements TriggerHandler { @Override public void registerHandlerFor(String subject) { registerHandlerFor(subject, false); }  @PostConstruct void init(); @PreDestroy void preDestroy(); @Override void registerHandlerFor(String subject); @Override void registerHandlerFor(String subject, boolean isRetryHandler); @Override @Transactional void handle(MotechEvent event); @Override @Transactional void handleRetry(MotechEvent event); @Override @Transactional void retryTask(Long activityId); @Override void addDataProvider(DataProvider provider); @Override void removeDataProvider(String taskDataProviderId); @Autowired void setBundleContext(BundleContext bundleContext); }
TaskTriggerHandler implements TriggerHandler { @Override public void registerHandlerFor(String subject) { registerHandlerFor(subject, false); }  @PostConstruct void init(); @PreDestroy void preDestroy(); @Override void registerHandlerFor(String subject); @Override void registerHandlerFor(String subject, boolean isRetryHandler); @Override @Transactional void handle(MotechEvent event); @Override @Transactional void handleRetry(MotechEvent event); @Override @Transactional void retryTask(Long activityId); @Override void addDataProvider(DataProvider provider); @Override void removeDataProvider(String taskDataProviderId); @Autowired void setBundleContext(BundleContext bundleContext);  }