mirror of
https://github.com/scm-manager/scm-manager.git
synced 2026-02-07 23:29:10 +01:00
Sort CLI commands alphabetically (#2020)
Sort CLI commands alphabetically to show them in consistent order.
This commit is contained in:
@@ -31,10 +31,8 @@ import org.mockito.InjectMocks;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.List;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.mockito.Mockito.when;
|
||||
@@ -52,7 +50,7 @@ class CommandRegistryTest {
|
||||
void shouldCreateTreeWithOnlyRootNodes() {
|
||||
mockCommands(rc(Object.class), rc(String.class), rc(Integer.class));
|
||||
|
||||
Set<RegisteredCommandNode> commandTree = registry.createCommandTree();
|
||||
List<RegisteredCommandNode> commandTree = registry.createCommandTree();
|
||||
assertContainsCommands(commandTree, Object.class, String.class, Integer.class);
|
||||
}
|
||||
|
||||
@@ -60,7 +58,7 @@ class CommandRegistryTest {
|
||||
void shouldCreateTreeWithParents() {
|
||||
mockCommands(rc(Object.class), rc(String.class, Object.class), rc(Integer.class, Object.class));
|
||||
|
||||
Set<RegisteredCommandNode> commandTree = registry.createCommandTree();
|
||||
List<RegisteredCommandNode> commandTree = registry.createCommandTree();
|
||||
|
||||
assertContainsCommands(commandTree, Object.class);
|
||||
assertContainsCommands(commandTree.iterator().next().getChildren(), Integer.class, String.class);
|
||||
@@ -70,7 +68,7 @@ class CommandRegistryTest {
|
||||
void shouldCreateTreeWithParentsSecondLevel() {
|
||||
mockCommands(rc(Object.class), rc(String.class, Object.class), rc(Integer.class, String.class));
|
||||
|
||||
Set<RegisteredCommandNode> commandTree = registry.createCommandTree();
|
||||
List<RegisteredCommandNode> commandTree = registry.createCommandTree();
|
||||
|
||||
assertContainsCommands(commandTree, Object.class);
|
||||
RegisteredCommandNode rootNode = commandTree.iterator().next();
|
||||
@@ -78,6 +76,18 @@ class CommandRegistryTest {
|
||||
assertContainsCommands(rootNode.getChildren().get(0).getChildren(), Integer.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldSortCommandsAlphabetically() {
|
||||
mockCommands(rc(Object.class), rc(String.class, Object.class), rc(Float.class, Object.class), rc(Integer.class, Object.class));
|
||||
|
||||
List<RegisteredCommandNode> commandTree = registry.createCommandTree();
|
||||
|
||||
List<RegisteredCommandNode> subCommands = commandTree.get(0).getChildren();
|
||||
assertThat(subCommands.get(0).getCommand()).isEqualTo(Float.class);
|
||||
assertThat(subCommands.get(1).getCommand()).isEqualTo(Integer.class);
|
||||
assertThat(subCommands.get(2).getCommand()).isEqualTo(String.class);
|
||||
}
|
||||
|
||||
private void mockCommands(RegisteredCommand... commands) {
|
||||
when(commandCollector.collect()).thenReturn(ImmutableSet.copyOf(commands));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user