forked from airlift/airline
-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
First unit tests for positional args (#91)
- Loading branch information
Showing
5 changed files
with
139 additions
and
10 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
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
40 changes: 40 additions & 0 deletions
40
airline-core/src/test/java/com/github/rvesse/airline/TestPositionalArgs.java
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,40 @@ | ||
package com.github.rvesse.airline; | ||
|
||
import com.github.rvesse.airline.args.ArgsPositional; | ||
import com.github.rvesse.airline.args.ArgsPositionalGap; | ||
import com.github.rvesse.airline.model.PositionalArgumentMetadata; | ||
import com.github.rvesse.airline.parser.command.SingleCommandParser; | ||
|
||
import static com.github.rvesse.airline.TestingUtil.singleCommandParser; | ||
import static org.testng.Assert.assertEquals; | ||
import static org.testng.Assert.assertFalse; | ||
import static org.testng.Assert.assertTrue; | ||
|
||
import org.testng.Assert; | ||
import org.testng.annotations.Test; | ||
|
||
public class TestPositionalArgs { | ||
|
||
@Test | ||
public void positional_args_01() { | ||
SingleCommand<ArgsPositional> parser = singleCommandParser(ArgsPositional.class); | ||
assertFalse(parser.getCommandMetadata().getPositionalArguments().isEmpty()); | ||
assertEquals(parser.getCommandMetadata().getPositionalArguments().size(), 2); | ||
|
||
PositionalArgumentMetadata posArg = parser.getCommandMetadata().getPositionalArguments().get(0); | ||
assertEquals(posArg.getZeroBasedPosition(), 0); | ||
assertEquals(posArg.getOneBasedPosition(), 1); | ||
assertEquals(posArg.getJavaType(), String.class); | ||
|
||
posArg = parser.getCommandMetadata().getPositionalArguments().get(1); | ||
assertEquals(posArg.getZeroBasedPosition(), 1); | ||
assertEquals(posArg.getOneBasedPosition(), 2); | ||
assertEquals(posArg.getJavaType(), Integer.class); | ||
|
||
} | ||
|
||
@Test(expectedExceptions = IllegalStateException.class) | ||
public void positional_args_gap_01() { | ||
singleCommandParser(ArgsPositionalGap.class); | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
airline-core/src/test/java/com/github/rvesse/airline/args/ArgsPositional.java
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,38 @@ | ||
/** | ||
* Copyright (C) 2010-16 the original author or authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package com.github.rvesse.airline.args; | ||
|
||
import com.github.rvesse.airline.annotations.Arguments; | ||
import com.github.rvesse.airline.annotations.Command; | ||
import com.github.rvesse.airline.annotations.PositionalArgument; | ||
import com.github.rvesse.airline.annotations.restrictions.Required; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
@Command(name = "ArgsPositional", description = "ArgsPositional description") | ||
public class ArgsPositional | ||
{ | ||
@PositionalArgument(position = PositionalArgument.FIRST, title = "File") | ||
@Required | ||
public String file; | ||
|
||
@PositionalArgument(position = PositionalArgument.SECOND, title = "Mode") | ||
public Integer mode; | ||
|
||
@Arguments | ||
public List<String> parameters = new ArrayList<>(); | ||
} |
38 changes: 38 additions & 0 deletions
38
airline-core/src/test/java/com/github/rvesse/airline/args/ArgsPositionalGap.java
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,38 @@ | ||
/** | ||
* Copyright (C) 2010-16 the original author or authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package com.github.rvesse.airline.args; | ||
|
||
import com.github.rvesse.airline.annotations.Arguments; | ||
import com.github.rvesse.airline.annotations.Command; | ||
import com.github.rvesse.airline.annotations.PositionalArgument; | ||
import com.github.rvesse.airline.annotations.restrictions.Required; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
@Command(name = "ArgsPositional", description = "ArgsPositional description") | ||
public class ArgsPositionalGap | ||
{ | ||
@PositionalArgument(position = PositionalArgument.FIRST, title = "File") | ||
@Required | ||
public String file; | ||
|
||
@PositionalArgument(position = PositionalArgument.THIRD, title = "Mode") | ||
public Integer mode; | ||
|
||
@Arguments | ||
public List<String> parameters = new ArrayList<>(); | ||
} |