Skip to content
This repository was archived by the owner on Jun 3, 2025. It is now read-only.

Commit 69154a0

Browse files
author
Aleksi Salmela
committed
Remove some unused code.
1 parent 16764c8 commit 69154a0

2 files changed

Lines changed: 15 additions & 72 deletions

File tree

src/main/java/fi/helsinki/cs/tmc/cli/core/CommandFactory.java

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -42,25 +42,6 @@ public static void addCommand(String name, String packageName, Class commandClas
4242
list.add(klass);
4343
}
4444

45-
/**
46-
* Merge this method implementation with the above version.
47-
*
48-
* @param packageName The package/category of the command
49-
* @param commandClass The class of the command
50-
*/
51-
protected static void addCommand(String packageName, Class commandClass) {
52-
Class<Command> klass = castToCommandClass(commandClass);
53-
Annotation annotation = klass.getAnnotation(Command.class);
54-
if (annotation == null) {
55-
throw new RuntimeException("Command must have Command annotation");
56-
}
57-
Command command = (Command) annotation;
58-
if (!AbstractCommand.class.isAssignableFrom(commandClass)) {
59-
throw new RuntimeException("Command must implement CommandInterface");
60-
}
61-
CommandFactory.addCommand(command.name(), packageName, commandClass);
62-
}
63-
6445
/**
6546
* Create new instance of the command.
6647
*

src/test/java/fi/helsinki/cs/tmc/cli/core/CommandFactoryTest.java

Lines changed: 15 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -29,27 +29,6 @@ public class CommandFactoryTest {
2929

3030
private CliContext ctx;
3131

32-
@Before
33-
public void setUp() {
34-
ctx = new CliContext(new TestIo());
35-
CommandFactory.reload();
36-
}
37-
38-
@Test
39-
public void constructorAddsCommands() {
40-
assertTrue(!CommandFactory.getCommands().isEmpty());
41-
}
42-
43-
@Test
44-
public void createHelpCommand() {
45-
assertNotNull(CommandFactory.createCommand("help"));
46-
}
47-
48-
@Test
49-
public void createNonexistingCommand() {
50-
assertNull(CommandFactory.createCommand("foobar"));
51-
}
52-
5332
@Command(name = "good", desc = "test")
5433
public static class GoodCommand extends AbstractCommand {
5534

@@ -64,42 +43,25 @@ public void run(CliContext context, CommandLine args) {
6443
}
6544
}
6645

67-
@Test
68-
public void addGoodCommand() {
69-
CommandFactory.addCommand("category", GoodCommand.class);
70-
//TODO check the all the stuff in the command
71-
assertNotNull(CommandFactory.createCommand("good"));
46+
@Before
47+
public void setUp() {
48+
ctx = new CliContext(new TestIo());
49+
CommandFactory.reload();
7250
}
7351

74-
public static class BadCommand extends AbstractCommand {
75-
76-
@Override
77-
public void getOptions(Options options) {
78-
throw new UnsupportedOperationException();
79-
}
80-
81-
@Override
82-
public void run(CliContext context, CommandLine args) {
83-
throw new UnsupportedOperationException();
84-
}
52+
@Test
53+
public void constructorAddsCommands() {
54+
assertTrue(!CommandFactory.getCommands().isEmpty());
8555
}
8656

87-
@Test(expected = RuntimeException.class)
88-
public void addCommandWithoutProperAnnotation() {
89-
//WARNING The exception code leads to unpredicatble test results
90-
//exception.expect(RuntimeException.class);
91-
//exception.expectMessage(contains("annotation"));
92-
CommandFactory.addCommand("category", BadCommand.class);
57+
@Test
58+
public void createHelpCommand() {
59+
assertNotNull(CommandFactory.createCommand("help"));
9360
}
9461

95-
private static class ReallyBadCommand {}
96-
97-
@Test(expected = RuntimeException.class)
98-
public void addCommandThatDoesntExtendInterface() {
99-
//WARNING The exception code leads to unpredicatble test results
100-
//exception.expect(RuntimeException.class);
101-
//exception.expectMessage(contains("Interface"));
102-
CommandFactory.addCommand("category", ReallyBadCommand.class);
62+
@Test
63+
public void createNonexistingCommand() {
64+
assertNull(CommandFactory.createCommand("foobar"));
10365
}
10466

10567
@Test
@@ -112,7 +74,7 @@ public void getCommandsGivesDefaultCommands() {
11274
@Test
11375
public void getCommandsWhenSingleCommandIsAdded() {
11476
int oldSize = CommandFactory.getCommands().size();
115-
CommandFactory.addCommand("", GoodCommand.class);
77+
CommandFactory.addCommand("good", "", GoodCommand.class);
11678
assertEquals(oldSize + 1, CommandFactory.getCommands().size());
11779
assertTrue(CommandFactory.getCommands().contains(
11880
CommandFactory.castToCommandClass(GoodCommand.class)));
@@ -126,7 +88,7 @@ public void getCategoryCommandsWhenItsEmpty() {
12688
@Test
12789
public void getCategoryCommandsWhenSingleCategorizedCommandIsAdded() {
12890
int oldSize = CommandFactory.getCommands().size();
129-
CommandFactory.addCommand("xyz", GoodCommand.class);
91+
CommandFactory.addCommand("good", "xyz", GoodCommand.class);
13092
List<Class<Command>> list = CommandFactory.getCategoryCommands("xyz");
13193
assertEquals(1, list.size());
13294
assertEquals(GoodCommand.class, list.get(0));

0 commit comments

Comments
 (0)