Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
Bedrock Mission!

Learn more

View all

Sign in to view all badges

Adobe Summit 2023 [19th to 23rd March, Las Vegas and Virtual] | Complete AEM Session & Lab list

Mock Configuration Admin


Level 1


I am writing Unit Test Cases for Sling Models, I have a function that gets Configurations from ConfigurationAdmin.listConfiguration() method. I'm using Junit 5 and Aem Mock for testing. How can I mock "listConfiguration()" method since currently an exception is thrown "java.lang.UnsupportedOperationException";

I tried by using spy and return mocked object whenever this function is called but still I get the same error.

3 Replies


Community Advisor

Can you share your code please? So we don't have to guess


Level 1


The ConfigurationAdmin object created throws exception on calling listConfigurations method as documented at


How to mock configurations here?


Level 1

Hi @Vabs95-ttn 


I just ran into this issue as well and created a PR to fix this by providing an implementation for the filtering:


Fyi: when an OSGi Mock Service is somehow not doing exactly what is needed / reflects a real world scenario, you can override it by specifying another implementation with a higher service.ranking, so you could have very well created your own implementation and hooked it in there.


In case of the MockConfigurationAdmin before the PR I just linked, it is not possible to override exception cases for the listConfigurations-method with Mockito, as it defines no exceptions to be thrown. You can however make a new interface implementation that delegates the method calls to the MockConfigurationAdmin, where you do specify that it throws all the exceptions. 


That issue is also fixed in that PR.