### Question:
FindCopybookCommand implements CodeActionProvider { @Nonnull @Override public List<Either<Command, CodeAction>> collectCommandsOrActions( @Nonnull CodeActionParams params) { return params.getContext().getDiagnostics().stream() .filter(it -> it.getCode() != null) .filter(it -> MISSING_COPYBOOK.equals(valueOf(it.getCode()))) .map(toCodeAction(params)) .map(Either::<Command, CodeAction>forRight) .collect(toList()); }  @Nonnull @Override List<Either<Command, CodeAction>> collectCommandsOrActions(
      @Nonnull CodeActionParams params);  }### Answer:
@Test void testCollectCommandsOrActionsPositive() { CodeActionProvider provider = new FindCopybookCommand(); List<Diagnostic> diagnostics = singletonList(COPYBOOK_ERROR); CodeActionParams params = new CodeActionParams( new TextDocumentIdentifier(DOCUMENT_URI), RANGE, new CodeActionContext(diagnostics)); List<Either<Command, CodeAction>> actions = provider.collectCommandsOrActions(params); assertEquals(1, actions.size()); CodeAction action = actions.get(0).getRight(); assertCorrectCodeAction(action); }
@Test void testCollectCommandsOrActionsNegative() { CodeActionProvider provider = new FindCopybookCommand(); List<Diagnostic> diagnostics = singletonList(SYNTAX_ERROR); CodeActionParams params = new CodeActionParams( new TextDocumentIdentifier(DOCUMENT_URI), RANGE, new CodeActionContext(diagnostics)); List<Either<Command, CodeAction>> actions = provider.collectCommandsOrActions(params); assertEquals(0, actions.size()); }
@Test void testCollectCommandsOrActionsMixed() { CodeActionProvider provider = new FindCopybookCommand(); List<Diagnostic> diagnostics = Lists.newArrayList(SYNTAX_ERROR, COPYBOOK_ERROR); CodeActionParams params = new CodeActionParams( new TextDocumentIdentifier(DOCUMENT_URI), RANGE, new CodeActionContext(diagnostics)); List<Either<Command, CodeAction>> actions = provider.collectCommandsOrActions(params); assertEquals(1, actions.size()); CodeAction action = actions.get(0).getRight(); assertCorrectCodeAction(action); }