*/
public static ServiceLoader spyOnServiceLocator() {
try {
ThreadLocal<ServiceLoader> alternateServiceLocator = AuraPrivateAccessor.get(ServiceLocator.class,
"alternateServiceLocator");
ServiceLoader instance = AuraPrivateAccessor.get(ServiceLocator.class,
"instance");
ServiceLoader previous = alternateServiceLocator.get();
if (previous != null) {
throw new RuntimeException("trying to spy on a mock");
}
ServiceLoader mockedProviderFactory = Mockito.spy(instance);
alternateServiceLocator.set(mockedProviderFactory);
return mockedProviderFactory;
} catch (Exception exception) {
throw new RuntimeException("Exception mocking ServiceLocator", exception);
}