### Question:
Engine implements ReactiveStreamsEngine { @Override public <T> CompletionStage<T> buildCompletion(Graph graph) { Multi<?> flowable = null; for (Stage stage : graph.getStages()) { Operator operator = Stages.lookup(stage); if (operator instanceof PublisherOperator) { flowable = createPublisher(stage, (PublisherOperator) operator); } else if (operator instanceof ProcessorOperator) { flowable = applyProcessors(flowable, stage, (ProcessorOperator) operator); } else { return applySubscriber(flowable, stage, (TerminalOperator) operator); } } throw new IllegalArgumentException("Graph did not have terminal stage"); }  @Override Publisher<T> buildPublisher(Graph graph); @Override SubscriberWithCompletionStage<T, R> buildSubscriber(Graph graph); @Override Processor<T, R> buildProcessor(Graph graph); @Override CompletionStage<T> buildCompletion(Graph graph);  }### Answer:
@Test public void testValidCompletion() { engine = new Engine(); List<Stage> stages = new ArrayList<>(); stages.add((Stage.PublisherStage) () -> Multi.createFrom().empty()); stages.add((Stage.Map) () -> i -> (int) i + 1); stages.add(new Stage.FindFirst() { }); Graph graph = () -> stages; assertThat(engine.buildCompletion(graph)).isNotNull(); }
@Test public void testInvalidCompletion() { assertThrows(IllegalArgumentException.class, () -> { engine = new Engine(); List<Stage> stages = new ArrayList<>(); stages.add((Stage.PublisherStage) () -> Multi.createFrom().empty()); stages.add((Stage.Map) () -> i -> (int) i + 1); Graph graph = () -> stages; engine.buildCompletion(graph); }); }
@Test public void testCompletionWithUnknownStage() { assertThrows(UnsupportedStageException.class, () -> { engine = new Engine(); List<Stage> stages = new ArrayList<>(); stages.add((Stage.PublisherStage) () -> Multi.createFrom().empty()); stages.add((Stage.Map) () -> i -> (int) i + 1); stages.add(new Stage() { }); stages.add(new Stage.FindFirst() { }); Graph graph = () -> stages; assertThat(engine.buildCompletion(graph)).isNotNull(); }); }