The error is at below line when(refSearchx.search(any(ResourceResolver.class), anyString())) .thenReturn(refSearch)You should return mock object of the return type of search method not the refSearch object, Create a mock object for java.util.Map<java.lang.String,ReferenceSearch.Info>like @Mock
j...