ListDriversFunction extends CliFunction<Object[]> { @Override public CliFunctionResult executeFunction(FunctionContext<Object[]> context) { try { List<String> driverNames; driverNames = (getDriverJarUtil()).getRegisteredDriverNames(); return new CliFunctionResult(context.getMemberName(), driverNames, createMessageFromDriversList(driverNames)); } catch (Exception ex) { return new CliFunctionResult(context.getMemberName(), CliFunctionResult.StatusState.ERROR, ex.getMessage()); } } ListDriversFunction(); @Override CliFunctionResult executeFunction(FunctionContext<Object[]> context);  }
@Test public void testExecuteFunctionDoesNotReturnError() { when(util.getRegisteredDriverNames()).thenReturn(driverNames); CliFunctionResult functionResult = function.executeFunction(context); assertThat(functionResult.getResultObject().equals(driverNames)); assertThat(functionResult.getStatusMessage()) .isEqualTo("{Driver.Class.One, Driver.Class.Two, Driver.Class.Three}"); assertThat(functionResult.isSuccessful()).isTrue(); }
@Test public void testExecuteFunctionReturnsWithException() { String exceptionString = "Test null pointer exception"; doThrow(new NullPointerException(exceptionString)).when(util).getRegisteredDriverNames(); CliFunctionResult functionResult = function.executeFunction(context); assertThat(functionResult.getStatusMessage()).contains(exceptionString); assertThat(functionResult.getStatus()).contains(CliFunctionResult.StatusState.ERROR.toString()); }