@Test
public void testBuildHistoryCommand() throws CruiseControlException {

    svn.setLocalWorkingCopy(".");
    Date checkTime = new Date();
    long tenMinutes = 10 * 60 * 1000;
    Date lastBuild = new Date(checkTime.getTime() - tenMinutes);
    String[] expectedCmd = new String[] { "svn", "log", "--non-interactive", "--xml", "-v", "-r",
            SVN.formatSVNDate(lastBuild, false) + ":" + SVN.formatSVNDate(checkTime, false) };
    String[] actualCmd = svn.buildHistoryCommand(SVN.formatSVNDate(lastBuild, false),
            SVN.formatSVNDate(checkTime, false)).getCommandline();
    assertThat(actualCmd, equalTo(expectedCmd));
    expectedCmd = new String[] { "svn", "log", "--non-interactive", "--xml", "-v", "-r",
            SVN.formatSVNDate(lastBuild, false) + ":" + SVN.formatSVNDate(checkTime, false), "external/path" };
    actualCmd = svn.buildHistoryCommand(SVN.formatSVNDate(lastBuild, false), SVN.formatSVNDate(checkTime, false),
            "external/path").getCommandline();
    assertThat(actualCmd, equalTo(expectedCmd));
    svn.setRepositoryLocation("http://svn.collab.net/repos/svn");
    expectedCmd = new String[] { "svn", "log", "--non-interactive", "--xml", "-v", "-r",
            SVN.formatSVNDate(lastBuild, false) + ":" + SVN.formatSVNDate(checkTime, false),
            "http://svn.collab.net/repos/svn" };
    actualCmd = svn.buildHistoryCommand(SVN.formatSVNDate(lastBuild, false), SVN.formatSVNDate(checkTime, false))
            .getCommandline();
    assertThat(actualCmd, equalTo(expectedCmd));
    expectedCmd = new String[] { "svn", "log", "--non-interactive", "--xml", "-v", "-r",
            SVN.formatSVNDate(lastBuild, false) + ":" + SVN.formatSVNDate(checkTime, false),
            "http://svn.collab.net/repos/external" };
    actualCmd = svn.buildHistoryCommand(SVN.formatSVNDate(lastBuild, false), SVN.formatSVNDate(checkTime, false),
            "http://svn.collab.net/repos/external").getCommandline();
    assertThat(actualCmd, equalTo(expectedCmd));
    svn.setUsername("lee");
    svn.setPassword("secret");
    expectedCmd = new String[] { "svn", "log", "--non-interactive", "--xml", "-v", "-r",
            SVN.formatSVNDate(lastBuild, false) + ":" + SVN.formatSVNDate(checkTime, false), "--no-auth-cache",
            "--username", "lee", "--password", "secret", "http://svn.collab.net/repos/svn" };
    actualCmd = svn.buildHistoryCommand(SVN.formatSVNDate(lastBuild, false), SVN.formatSVNDate(checkTime, false))
            .getCommandline();
    assertThat(actualCmd, equalTo(expectedCmd));
    svn.setUsername(null);
    svn.setPassword(null);
    final String testConfDir = "myConfigDir";
    svn.setConfigDir(testConfDir);
    expectedCmd = new String[] { "svn", "log", "--non-interactive", "--xml", "-v", "-r",
            SVN.formatSVNDate(lastBuild, false) + ":" + SVN.formatSVNDate(checkTime, false), "--config-dir",
            testConfDir, "http://svn.collab.net/repos/svn" };
    actualCmd = svn.buildHistoryCommand(SVN.formatSVNDate(lastBuild, false), SVN.formatSVNDate(checkTime, false))
            .getCommandline();
    assertThat(actualCmd, equalTo(expectedCmd));
}