@Test public void testGetConnectionById() throws Exception { doNothing().when(connectionServiceImpl).ensureDataAccessPermission(); doReturn(mockDBConnection) .when(connectionServiceImpl.datasourceMgmtSvc) .getDatasourceById(CONN_ID); IDatabaseConnection connection = connectionServiceImpl.getConnectionById(CONN_ID); verify(connectionServiceImpl).getConnectionById(CONN_ID); assertEquals(mockDBConnection, connection); }
@Test public void testGetConnectionByIdError_NullDatasource() throws Exception { doNothing().when(connectionServiceImpl).ensureDataAccessPermission(); doReturn(null).when(connectionServiceImpl.datasourceMgmtSvc).getDatasourceById(CONN_ID); try { connectionServiceImpl.getConnectionById(CONN_ID); fail(); // This line should never be reached } catch (ConnectionServiceException e) { // Expected exception } }