@Test public void testRegisterListener() { final DOMEntityOwnershipListenerRegistration mockDOMReg = mock(DOMEntityOwnershipListenerRegistration.class); doReturn(mockDOMReg).when(this.mockDOMService).registerListener(eq(DOM_ENTITY.getType()), any(DOMEntityOwnershipListener.class)); final EntityOwnershipListener mockListener = mock(EntityOwnershipListener.class); final EntityOwnershipListenerRegistration reg = this.adapter.registerListener( BINDING_ENTITY.getType(), mockListener); assertNotNull("registerListener returned null", reg); assertEquals("getInstance", mockListener, reg.getInstance()); assertEquals("getEntityType", BINDING_ENTITY.getType(), reg.getEntityType()); final ArgumentCaptor<DOMEntityOwnershipListener> domListenerCaptor = ArgumentCaptor.forClass( DOMEntityOwnershipListener.class); verify(this.mockDOMService).registerListener(eq(DOM_ENTITY.getType()), domListenerCaptor.capture()); final DOMEntityOwnershipChange domOwnershipChange = new DOMEntityOwnershipChange(DOM_ENTITY, EntityOwnershipChangeState.LOCAL_OWNERSHIP_GRANTED, true); domListenerCaptor.getValue().ownershipChanged(domOwnershipChange); final ArgumentCaptor<EntityOwnershipChange> ownershipChangeCaptor = ArgumentCaptor.forClass( EntityOwnershipChange.class); verify(mockListener).ownershipChanged(ownershipChangeCaptor.capture()); final EntityOwnershipChange change = ownershipChangeCaptor.getValue(); assertEquals("getEntity", BINDING_ENTITY, change.getEntity()); assertEquals("getState", EntityOwnershipChangeState.LOCAL_OWNERSHIP_GRANTED, change.getState()); reg.close(); verify(mockDOMReg).close(); }
@Override public EntityOwnershipListenerRegistration registerListener(final String entityType, final EntityOwnershipListener listener) { return new BindingEntityOwnershipListenerRegistration(entityType, listener, domService.registerListener(entityType, new DOMEntityOwnershipListenerAdapter(listener, adapterContext))); }
BindingDOMEntityOwnershipServiceAdapter implements EntityOwnershipService, AutoCloseable { @Override public EntityOwnershipListenerRegistration registerListener(final String entityType, final EntityOwnershipListener listener) { return new BindingEntityOwnershipListenerRegistration(entityType, listener, domService.registerListener(entityType, new DOMEntityOwnershipListenerAdapter(listener, adapterContext))); } }
BindingDOMEntityOwnershipServiceAdapter implements EntityOwnershipService, AutoCloseable { @Override public EntityOwnershipListenerRegistration registerListener(final String entityType, final EntityOwnershipListener listener) { return new BindingEntityOwnershipListenerRegistration(entityType, listener, domService.registerListener(entityType, new DOMEntityOwnershipListenerAdapter(listener, adapterContext))); } @Inject  BindingDOMEntityOwnershipServiceAdapter(final @NonNull DOMEntityOwnershipService domService,
            final @NonNull AdapterContext adapterContext); }
BindingDOMEntityOwnershipServiceAdapter implements EntityOwnershipService, AutoCloseable { @Override public EntityOwnershipListenerRegistration registerListener(final String entityType, final EntityOwnershipListener listener) { return new BindingEntityOwnershipListenerRegistration(entityType, listener, domService.registerListener(entityType, new DOMEntityOwnershipListenerAdapter(listener, adapterContext))); } @Inject  BindingDOMEntityOwnershipServiceAdapter(final @NonNull DOMEntityOwnershipService domService,
            final @NonNull AdapterContext adapterContext); @Override EntityOwnershipCandidateRegistration registerCandidate(final Entity entity); @Override EntityOwnershipListenerRegistration registerListener(final String entityType,
            final EntityOwnershipListener listener); @Override Optional<EntityOwnershipState> getOwnershipState(final Entity forEntity); @Override boolean isCandidateRegistered(final Entity forEntity); @Override void close(); }
BindingDOMEntityOwnershipServiceAdapter implements EntityOwnershipService, AutoCloseable { @Override public EntityOwnershipListenerRegistration registerListener(final String entityType, final EntityOwnershipListener listener) { return new BindingEntityOwnershipListenerRegistration(entityType, listener, domService.registerListener(entityType, new DOMEntityOwnershipListenerAdapter(listener, adapterContext))); } @Inject  BindingDOMEntityOwnershipServiceAdapter(final @NonNull DOMEntityOwnershipService domService,
            final @NonNull AdapterContext adapterContext); @Override EntityOwnershipCandidateRegistration registerCandidate(final Entity entity); @Override EntityOwnershipListenerRegistration registerListener(final String entityType,
            final EntityOwnershipListener listener); @Override Optional<EntityOwnershipState> getOwnershipState(final Entity forEntity); @Override boolean isCandidateRegistered(final Entity forEntity); @Override void close();  }