Skip to content

Commit

Permalink
Added test Issue1528#testSubCommandAliasModification
Browse files Browse the repository at this point in the history
  • Loading branch information
rgoldberg committed Feb 7, 2022
1 parent 0f0d72c commit 85a3af2
Showing 1 changed file with 54 additions and 0 deletions.
54 changes: 54 additions & 0 deletions src/test/java/picocli/Issue1528.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package picocli;

import java.util.concurrent.Callable;
import org.junit.Test;
import picocli.CommandLine.Command;
import picocli.CommandLine.Model.CommandSpec;

import static org.junit.Assert.assertEquals;

public class Issue1528 {

@Command(name = "main", subcommands = SubCommand.class)
static class MainCommand implements Callable<Integer> {
@Override
public Integer call() throws Exception {
return null;
}
}

@Command(name = "sub")
static class SubCommand implements Callable<Integer> {
@Override
public Integer call() throws Exception {
return null;
}
}

@Test
public void testSubCommandAliasModification() {
CommandSpec cs = new CommandLine(new MainCommand()).getSubcommands().get("sub").getCommandSpec();

assertEquals(0, cs.aliases().length);

cs.aliases("alias");
assertEquals(1, cs.aliases().length);
assertEquals("alias", cs.aliases()[0]);

cs.aliases("alias", "2");
assertEquals(2, cs.aliases().length);
assertEquals("alias", cs.aliases()[0]);
assertEquals("2", cs.aliases()[1]);

cs.aliases("2");
assertEquals(1, cs.aliases().length);
assertEquals("2", cs.aliases()[0]);

cs.aliases("3");
assertEquals(1, cs.aliases().length);
assertEquals("3", cs.aliases()[0]);

cs.aliases(new String[0]);
assertEquals(0, cs.aliases().length);
}
}

0 comments on commit 85a3af2

Please sign in to comment.