@Before public void setUp() throws Exception { generator = context.mock(Runnable.class); renderer = context.mock(ProjectReportRenderer.class); task = HelperUtil.createTask(TestReportTask.class, project); task.setGenerator(generator); task.setRenderer(renderer); }
@Test public void passesEachProjectToRenderer() throws IOException { final Project child1 = createChildProject(project, "child1"); final Project child2 = createChildProject(project, "child2"); context.checking( new Expectations() { { Sequence sequence = context.sequence("seq"); one(renderer).startProject(project); inSequence(sequence); one(generator).run(); inSequence(sequence); one(renderer).completeProject(project); inSequence(sequence); one(renderer).startProject(child1); inSequence(sequence); one(generator).run(); inSequence(sequence); one(renderer).completeProject(child1); inSequence(sequence); one(renderer).startProject(child2); inSequence(sequence); one(generator).run(); inSequence(sequence); one(renderer).completeProject(child2); inSequence(sequence); one(renderer).complete(); inSequence(sequence); } }); task.generate(); }
@Test public void createsMissingOutputDirectory() throws IOException { final File file = new File(getTestDir(), "missing/missing.txt"); assertFalse(file.getParentFile().isDirectory()); context.checking( new Expectations() { { one(renderer).setOutputFile(file); one(renderer).startProject(project); one(generator).run(); one(renderer).completeProject(project); one(renderer).complete(); } }); task.setOutputFile(file); task.generate(); assertTrue(file.getParentFile().isDirectory()); }
@Test public void setsOutputFileNameOnRendererBeforeGeneration() throws IOException { final File file = new File(getTestDir(), "report.txt"); context.checking( new Expectations() { { Sequence sequence = context.sequence("sequence"); one(renderer).setOutputFile(file); inSequence(sequence); one(renderer).startProject(project); inSequence(sequence); one(generator).run(); inSequence(sequence); one(renderer).completeProject(project); inSequence(sequence); one(renderer).complete(); inSequence(sequence); } }); task.setOutputFile(file); task.generate(); }
@Test public void completesRendererAtEndOfGeneration() throws IOException { context.checking( new Expectations() { { Sequence sequence = context.sequence("sequence"); one(renderer).startProject(project); inSequence(sequence); one(generator).run(); inSequence(sequence); one(renderer).completeProject(project); inSequence(sequence); one(renderer).complete(); inSequence(sequence); } }); task.generate(); }