DeregisterDriverFunction extends CliFunction<Object[]> { @Override public CliFunctionResult executeFunction(FunctionContext<Object[]> context) { try { String driverClassName = (String) context.getArguments()[0]; DriverJarUtil util = getDriverJarUtil(); util.deregisterDriver(driverClassName); return new CliFunctionResult(context.getMemberName(), CliFunctionResult.StatusState.OK, driverClassName + " was successfully deregistered."); } catch (Exception ex) { return new CliFunctionResult(context.getMemberName(), CliFunctionResult.StatusState.ERROR, ex.getMessage()); } } DeregisterDriverFunction(); @Override CliFunctionResult executeFunction(FunctionContext<Object[]> context);  }
@Test public void testExecuteFunctionDoesNotReturnError() { CliFunctionResult functionResult = function.executeFunction(context); assertThat(functionResult.getStatusMessage()) .contains(DRIVER_CLASS_NAME + " was successfully deregistered."); assertThat(functionResult.getStatus()).contains(CliFunctionResult.StatusState.OK.toString()); }
@Test public void testExecuteFunctionReturnsWithException() throws SQLException { String exceptionString = "Test SQL Exception"; doThrow(new SQLException(exceptionString)).when(util).deregisterDriver(DRIVER_CLASS_NAME); CliFunctionResult functionResult = function.executeFunction(context); assertThat(functionResult.getStatusMessage()).contains(exceptionString); assertThat(functionResult.getStatus()).contains(CliFunctionResult.StatusState.ERROR.toString()); }