コード例 #1
0
 @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);
 }
コード例 #2
0
 @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
   }
 }