diff options
author | Anton Gustafsson <antag99@gmail.com> | 2015-07-06 15:57:32 +0200 |
---|---|---|
committer | Anton Gustafsson <antag99@gmail.com> | 2015-07-06 15:57:32 +0200 |
commit | e76c3a2a21a0d6c1e53a07d038f277500c43bbc8 (patch) | |
tree | b1200832ba6e1171585b2bcf412df8fa52452059 /src | |
parent | f14b0e97176de13aec696bc1771b33292c5d53fe (diff) | |
download | jcommander-e76c3a2a21a0d6c1e53a07d038f277500c43bbc8.tar.gz |
Add unit tests for inaccessible fields/methods/constructors
Diffstat (limited to 'src')
4 files changed, 124 insertions, 0 deletions
diff --git a/src/test/java/com/beust/jcommander/HiddenConverter.java b/src/test/java/com/beust/jcommander/HiddenConverter.java new file mode 100644 index 0000000..cd36b85 --- /dev/null +++ b/src/test/java/com/beust/jcommander/HiddenConverter.java @@ -0,0 +1,29 @@ +/** + * Copyright (C) 2010 the original author or authors. + * See the notice.md file distributed with this work for additional + * information regarding copyright ownership. + * + * 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.beust.jcommander; + +public class HiddenConverter implements IStringConverter<String> { + private HiddenConverter() { + } + + @Override + public String convert(String value) { + return value; + } +} diff --git a/src/test/java/com/beust/jcommander/HiddenParameterSplitter.java b/src/test/java/com/beust/jcommander/HiddenParameterSplitter.java new file mode 100644 index 0000000..cf2f3ee --- /dev/null +++ b/src/test/java/com/beust/jcommander/HiddenParameterSplitter.java @@ -0,0 +1,34 @@ +/** + * Copyright (C) 2010 the original author or authors. + * See the notice.md file distributed with this work for additional + * information regarding copyright ownership. + * + * 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.beust.jcommander; + +import java.util.Arrays; +import java.util.List; + +import com.beust.jcommander.converters.IParameterSplitter; + +public class HiddenParameterSplitter implements IParameterSplitter { + private HiddenParameterSplitter() { + } + + @Override + public List<String> split(String value) { + return Arrays.asList(value.split(";")); + } +} diff --git a/src/test/java/com/beust/jcommander/JCommanderTest.java b/src/test/java/com/beust/jcommander/JCommanderTest.java index d0bc4b6..6be7e9d 100644 --- a/src/test/java/com/beust/jcommander/JCommanderTest.java +++ b/src/test/java/com/beust/jcommander/JCommanderTest.java @@ -68,6 +68,7 @@ import com.beust.jcommander.args.ArgsSlaveBogus; import com.beust.jcommander.args.ArgsValidate1; import com.beust.jcommander.args.ArgsWithSet; import com.beust.jcommander.args.Arity1; +import com.beust.jcommander.args.HiddenArgs; import com.beust.jcommander.args.SeparatorColon; import com.beust.jcommander.args.SeparatorEqual; import com.beust.jcommander.args.SeparatorMixed; @@ -312,6 +313,30 @@ public class JCommanderTest { Assert.assertEquals(args.listBigDecimals.get(1), new BigDecimal("100.12")); } + public void hiddenConverter() { + class Args { + @Parameter(names = "--path", converter = HiddenConverter.class) + public String path; + } + + new JCommander(new Args(), "--path", "/tmp/a"); + } + + public void hiddenArgs() { + new JCommander(new HiddenArgs(), "--input", "/tmp/a", "--output", "/tmp/b"); + } + + public void hiddenSplitter() { + class Args { + @Parameter(names = "--extensions", splitter = HiddenParameterSplitter.class) + public List<String> extensions; + } + + Args args = new Args(); + new JCommander(args, "--extensions", ".txt;.md"); + Assert.assertEquals(Arrays.asList(".txt", ".md"), args.extensions); + } + private void argsBoolean1(String[] params, Boolean expected) { ArgsBooleanArity args = new ArgsBooleanArity(); new JCommander(args, params); diff --git a/src/test/java/com/beust/jcommander/args/HiddenArgs.java b/src/test/java/com/beust/jcommander/args/HiddenArgs.java new file mode 100644 index 0000000..1b89334 --- /dev/null +++ b/src/test/java/com/beust/jcommander/args/HiddenArgs.java @@ -0,0 +1,36 @@ +/** + * Copyright (C) 2010 the original author or authors. + * See the notice.md file distributed with this work for additional + * information regarding copyright ownership. + * + * 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.beust.jcommander.args; + +import com.beust.jcommander.Parameter; + +public class HiddenArgs { + public HiddenArgs() { + } + + @Parameter(names = "--input") + private String input; + + private String output; + + @Parameter(names = "--output") + private void setOutput(String output) { + this.output = output; + } +} |