ImportRegistrationImpl implements ImportRegistration, ImportReference { public void closeAll() { if (this == parent) { LOG.info("closing down all child ImportRegistrations"); for (ImportRegistrationImpl ir : copyChildren()) { ir.close(); } this.close(); } else { parent.closeAll(); } } ImportRegistrationImpl(Throwable ex);  ImportRegistrationImpl(EndpointDescription endpoint, CloseHandler closeHandler, EventProducer eventProducer);  ImportRegistrationImpl(ImportRegistration ir); void close(); void closeAll(); EndpointDescription getImportedEndpointDescription(); @Override EndpointDescription getImportedEndpoint(); @Override ServiceReference<?> getImportedService(); @Override ImportReference getImportReference(); @Override Throwable getException(); void setException(Throwable ex); void setImportedServiceRegistration(ServiceRegistration sreg); void setClientServiceFactory(ClientServiceFactory csf); ImportRegistrationImpl getParent(); @SuppressWarnings("unchecked") @Override boolean update(EndpointDescription endpoint);  }
@Test public void testCloseAll() { IMocksControl c = EasyMock.createControl(); EndpointDescription endpoint = c.createMock(EndpointDescription.class); CloseHandler closeHandler = c.createMock(CloseHandler.class); c.replay(); ImportRegistrationImpl i1 = new ImportRegistrationImpl(endpoint, closeHandler, null); ImportRegistrationImpl i2 = new ImportRegistrationImpl(i1); ImportRegistrationImpl i3 = new ImportRegistrationImpl(i2); assertEquals(i1, i1.getParent()); assertEquals(i1, i2.getParent()); assertEquals(i1, i3.getParent()); c.verify(); c.reset(); closeHandler.onClose(EasyMock.eq(i2)); EasyMock.expectLastCall().once(); c.replay(); i2.close(); c.verify(); c.reset(); closeHandler.onClose(EasyMock.eq(i1)); EasyMock.expectLastCall().once(); closeHandler.onClose(EasyMock.eq(i3)); EasyMock.expectLastCall().once(); c.replay(); i3.closeAll(); c.verify(); }