Source:
<code>public void setUp() throws Exception { MockitoAnnotations.initMocks(this); this.documentAccessBridge = this.mocker.getInstance(DocumentAccessBridge.class); DocumentReference patientDocument = new DocumentReference("wiki", "patient", "00000001"); doReturn(patientDocument).when(this.patient).getDocument(); doReturn(this.doc).when(this.documentAccessBridge).getDocument(patientDocument); doReturn("first").when(this.firstOntologyVersion).getStringValue("name"); doReturn("1.0").when(this.firstOntologyVersion).getStringValue("version"); doReturn("second").when(this.secondOntologyVersion).getStringValue("name"); doReturn("2.0").when(this.secondOntologyVersion).getStringValue("version"); List<BaseObject> ontologyVersionList = Arrays.asList(firstOntologyVersion, secondOntologyVersion); doReturn(ontologyVersionList).when(this.doc).getXObjects(ONTOLOGY_VERSION_CLASS_REFERENCE); <START> PowerMockito.mockStatic(ComponentManagerRegistry.class); <END> PowerMockito.when(ComponentManagerRegistry.getContextComponentManager()) .thenReturn(this.contextComponentManager); doReturn(this.distributionManager).when(this.contextComponentManager).getInstance(DistributionManager.class); CoreExtension coreExtension = Mockito.mock(CoreExtension.class); doReturn(coreExtension).when(this.distributionManager).getDistributionExtension(); ExtensionId id = Mockito.mock(ExtensionId.class); doReturn(id).when(coreExtension).getId(); Version version = Mockito.mock(Version.class); doReturn(version).when(id).getVersion(); when(version.toString()).thenReturn(PHENOTIPS_VERSION_STRING); }</code><technical_language>This is [usually done](<LINK_0> PowerMockito</technical_language>

Target:
public void setUp() throws Exception { MockitoAnnotations.initMocks(this); this.documentAccessBridge = this.mocker.getInstance(DocumentAccessBridge.class); DocumentReference patientDocument = new DocumentReference("wiki", "patient", "00000001"); doReturn(patientDocument).when(this.patient).getDocument(); doReturn(this.doc).when(this.documentAccessBridge).getDocument(patientDocument); doReturn("first").when(this.firstOntologyVersion).getStringValue("name"); doReturn("1.0").when(this.firstOntologyVersion).getStringValue("version"); doReturn("second").when(this.secondOntologyVersion).getStringValue("name"); doReturn("2.0").when(this.secondOntologyVersion).getStringValue("version"); List<BaseObject> ontologyVersionList = Arrays.asList(firstOntologyVersion, secondOntologyVersion); doReturn(ontologyVersionList).when(this.doc).getXObjects(ONTOLOGY_VERSION_CLASS_REFERENCE); ReflectionUtils.setFieldValue(new ComponentManagerRegistry(), "cmProvider", this.cmProvider); doReturn(this.contextComponentManager).when(this.cmProvider).get(); doReturn(this.distributionManager).when(this.contextComponentManager).getInstance(DistributionManager.class); CoreExtension coreExtension = Mockito.mock(CoreExtension.class); doReturn(coreExtension).when(this.distributionManager).getDistributionExtension(); ExtensionId id = Mockito.mock(ExtensionId.class); doReturn(id).when(coreExtension).getId(); Version version = Mockito.mock(Version.class); doReturn(version).when(id).getVersion(); when(version.toString()).thenReturn(PHENOTIPS_VERSION_STRING); }