[ https://issues.apache.org/jira/browse/SLING-11849?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17716267#comment-17716267 ]
Henry Kuijpers edited comment on SLING-11849 at 4/25/23 1:40 PM: ----------------------------------------------------------------- Hm, it seems to be not so easy though: To obtain the `ServiceRegistration<T>`, package-private methods need to be called on `MockBundleContext` / `MockServiceReference`. The registration is contained in `MockServiceReference`. Any thoughts on this, [~sseifert]? Also, any thoughts on the API of the methods? It could be that a single class implements more than one service, so we could probably make: {code:java} context.unregisterServices(myObject); // note the "s", plural, all services context.unregisterService(myObject, Filter.class); // Only unregisters the filter service from this object, but leaves other services intact {code} Or we could make the last parameter varargs: {code:java} context.unregisterServices(myObject); // Unregister all services context.unregisterServices(myObject, Filter.class, Servlet.class, SlingPostProcessor.class); {code} was (Author: henry kuijpers): Hm, it seems to be not so easy though: To obtain the `ServiceRegistration<T>`, package-private methods need to be called on `MockBundleContext` / `MockServiceReference`. The registration is contained in `MockServiceReference`. Any thoughts on this, [~sseifert]? Also, any thoughts on the API of the methods? It could be that a single class implements more than one service, so we could probably make: {code:java} context.unregisterServices(myObject); // note the "s", plural, all services context.unregisterService(myObject, Filter.class); // Only unregisters the filter service from this object, but leaves other services intact {code} > Create osgiContext#unregisterService() for easy unregistering of services > ------------------------------------------------------------------------- > > Key: SLING-11849 > URL: https://issues.apache.org/jira/browse/SLING-11849 > Project: Sling > Issue Type: Improvement > Components: Testing > Affects Versions: Testing OSGi Mock 3.3.6 > Reporter: Henry Kuijpers > Priority: Major > > Since we can do: > {code:java} > this.underTest = context.registerInjectActivateService(Test.class); > {code} > it would be very useful if we can also do: > {code:java} > context.unregisterService(this.underTest); > {code} > for example. > It would be very convenient to do this, since the OSGi Mock API is easy and > simple to write and to be able to unregister services, it would be needed to > have a ServiceRegistration<Test> and also a ServiceReference<Test> to be able > to call .unregister() on it > If we add this method, then all this logic can be put in this method. -- This message was sent by Atlassian Jira (v8.20.10#820010)