  |
17 | 17 | | |
| |
18 | 18 | | import junit.framework.TestCase; |
| |
19 | 19 | | |
  |
| 20 | + | import org.laughingpanda.halo.commands.Command; |
|
20 | 21 | | import org.laughingpanda.halo.commands.eclipse.GenerateEclipseDotClasspathFileCommand; |
| |
21 | 22 | | import org.laughingpanda.halo.commands.project.CleanCommand; |
| |
22 | 23 | | import org.laughingpanda.halo.commands.project.DefaultBuildCommand; |
| |
|
|
 |
… |
|
27 | 28 | | */ |
| |
28 | 29 | | public class ArgsTest extends TestCase { |
| |
29 | 30 | | public void testShouldGiveSelfBuildCommandForEmptyArgumentList() { |
  |
30 | | - | assertTrue(new Args(new ProjectProperties()).getCommand() instanceof DefaultBuildCommand); |
| |
| 31 | + | assertParsedCommandType(DefaultBuildCommand.class); |
|
31 | 32 | | } |
  |
32 | | - | |
| |
| 33 | + | |
|
33 | 34 | | public void testShouldGiveEclipseCommandWhenArgumentIsEclipse() { |
  |
34 | | - | assertTrue(new Args(new ProjectProperties(), "eclipse").getCommand() instanceof GenerateEclipseDotClasspathFileCommand); |
| |
| 35 | + | assertParsedCommandType(GenerateEclipseDotClasspathFileCommand.class, "eclipse"); |
|
35 | 36 | | } |
  |
36 | | - | |
| |
| 37 | + | |
|
37 | 38 | | public void testShouldGiveCleanCommandWhenArgumentIsClean() { |
  |
38 | | - | assertTrue(new Args(new ProjectProperties(), "clean").getCommand() instanceof CleanCommand); |
| |
| 39 | + | assertParsedCommandType(CleanCommand.class, "clean"); |
|
39 | 40 | | } |
  |
40 | | - | |
| |
| 41 | + | |
| |
| 42 | + | private void assertParsedCommandType(Class<?> expectedCommandType, String... args) { |
| |
| 43 | + | Command command = new Args(new ProjectProperties(), args).getCommand(); |
| |
| 44 | + | assertTrue(command.getClass().equals(expectedCommandType)); |
| |
| 45 | + | } |
| |
| 46 | + | |
  |
41 | 47 | | public void testShouldThrowExceptionIfArgumentIsNotRecognized() { |
| |
42 | 48 | | try { |
| |
43 | 49 | | new Args(new ProjectProperties(), "unknown").getCommand(); |