BaseCommands implements CommandMarker { protected <T extends Request<?>> void validateExecuteShowResult( T request, String[] columns, Function<T, List<String[]>> task ) { try { List<String[]> data = task.apply(request); if (data.isEmpty() && filterProcessor.hasAppliedFilters(request)) { ok("Nothing selected. However the following filters are set:"); listFilters(); ok("Would you like to search again without filters? Press y to proceed, n or q to abort operation."); Optional<Boolean> confirmationResult = routeByKey(new LinkedHashMap<Predicate<String>, Function<String, Boolean>>() { { put(TextUtils::isYesKey, k -> true); put(k -> isNoKey(k) || isExitKey(k), k -> false); } }); if (confirmationResult.isPresent() && confirmationResult.get()) { ok("Processing..."); T newRequest = filterProcessor.unsetFilters(request); validateExecuteShowResult(newRequest, columns, task); return; } } tableOrNothing(columns, data); } catch (InvalidRequestException e) { error(joinLines(e.getErrors())); } }    }
@Test public void testValidateExecuteShowResult() { List<String> results = new ArrayList<>(); Request<String> request = () -> "test"; mockBaseCommands.validateExecuteShowResult(request, r -> results.add(r.getPayload())); assertThat(results, contains("test")); mockBaseCommands.validateExecuteShowResult(request, r -> { throw new InvalidRequestException(new HashSet<>(Arrays.asList("one", "two"))); }); assertThat(logger.getErrorMessages(), contains("one\ntwo")); }