@Test public void testUpdateConnection() throws Exception { doNothing().when(connectionServiceImpl).ensureDataAccessPermission(); doReturn("").when(connectionServiceImpl).getConnectionPassword(anyString(), anyString()); assertTrue(connectionServiceImpl.updateConnection(mockDBConnection)); verify(connectionServiceImpl).updateConnection(mockDBConnection); verify(datasourceService).clearDataSource(CONN_NAME); }
private void testUpdateConnectionError(Exception ex) throws Exception { doNothing().when(connectionServiceImpl).ensureDataAccessPermission(); doReturn("").when(connectionServiceImpl).getConnectionPassword(anyString(), anyString()); doThrow(ex) .when(connectionServiceImpl.datasourceMgmtSvc) .updateDatasourceByName(CONN_NAME, mockDBConnection); try { connectionServiceImpl.updateConnection(mockDBConnection); fail(); // This line should never be reached } catch (ConnectionServiceException e) { // Expected exception } verify(connectionServiceImpl).updateConnection(mockDBConnection); }