### Question:
WildflyDataSourceProvider implements DataSourceProvider { @Override public void hasStarted() throws Exception { dataSourceMgmtClient.testConnection(); dataSourceMgmtClient.getDataSources(); } WildflyDataSourceProvider(); @Inject  WildflyDataSourceProvider(WildflyDriverProvider driverProvider); @Override List< DataSourceDef > getDeployments(); @Override DataSourceDeploymentInfo deploy(DataSourceDef dataSourceDef); DataSourceDeploymentInfo resync(DataSourceDef dataSourceDef,
                                           DataSourceDeploymentInfo deploymentInfo); @Override void undeploy(final DataSourceDeploymentInfo deploymentInfo); DataSourceDeploymentInfo getDeploymentInfo(final String uuid); List< DataSourceDeploymentInfo > getDeploymentsInfo(); @Override DataSource lookupDataSource(DataSourceDeploymentInfo deploymentInfo); @Override void loadConfig(Properties properties); @Override void hasStarted(); void setDataSourceMgmtClient(WildflyDataSourceManagementClient dataSourceMgmtClient);  }### Answer:
@Test public void testHasStartedOk() throws Exception { when(managementClient.testConnection()).thenReturn(METHOD_EXECUTION_OK); when(managementClient.getDataSources()).thenReturn(Collections.EMPTY_LIST); dataSourceProvider.hasStarted(); verify(managementClient, times(1)).testConnection(); verify(managementClient, times(1)).getDataSources(); }
@Test public void testHasStartedWithError1() throws Exception { when(managementClient.testConnection()).thenThrow(new Exception(METHOD_EXECUTION_FAILED)); when(managementClient.getDataSources()).thenReturn(Collections.EMPTY_LIST); expectedException.expectMessage(METHOD_EXECUTION_FAILED); dataSourceProvider.hasStarted(); verify(managementClient, times(1)).testConnection(); verify(managementClient, never()).getDataSources(); }
@Test public void testHasStartedWithError2() throws Exception { when(managementClient.testConnection()).thenReturn(METHOD_EXECUTION_OK); when(managementClient.getDataSources()).thenThrow(new Exception(METHOD_EXECUTION_FAILED)); expectedException.expectMessage(METHOD_EXECUTION_FAILED); dataSourceProvider.hasStarted(); verify(managementClient, times(1)).testConnection(); verify(managementClient, times(1)).getDataSources(); }