|
18 | 18 | import org.junit.Test; |
19 | 19 | import org.junit.rules.ExpectedException; |
20 | 20 |
|
| 21 | +import java.util.List; |
| 22 | +import java.util.Set; |
| 23 | + |
21 | 24 | public class CommandFactoryTest { |
22 | 25 |
|
23 | 26 | Application app; |
@@ -98,4 +101,58 @@ public void addCommandThatDoesntExtendInterface() { |
98 | 101 | //exception.expectMessage(contains("Interface")); |
99 | 102 | CommandFactory.addCommand("category", ReallyBadCommand.class); |
100 | 103 | } |
| 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 | + } |
101 | 158 | } |
0 commit comments