@Test
public void testClearOutputLoggerFileAtEndOfScript() throws Exception {

    final String logFilename = "logFilename-" + getName();
    final File outputLog = new File(TestUtil.getTargetDir(), logFilename);
    assertFalse(outputLog.exists());
    final MockCommandline mockCommandline = new MockCommandline();
    mockCommandline.setAssertCorrectCommandline(false);
    mockCommandline.setProcessInputStream(
            // need to provide some output to ensure StreamPumper threads have some work to do
            new ByteArrayInputStream("some stuff\nmore stuff\n".getBytes()));
    mockCommandline.setProcessErrorStream(new ByteArrayInputStream("".getBytes()));
    final Script dummyScript = new Script() {
        public Commandline buildCommandline() throws CruiseControlException {
            return mockCommandline;
        }
        public void setExitCode(int result) {
        }
        public int getExitCode() {
            return 0;
        }
    };
    final ScriptRunner sr = new ScriptRunner();
    final TestBuilder builder = new TestBuilder();
    final String projectName = "testProjectName";
    final BuildOutputLogger buildOutputLogger = builder.getBuildOutputConsumer(projectName,
            outputLog.getParentFile(), outputLog.getName());
    final String origId = buildOutputLogger.getID();
    sr.runScript(TestUtil.getTargetDir(), dummyScript, ScriptRunner.NO_TIMEOUT, buildOutputLogger);
    assertFalse("LiveOutput log should be cleared at end of script run: " + outputLog.getAbsolutePath(),
            outputLog.exists());
    final String currentId = buildOutputLogger.getID();
    assertTrue("buildOutputLogger id should change due to clear() at end of script run. origId: " + origId
            + "; current Id: " + currentId,
            currentId.startsWith(origId) && (currentId.length() > origId.length()));
}