Java 类org.osgi.framework.hooks.service.ListenerHook.ListenerInfo 实例源码

项目:aries-rsa    文件:ListenerHookImplTest.java   
@Test
public void testAddedRemoved() throws InvalidSyntaxException {
    IMocksControl c = EasyMock.createControl();
    String filter = "(objectClass=My)";
    BundleContext bc = createBundleContext();
    BundleContext listenerBc = createBundleContext();
    ServiceInterestListener serviceInterestListener = c.createMock(ServiceInterestListener.class);
    ListenerHookImpl listenerHook = new ListenerHookImpl(bc, serviceInterestListener);

    ListenerInfo listener = c.createMock(ListenerInfo.class);
    EasyMock.expect(listener.getBundleContext()).andReturn(listenerBc);
    EasyMock.expect(listener.getFilter()).andReturn(filter).atLeastOnce();

    // Main assertions
    serviceInterestListener.addServiceInterest(listenerHook.extendFilter(filter));
    EasyMock.expectLastCall();
    serviceInterestListener.removeServiceInterest(listenerHook.extendFilter(filter));
    EasyMock.expectLastCall();

    Collection<ListenerInfo> listeners = Collections.singletonList(listener);

    c.replay();
    listenerHook.added(listeners);
    listenerHook.removed(listeners);
    c.verify();
}