package com.aragost.javahg.commands;
import java.io.IOException;
import junit.framework.Assert;
import org.junit.Test;
import com.aragost.javahg.HgVersion;
import com.aragost.javahg.Repository;
import com.aragost.javahg.UnknownCommandException;
import com.aragost.javahg.internals.AbstractCommand;
import com.aragost.javahg.test.AbstractTestCase;
public class AbstractCommandTest extends AbstractTestCase {
@Test
public void testGetErrorStringTwice() throws IOException {
Repository repo = getTestRepository();
LogCommand cmd = LogCommand.on(repo).branch("no such branch");
try {
cmd.execute();
assertFailedExecution(cmd);
} catch (ExecutionException e) {
String errorString1 = cmd.getErrorString();
String errorString2 = cmd.getErrorString();
Assert.assertEquals(errorString1, errorString2);
}
}
@Test
public void testUnknownCommand() {
Repository repo = getTestRepository();
HgVersion hgVersion = repo.getHgVersion();
DummyTestCommand cmd = new DummyTestCommand(repo);
try {
cmd.execute();
assertFailedExecution(cmd);
} catch (UnknownCommandException e) {
Assert.assertSame(cmd, e.getCommand());
Assert.assertTrue(e.getMessage().indexOf(hgVersion.getVersionString()) >= 0);
}
}
}
class DummyTestCommand extends AbstractCommand {
protected DummyTestCommand(Repository repository) {
super(repository);
}
public void execute() {
launchString();
}
@Override
public String getCommandName() {
return "unsupportedCommand";
}
}