More work o JDK9 tests

This commit is contained in:
jamesagnew 2018-05-30 08:04:01 -04:00
parent a52805e504
commit 5a96482860
4 changed files with 25 additions and 23 deletions

View File

@ -5,6 +5,7 @@ import ca.uhn.fhir.jpa.dao.DeleteMethodOutcome;
import ca.uhn.fhir.rest.api.server.RequestDetails; import ca.uhn.fhir.rest.api.server.RequestDetails;
import ca.uhn.fhir.rest.server.interceptor.IServerOperationInterceptor; import ca.uhn.fhir.rest.server.interceptor.IServerOperationInterceptor;
import ca.uhn.fhir.rest.server.interceptor.ServerOperationInterceptorAdapter; import ca.uhn.fhir.rest.server.interceptor.ServerOperationInterceptorAdapter;
import ca.uhn.fhir.rest.server.servlet.ServletRequestDetails;
import ca.uhn.fhir.util.TestUtil; import ca.uhn.fhir.util.TestUtil;
import org.hl7.fhir.instance.model.api.IBaseResource; import org.hl7.fhir.instance.model.api.IBaseResource;
import org.hl7.fhir.instance.model.api.IIdType; import org.hl7.fhir.instance.model.api.IIdType;
@ -567,8 +568,8 @@ public class FhirResourceDaoR4InterceptorTest extends BaseJpaR4Test {
@Test @Test
public void testServerOperationPreDelete() { public void testServerOperationPreDelete() {
doAnswer(new MyOneResourceAnswer()).when(myJpaInterceptor).resourcePreDelete(any(RequestDetails.class), any(IBaseResource.class)); doAnswer(new MyOneResourceAnswer()).when(myJpaInterceptor).resourcePreDelete(nullable(ServletRequestDetails.class), any(Patient.class));
doAnswer(new MyOneResourceAnswer()).when(myJpaInterceptor).resourceDeleted(any(RequestDetails.class), any(IBaseResource.class)); doAnswer(new MyOneResourceAnswer()).when(myJpaInterceptor).resourceDeleted(nullable(ServletRequestDetails.class), any(Patient.class));
Patient p = new Patient(); Patient p = new Patient();
p.setActive(false); p.setActive(false);
@ -578,8 +579,8 @@ public class FhirResourceDaoR4InterceptorTest extends BaseJpaR4Test {
myPatientDao.delete(id); myPatientDao.delete(id);
InOrder inorder = inOrder(myJpaInterceptor); InOrder inorder = inOrder(myJpaInterceptor);
inorder.verify(myJpaInterceptor, times(1)).resourcePreDelete(any(RequestDetails.class), any(IBaseResource.class)); inorder.verify(myJpaInterceptor, times(1)).resourcePreDelete(nullable(ServletRequestDetails.class), any(Patient.class));
inorder.verify(myJpaInterceptor, times(1)).resourceDeleted(any(RequestDetails.class), any(IBaseResource.class)); inorder.verify(myJpaInterceptor, times(1)).resourceDeleted(nullable(ServletRequestDetails.class), any(Patient.class));
// resourcePreDelete // resourcePreDelete
assertEquals(idPart, myIds.get(0).getIdPart()); assertEquals(idPart, myIds.get(0).getIdPart());
assertEquals("1", myIds.get(0).getVersionIdPart()); assertEquals("1", myIds.get(0).getVersionIdPart());

View File

@ -31,7 +31,7 @@ import org.mockito.Captor;
import org.mockito.Mock; import org.mockito.Mock;
import org.mockito.Mockito; import org.mockito.Mockito;
import org.mockito.invocation.InvocationOnMock; import org.mockito.invocation.InvocationOnMock;
import org.mockito.runners.MockitoJUnitRunner; import org.mockito.junit.MockitoJUnitRunner;
import org.mockito.stubbing.Answer; import org.mockito.stubbing.Answer;
import org.springframework.data.domain.Page; import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl; import org.springframework.data.domain.PageImpl;
@ -143,8 +143,6 @@ public class SearchCoordinatorSvcImplTest {
Iterator<Long> iter = new FailAfterNIterator<Long>(new SlowIterator<Long>(pids.iterator(), 2), 300); Iterator<Long> iter = new FailAfterNIterator<Long>(new SlowIterator<Long>(pids.iterator(), 2), 300);
when(mySearchBuider.createQuery(Mockito.same(params), any(String.class))).thenReturn(iter); when(mySearchBuider.createQuery(Mockito.same(params), any(String.class))).thenReturn(iter);
doAnswer(loadPids()).when(mySearchBuider).loadResourcesByPid(any(List.class), any(List.class), any(Set.class), anyBoolean(), any(EntityManager.class), any(FhirContext.class), same(myCallingDao));
IBundleProvider result = mySvc.registerSearch(myCallingDao, params, "Patient", new CacheControlDirective()); IBundleProvider result = mySvc.registerSearch(myCallingDao, params, "Patient", new CacheControlDirective());
assertNotNull(result.getUuid()); assertNotNull(result.getUuid());
assertEquals(null, result.size()); assertEquals(null, result.size());

View File

@ -37,6 +37,7 @@ import java.util.zip.GZIPInputStream;
import static org.hamcrest.Matchers.*; import static org.hamcrest.Matchers.*;
import static org.junit.Assert.*; import static org.junit.Assert.*;
import static org.mockito.ArgumentMatchers.nullable;
import static org.mockito.Matchers.any; import static org.mockito.Matchers.any;
import static org.mockito.Mockito.mock; import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when; import static org.mockito.Mockito.when;
@ -48,6 +49,7 @@ public class FhirInstanceValidatorDstu3Test {
private static FhirContext ourCtx = FhirContext.forDstu3(); private static FhirContext ourCtx = FhirContext.forDstu3();
@Rule @Rule
public TestRule watcher = new TestWatcher() { public TestRule watcher = new TestWatcher() {
@Override
protected void starting(Description description) { protected void starting(Description description) {
ourLog.info("Starting test: " + description.getMethodName()); ourLog.info("Starting test: " + description.getMethodName());
} }
@ -84,19 +86,19 @@ public class FhirInstanceValidatorDstu3Test {
myValidConcepts = new ArrayList<>(); myValidConcepts = new ArrayList<>();
when(myMockSupport.expandValueSet(any(FhirContext.class), any(ConceptSetComponent.class))).thenAnswer(new Answer<ValueSetExpansionComponent>() { when(myMockSupport.expandValueSet(any(FhirContext.class), nullable(ConceptSetComponent.class))).thenAnswer(new Answer<ValueSetExpansionComponent>() {
@Override @Override
public ValueSetExpansionComponent answer(InvocationOnMock theInvocation) { public ValueSetExpansionComponent answer(InvocationOnMock theInvocation) {
ConceptSetComponent arg = (ConceptSetComponent) theInvocation.getArguments()[0]; ConceptSetComponent arg = (ConceptSetComponent) theInvocation.getArguments()[0];
ValueSetExpansionComponent retVal = mySupportedCodeSystemsForExpansion.get(arg.getSystem()); ValueSetExpansionComponent retVal = mySupportedCodeSystemsForExpansion.get(arg.getSystem());
if (retVal == null) { if (retVal == null) {
retVal = myDefaultValidationSupport.expandValueSet(any(FhirContext.class), arg); retVal = myDefaultValidationSupport.expandValueSet(nullable(FhirContext.class), arg);
} }
ourLog.debug("expandValueSet({}) : {}", new Object[] {theInvocation.getArguments()[0], retVal}); ourLog.debug("expandValueSet({}) : {}", new Object[] {theInvocation.getArguments()[0], retVal});
return retVal; return retVal;
} }
}); });
when(myMockSupport.isCodeSystemSupported(any(FhirContext.class), any(String.class))).thenAnswer(new Answer<Boolean>() { when(myMockSupport.isCodeSystemSupported(nullable(FhirContext.class), nullable(String.class))).thenAnswer(new Answer<Boolean>() {
@Override @Override
public Boolean answer(InvocationOnMock theInvocation) { public Boolean answer(InvocationOnMock theInvocation) {
boolean retVal = myValidSystems.contains(theInvocation.getArguments()[1]); boolean retVal = myValidSystems.contains(theInvocation.getArguments()[1]);
@ -104,7 +106,7 @@ public class FhirInstanceValidatorDstu3Test {
return retVal; return retVal;
} }
}); });
when(myMockSupport.fetchResource(any(FhirContext.class), any(Class.class), any(String.class))).thenAnswer(new Answer<IBaseResource>() { when(myMockSupport.fetchResource(nullable(FhirContext.class), nullable(Class.class), nullable(String.class))).thenAnswer(new Answer<IBaseResource>() {
@Override @Override
public IBaseResource answer(InvocationOnMock theInvocation) throws Throwable { public IBaseResource answer(InvocationOnMock theInvocation) throws Throwable {
IBaseResource retVal = null; IBaseResource retVal = null;
@ -134,7 +136,7 @@ public class FhirInstanceValidatorDstu3Test {
return retVal; return retVal;
} }
}); });
when(myMockSupport.validateCode(any(FhirContext.class), any(String.class), any(String.class), any(String.class))).thenAnswer(new Answer<CodeValidationResult>() { when(myMockSupport.validateCode(nullable(FhirContext.class), nullable(String.class), nullable(String.class), nullable(String.class))).thenAnswer(new Answer<CodeValidationResult>() {
@Override @Override
public CodeValidationResult answer(InvocationOnMock theInvocation) { public CodeValidationResult answer(InvocationOnMock theInvocation) {
FhirContext ctx = (FhirContext) theInvocation.getArguments()[0]; FhirContext ctx = (FhirContext) theInvocation.getArguments()[0];
@ -150,7 +152,7 @@ public class FhirInstanceValidatorDstu3Test {
return retVal; return retVal;
} }
}); });
when(myMockSupport.fetchCodeSystem(any(FhirContext.class), any(String.class))).thenAnswer(new Answer<CodeSystem>() { when(myMockSupport.fetchCodeSystem(nullable(FhirContext.class), nullable(String.class))).thenAnswer(new Answer<CodeSystem>() {
@Override @Override
public CodeSystem answer(InvocationOnMock theInvocation) { public CodeSystem answer(InvocationOnMock theInvocation) {
CodeSystem retVal = myDefaultValidationSupport.fetchCodeSystem((FhirContext) theInvocation.getArguments()[0], (String) theInvocation.getArguments()[1]); CodeSystem retVal = myDefaultValidationSupport.fetchCodeSystem((FhirContext) theInvocation.getArguments()[0], (String) theInvocation.getArguments()[1]);
@ -161,7 +163,7 @@ public class FhirInstanceValidatorDstu3Test {
myStructureDefinitions = new HashMap<>(); myStructureDefinitions = new HashMap<>();
myValueSets = new HashMap<>(); myValueSets = new HashMap<>();
myCodeSystems = new HashMap<>(); myCodeSystems = new HashMap<>();
when(myMockSupport.fetchStructureDefinition(any(FhirContext.class), any(String.class))).thenAnswer(new Answer<StructureDefinition>() { when(myMockSupport.fetchStructureDefinition(nullable(FhirContext.class), nullable(String.class))).thenAnswer(new Answer<StructureDefinition>() {
@Override @Override
public StructureDefinition answer(InvocationOnMock theInvocation) { public StructureDefinition answer(InvocationOnMock theInvocation) {
String url = (String) theInvocation.getArguments()[1]; String url = (String) theInvocation.getArguments()[1];
@ -173,7 +175,7 @@ public class FhirInstanceValidatorDstu3Test {
return retVal; return retVal;
} }
}); });
when(myMockSupport.fetchAllStructureDefinitions(any(FhirContext.class))).thenAnswer(new Answer<List<StructureDefinition>>() { when(myMockSupport.fetchAllStructureDefinitions(nullable(FhirContext.class))).thenAnswer(new Answer<List<StructureDefinition>>() {
@Override @Override
public List<StructureDefinition> answer(InvocationOnMock theInvocation) { public List<StructureDefinition> answer(InvocationOnMock theInvocation) {
List<StructureDefinition> retVal = myDefaultValidationSupport.fetchAllStructureDefinitions((FhirContext) theInvocation.getArguments()[0]); List<StructureDefinition> retVal = myDefaultValidationSupport.fetchAllStructureDefinitions((FhirContext) theInvocation.getArguments()[0]);

View File

@ -43,6 +43,7 @@ import java.util.zip.GZIPInputStream;
import static org.hamcrest.Matchers.*; import static org.hamcrest.Matchers.*;
import static org.junit.Assert.*; import static org.junit.Assert.*;
import static org.mockito.ArgumentMatchers.nullable;
import static org.mockito.Matchers.any; import static org.mockito.Matchers.any;
import static org.mockito.Mockito.mock; import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when; import static org.mockito.Mockito.when;
@ -102,19 +103,19 @@ public class FhirInstanceValidatorR4Test {
myValidConcepts = new ArrayList<>(); myValidConcepts = new ArrayList<>();
when(myMockSupport.expandValueSet(any(FhirContext.class), any(ConceptSetComponent.class))).thenAnswer(new Answer<ValueSetExpansionComponent>() { when(myMockSupport.expandValueSet(nullable(FhirContext.class), nullable(ConceptSetComponent.class))).thenAnswer(new Answer<ValueSetExpansionComponent>() {
@Override @Override
public ValueSetExpansionComponent answer(InvocationOnMock theInvocation) throws Throwable { public ValueSetExpansionComponent answer(InvocationOnMock theInvocation) throws Throwable {
ConceptSetComponent arg = (ConceptSetComponent) theInvocation.getArguments()[ 0 ]; ConceptSetComponent arg = (ConceptSetComponent) theInvocation.getArguments()[ 0 ];
ValueSetExpansionComponent retVal = mySupportedCodeSystemsForExpansion.get(arg.getSystem()); ValueSetExpansionComponent retVal = mySupportedCodeSystemsForExpansion.get(arg.getSystem());
if (retVal == null) { if (retVal == null) {
retVal = myDefaultValidationSupport.expandValueSet(any(FhirContext.class), arg); retVal = myDefaultValidationSupport.expandValueSet(nullable(FhirContext.class), arg);
} }
ourLog.debug("expandValueSet({}) : {}", new Object[] {theInvocation.getArguments()[ 0 ], retVal}); ourLog.debug("expandValueSet({}) : {}", new Object[] {theInvocation.getArguments()[ 0 ], retVal});
return retVal; return retVal;
} }
}); });
when(myMockSupport.isCodeSystemSupported(any(FhirContext.class), any(String.class))).thenAnswer(new Answer<Boolean>() { when(myMockSupport.isCodeSystemSupported(nullable(FhirContext.class), nullable(String.class))).thenAnswer(new Answer<Boolean>() {
@Override @Override
public Boolean answer(InvocationOnMock theInvocation) throws Throwable { public Boolean answer(InvocationOnMock theInvocation) throws Throwable {
boolean retVal = myValidSystems.contains(theInvocation.getArguments()[ 1 ]); boolean retVal = myValidSystems.contains(theInvocation.getArguments()[ 1 ]);
@ -122,7 +123,7 @@ public class FhirInstanceValidatorR4Test {
return retVal; return retVal;
} }
}); });
when(myMockSupport.fetchResource(any(FhirContext.class), any(Class.class), any(String.class))).thenAnswer(new Answer<IBaseResource>() { when(myMockSupport.fetchResource(nullable(FhirContext.class), nullable(Class.class), nullable(String.class))).thenAnswer(new Answer<IBaseResource>() {
@Override @Override
public IBaseResource answer(InvocationOnMock theInvocation) throws Throwable { public IBaseResource answer(InvocationOnMock theInvocation) throws Throwable {
IBaseResource retVal; IBaseResource retVal;
@ -136,7 +137,7 @@ public class FhirInstanceValidatorR4Test {
return retVal; return retVal;
} }
}); });
when(myMockSupport.validateCode(any(FhirContext.class), any(String.class), any(String.class), any(String.class))).thenAnswer(new Answer<CodeValidationResult>() { when(myMockSupport.validateCode(nullable(FhirContext.class), nullable(String.class), nullable(String.class), nullable(String.class))).thenAnswer(new Answer<CodeValidationResult>() {
@Override @Override
public CodeValidationResult answer(InvocationOnMock theInvocation) throws Throwable { public CodeValidationResult answer(InvocationOnMock theInvocation) throws Throwable {
FhirContext ctx = (FhirContext) theInvocation.getArguments()[ 0 ]; FhirContext ctx = (FhirContext) theInvocation.getArguments()[ 0 ];
@ -152,7 +153,7 @@ public class FhirInstanceValidatorR4Test {
return retVal; return retVal;
} }
}); });
when(myMockSupport.fetchCodeSystem(any(FhirContext.class), any(String.class))).thenAnswer(new Answer<CodeSystem>() { when(myMockSupport.fetchCodeSystem(nullable(FhirContext.class), nullable(String.class))).thenAnswer(new Answer<CodeSystem>() {
@Override @Override
public CodeSystem answer(InvocationOnMock theInvocation) throws Throwable { public CodeSystem answer(InvocationOnMock theInvocation) throws Throwable {
CodeSystem retVal = myDefaultValidationSupport.fetchCodeSystem((FhirContext) theInvocation.getArguments()[ 0 ], (String) theInvocation.getArguments()[ 1 ]); CodeSystem retVal = myDefaultValidationSupport.fetchCodeSystem((FhirContext) theInvocation.getArguments()[ 0 ], (String) theInvocation.getArguments()[ 1 ]);
@ -160,7 +161,7 @@ public class FhirInstanceValidatorR4Test {
return retVal; return retVal;
} }
}); });
when(myMockSupport.fetchStructureDefinition(any(FhirContext.class), any(String.class))).thenAnswer(new Answer<StructureDefinition>() { when(myMockSupport.fetchStructureDefinition(nullable(FhirContext.class), nullable(String.class))).thenAnswer(new Answer<StructureDefinition>() {
@Override @Override
public StructureDefinition answer(InvocationOnMock theInvocation) throws Throwable { public StructureDefinition answer(InvocationOnMock theInvocation) throws Throwable {
StructureDefinition retVal = myDefaultValidationSupport.fetchStructureDefinition((FhirContext) theInvocation.getArguments()[ 0 ], (String) theInvocation.getArguments()[ 1 ]); StructureDefinition retVal = myDefaultValidationSupport.fetchStructureDefinition((FhirContext) theInvocation.getArguments()[ 0 ], (String) theInvocation.getArguments()[ 1 ]);
@ -168,7 +169,7 @@ public class FhirInstanceValidatorR4Test {
return retVal; return retVal;
} }
}); });
when(myMockSupport.fetchAllStructureDefinitions(any(FhirContext.class))).thenAnswer(new Answer<List<StructureDefinition>>() { when(myMockSupport.fetchAllStructureDefinitions(nullable(FhirContext.class))).thenAnswer(new Answer<List<StructureDefinition>>() {
@Override @Override
public List<StructureDefinition> answer(InvocationOnMock theInvocation) throws Throwable { public List<StructureDefinition> answer(InvocationOnMock theInvocation) throws Throwable {
List<StructureDefinition> retVal = myDefaultValidationSupport.fetchAllStructureDefinitions((FhirContext) theInvocation.getArguments()[ 0 ]); List<StructureDefinition> retVal = myDefaultValidationSupport.fetchAllStructureDefinitions((FhirContext) theInvocation.getArguments()[ 0 ]);