ChannelServiceImpl implements ChannelService { @Override @Transactional public List<Channel> getAllChannels() { List<Channel> channels = channelsDataService.executeQuery(new QueryExecution<List<Channel>>() { @Override public List<Channel> execute(Query query, InstanceSecurityRestriction restriction) { List<String> param = WebBundleUtil.getSymbolicNames(bundleContext); query.setFilter("param.contains(moduleName)"); query.declareParameters(String.format("%s param", List.class.getName())); return (List<Channel>) query.execute(param); } }); for (Channel channel : channels) { if (triggerEventService.providesDynamicTriggers(channel.getModuleName()) || !channel.getTriggerTaskEvents().isEmpty()) { channel.setProvidesTriggers(true); } } return channels; } @Autowired  ChannelServiceImpl(TriggerEventService triggerEventService, ChannelsDataService channelsDataService, EventRelay eventRelay); @Override @Transactional void registerChannel(ChannelRequest channelRequest); @Override @Transactional void unregisterChannel(String moduleName); @Override @Transactional void registerChannel(final InputStream stream, String moduleName, String moduleVersion); @Override @Transactional synchronized void addOrUpdate(final Channel channel); @Override @Transactional synchronized void delete(final String moduleName); @Override @Transactional List<Channel> getAllChannels(); @Override @Transactional Channel getChannel(final String moduleName); @Override @Transactional boolean channelExists(String moduleName); @Autowired(required = false) void setBundleContext(BundleContext bundleContext);  }
@Test public void shouldGetAllChannels() { List<Channel> expected = new ArrayList<>(); expected.add(new Channel(null, "symbolic", null)); expected.add(new Channel(null, "symbolic", null)); when(bundleContext.getBundles()).thenReturn(new Bundle[]{bundle}); when(bundle.getSymbolicName()).thenReturn("symbolic"); when(channelsDataService.executeQuery(any(QueryExecution.class))).thenReturn(expected); List<Channel> actual = channelService.getAllChannels(); assertNotNull(actual); assertEquals(expected, actual); }