@Test @DisplayName("Methods should not be called more than once") void pipelineTest() { final QueryRunner queryRunner = mock(QueryRunner.class); final String sql = "Select * From any;"; final ConnectionData connectionData = new ConnectionData("", "", "", ""); final Result result = mock(Result.class); when(queryRunner.runQuery(sql, connectionData)).thenReturn(result); final Generator generator = mock(Generator.class); final VendorOptions vendorOptions = new PostgreSQLOptions(); final List<Output> outputs = Arrays.asList(new Output("1", "one"), new Output("2", "two")); when(generator.generate(result, vendorOptions)).thenReturn(outputs); final OutputConsumer outputConsumer = mock(OutputConsumer.class); Pipeline p = Pipeline.builder() .queryRunner(queryRunner) .connectionData(connectionData) .sqlQuery(sql) .resultProcessor(new Pipeline.ResultProcessor(generator, vendorOptions, outputConsumer)) .build(); p.execute(); verify(queryRunner, times(1)).runQuery(sql, connectionData); verify(generator, times(1)).generate(result, vendorOptions); verify(outputConsumer, times(1)).consumeOutput(outputs); }
public void execute() { Result queryRunnerResult = queryRunner.runQuery(sqlQuery, connectionData); Map<Generator, List<Output>> outputCache = new HashMap<>(); for (ResultProcessor rp : resultProcessors) { List<Output> generatedOutputs; if (outputCache.containsKey(rp.getGenerator())) { generatedOutputs = outputCache.get(rp.getGenerator()); } else { generatedOutputs = rp.getGenerator() .generate(queryRunnerResult, rp.getVendorOptions()); outputCache.put(rp.getGenerator(), generatedOutputs); } rp.getOutputConsumer().consumeOutput(generatedOutputs); } }
Pipeline { public void execute() { Result queryRunnerResult = queryRunner.runQuery(sqlQuery, connectionData); Map<Generator, List<Output>> outputCache = new HashMap<>(); for (ResultProcessor rp : resultProcessors) { List<Output> generatedOutputs; if (outputCache.containsKey(rp.getGenerator())) { generatedOutputs = outputCache.get(rp.getGenerator()); } else { generatedOutputs = rp.getGenerator() .generate(queryRunnerResult, rp.getVendorOptions()); outputCache.put(rp.getGenerator(), generatedOutputs); } rp.getOutputConsumer().consumeOutput(generatedOutputs); } } }
Pipeline { public void execute() { Result queryRunnerResult = queryRunner.runQuery(sqlQuery, connectionData); Map<Generator, List<Output>> outputCache = new HashMap<>(); for (ResultProcessor rp : resultProcessors) { List<Output> generatedOutputs; if (outputCache.containsKey(rp.getGenerator())) { generatedOutputs = outputCache.get(rp.getGenerator()); } else { generatedOutputs = rp.getGenerator() .generate(queryRunnerResult, rp.getVendorOptions()); outputCache.put(rp.getGenerator(), generatedOutputs); } rp.getOutputConsumer().consumeOutput(generatedOutputs); } }  }
Pipeline { public void execute() { Result queryRunnerResult = queryRunner.runQuery(sqlQuery, connectionData); Map<Generator, List<Output>> outputCache = new HashMap<>(); for (ResultProcessor rp : resultProcessors) { List<Output> generatedOutputs; if (outputCache.containsKey(rp.getGenerator())) { generatedOutputs = outputCache.get(rp.getGenerator()); } else { generatedOutputs = rp.getGenerator() .generate(queryRunnerResult, rp.getVendorOptions()); outputCache.put(rp.getGenerator(), generatedOutputs); } rp.getOutputConsumer().consumeOutput(generatedOutputs); } }  void execute(); }
Pipeline { public void execute() { Result queryRunnerResult = queryRunner.runQuery(sqlQuery, connectionData); Map<Generator, List<Output>> outputCache = new HashMap<>(); for (ResultProcessor rp : resultProcessors) { List<Output> generatedOutputs; if (outputCache.containsKey(rp.getGenerator())) { generatedOutputs = outputCache.get(rp.getGenerator()); } else { generatedOutputs = rp.getGenerator() .generate(queryRunnerResult, rp.getVendorOptions()); outputCache.put(rp.getGenerator(), generatedOutputs); } rp.getOutputConsumer().consumeOutput(generatedOutputs); } }  void execute();  }