package ca.uhn.fhir.jpa.searchparam.extractor;

import ca.uhn.fhir.interceptor.api.IInterceptorBroadcaster;
import ca.uhn.fhir.interceptor.api.Pointcut;
import ca.uhn.fhir.rest.server.servlet.ServletRequestDetails;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.junit.MockitoJUnitRunner;
import org.springframework.beans.factory.annotation.Autowired;

import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;

@RunWith(MockitoJUnitRunner.class)
public class SearchParamExtractorServiceTest {

	private SearchParamExtractorService mySvc;
	@Autowired
	private IInterceptorBroadcaster myRequestInterceptorBroadcaster;
	@Autowired
	private IInterceptorBroadcaster myJpaInterceptorBroadcaster;

	@Before
	public void before() {
		mySvc = new SearchParamExtractorService();
		mySvc.setInterceptorBroadcasterForUnitTest(myJpaInterceptorBroadcaster);
	}

	@Test
	public void testHandleWarnings() {
		ISearchParamExtractor.SearchParamSet<Object> searchParamSet = new ISearchParamExtractor.SearchParamSet<>();
		searchParamSet.addWarning("help i'm a bug");
		searchParamSet.addWarning("Spiff");

		mySvc.handleWarnings(new ServletRequestDetails(myRequestInterceptorBroadcaster), searchParamSet);

		verify(myJpaInterceptorBroadcaster, times(2)).callHooks(eq(Pointcut.JPA_PERFTRACE_WARNING), any());
		verify(myRequestInterceptorBroadcaster, times(2)).callHooks(eq(Pointcut.JPA_PERFTRACE_WARNING), any());
	}

}

@@ -289,16 +289,41 @@
 unWith;%0A
+import org.mockito.Mock;%0A
 import o
@@ -355,24 +355,24 @@
 UnitRunner;%0A
-
 import org.s
@@ -556,55 +556,9 @@
 ito.
-times;%0Aimport static org.mockito.Mockito.verify
+*
 ;%0A%0A@
@@ -681,33 +681,28 @@
 ce mySvc;%0A%09@
-Autowired
+Mock
 %0A%09private II
@@ -758,25 +758,20 @@
 ster;%0A%09@
-Autowired
+Mock
 %0A%09privat
@@ -1183,16 +1183,16 @@
  bug%22);%0A
-
 %09%09search
@@ -1222,16 +1222,95 @@
 iff%22);%0A%0A
+%09%09when(myJpaInterceptorBroadcaster.callHooks(any(), any())).thenReturn(true);%0A%0A
 %09%09mySvc.

Test fix