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

Commit 16764c8

Browse files
author
Aleksi Salmela
committed
Add more unit tests for CommandFactory.
1 parent a26e7dc commit 16764c8

1 file changed

Lines changed: 57 additions & 0 deletions

File tree

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

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@
1818
import org.junit.Test;
1919
import org.junit.rules.ExpectedException;
2020

21+
import java.util.List;
22+
import java.util.Set;
23+
2124
public class CommandFactoryTest {
2225

2326
Application app;
@@ -98,4 +101,58 @@ public void addCommandThatDoesntExtendInterface() {
98101
//exception.expectMessage(contains("Interface"));
99102
CommandFactory.addCommand("category", ReallyBadCommand.class);
100103
}
104+
105+
@Test
106+
public void getCommandsGivesDefaultCommands() {
107+
assertNotSame(0, CommandFactory.getCommands().size());
108+
assertTrue(CommandFactory.getCommands().contains(
109+
CommandFactory.castToCommandClass(HelpCommand.class)));
110+
}
111+
112+
@Test
113+
public void getCommandsWhenSingleCommandIsAdded() {
114+
int oldSize = CommandFactory.getCommands().size();
115+
CommandFactory.addCommand("", GoodCommand.class);
116+
assertEquals(oldSize + 1, CommandFactory.getCommands().size());
117+
assertTrue(CommandFactory.getCommands().contains(
118+
CommandFactory.castToCommandClass(GoodCommand.class)));
119+
}
120+
121+
@Test
122+
public void getCategoryCommandsWhenItsEmpty() {
123+
assertEquals(null, CommandFactory.getCategoryCommands("xyz"));
124+
}
125+
126+
@Test
127+
public void getCategoryCommandsWhenSingleCategorizedCommandIsAdded() {
128+
int oldSize = CommandFactory.getCommands().size();
129+
CommandFactory.addCommand("xyz", GoodCommand.class);
130+
List<Class<Command>> list = CommandFactory.getCategoryCommands("xyz");
131+
assertEquals(1, list.size());
132+
assertEquals(GoodCommand.class, list.get(0));
133+
}
134+
135+
@Test
136+
public void getCommandCategoriesIsNotEmpty() {
137+
Set<String> list = CommandFactory.getCommandCategories();
138+
assertNotSame(0, list.size());
139+
}
140+
141+
@Test
142+
public void getCommandCategoriesContainsDefaultCategory() {
143+
Set<String> list = CommandFactory.getCommandCategories();
144+
assertTrue(list.contains(""));
145+
}
146+
147+
@Test
148+
public void getCommandCategoriesContainsHiddenCategory() {
149+
Set<String> list = CommandFactory.getCommandCategories();
150+
assertTrue(list.contains("hidden"));
151+
}
152+
153+
@Test
154+
public void getCommandCategoriesContainsAdminCategory() {
155+
Set<String> list = CommandFactory.getCommandCategories();
156+
assertTrue(list.contains("admin"));
157+
}
101158
}

0 commit comments

Comments
 (0)