-
Notifications
You must be signed in to change notification settings - Fork 418
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added test Issue1528#testSubCommandAliasModification
- Loading branch information
Showing
1 changed file
with
54 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |