1 package com.aragost.javahg.commands;
2
3 import java.io.IOException;
4
5 import junit.framework.Assert;
6
7 import org.junit.Test;
8
9 import com.aragost.javahg.HgVersion;
10 import com.aragost.javahg.Repository;
11 import com.aragost.javahg.UnknownCommandException;
12 import com.aragost.javahg.internals.AbstractCommand;
13 import com.aragost.javahg.test.AbstractTestCase;
14
15 public class AbstractCommandTest extends AbstractTestCase {
16
17 @Test
18 public void testGetErrorStringTwice() throws IOException {
19 Repository repo = getTestRepository();
20 LogCommand cmd = LogCommand.on(repo).branch("no such branch");
21 try {
22 cmd.execute();
23 assertFailedExecution(cmd);
24 } catch (ExecutionException e) {
25 String errorString1 = cmd.getErrorString();
26 String errorString2 = cmd.getErrorString();
27 Assert.assertEquals(errorString1, errorString2);
28 }
29 }
30
31 @Test
32 public void testUnknownCommand() {
33 Repository repo = getTestRepository();
34 HgVersion hgVersion = repo.getHgVersion();
35 DummyTestCommand cmd = new DummyTestCommand(repo);
36
37 try {
38 cmd.execute();
39 assertFailedExecution(cmd);
40 } catch (UnknownCommandException e) {
41 Assert.assertSame(cmd, e.getCommand());
42 Assert.assertTrue(e.getMessage().indexOf(hgVersion.getVersionString()) >= 0);
43 }
44
45 }
46
47 }
48
49 class DummyTestCommand extends AbstractCommand {
50
51 protected DummyTestCommand(Repository repository) {
52 super(repository);
53 }
54
55 public void execute() {
56 launchString();
57 }
58
59 @Override
60 public String getCommandName() {
61 return "unsupportedCommand";
62 }
63
64 }