Mercurial > hg > release > icedtea-web-1.8
changeset 1280:09792ebffb27
Add tests for PolicyEditor.getFilePathArgument
* netx/net/sourceforge/jnlp/security/policyeditor/PolicyEditor.java
(getFilePathArgument): made package-private for testing
* tests/netx/unit/net/sourceforge/jnlp/security/policyeditor/PolicyEditorTest.java:
new tests for PolicyEditor.getFilePathArgument
author | Andrew Azores <aazores@redhat.com> |
---|---|
date | Thu, 30 Jul 2015 13:49:33 -0400 |
parents | bbab18a43972 |
children | bbd5fd366c96 |
files | ChangeLog netx/net/sourceforge/jnlp/security/policyeditor/PolicyEditor.java tests/netx/unit/net/sourceforge/jnlp/security/policyeditor/PolicyEditorTest.java |
diffstat | 3 files changed, 105 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- a/ChangeLog Thu Jul 30 18:51:00 2015 +0200 +++ b/ChangeLog Thu Jul 30 13:49:33 2015 -0400 @@ -1,3 +1,11 @@ +2015-07-30 Andrew Azores <aazores@redhat.com> + + Add tests for PolicyEditor.getFilePathArgument + * netx/net/sourceforge/jnlp/security/policyeditor/PolicyEditor.java + (getFilePathArgument): made package-private for testing + * tests/netx/unit/net/sourceforge/jnlp/security/policyeditor/PolicyEditorTest.java: + new tests for PolicyEditor.getFilePathArgument + 2015-07-30 Jiri Vanek <jvanek@redhat.com> Added more asserts to MixedSigningAndTrustedOnly tests
--- a/netx/net/sourceforge/jnlp/security/policyeditor/PolicyEditor.java Thu Jul 30 18:51:00 2015 +0200 +++ b/netx/net/sourceforge/jnlp/security/policyeditor/PolicyEditor.java Thu Jul 30 13:49:33 2015 -0400 @@ -1778,7 +1778,7 @@ }); } - private static String getFilePathArgument(OptionParser optionParser) { + static String getFilePathArgument(OptionParser optionParser) { final boolean openDefaultFile = optionParser.hasOption(OptionsDefinitions.OPTIONS.DEFAULTFILE); final boolean hasFileArgument = optionParser.hasOption(OptionsDefinitions.OPTIONS.FILE); final boolean hasMainArgument = optionParser.mainArgExists();
--- a/tests/netx/unit/net/sourceforge/jnlp/security/policyeditor/PolicyEditorTest.java Thu Jul 30 18:51:00 2015 +0200 +++ b/tests/netx/unit/net/sourceforge/jnlp/security/policyeditor/PolicyEditorTest.java Thu Jul 30 13:49:33 2015 -0400 @@ -42,11 +42,16 @@ import static org.junit.Assert.assertTrue; import java.io.File; +import java.net.URI; +import java.net.URISyntaxException; import java.util.Collection; import java.util.HashSet; import java.util.Map; import java.util.Set; +import net.sourceforge.jnlp.OptionsDefinitions; +import net.sourceforge.jnlp.config.PathsAndFiles; +import net.sourceforge.jnlp.util.optionparser.OptionParser; import org.junit.Before; import org.junit.Test; import sun.security.provider.PolicyParser; @@ -68,7 +73,7 @@ final Collection<String> initialCodebases = editor.getCodebases(); assertTrue("Editor should have one codebase to begin with", initialCodebases.size() == 1); assertTrue("Editor's initial codebase should be \"\" (empty string)", - initialCodebases.toArray(new String[initialCodebases.size()])[0].equals("")); + initialCodebases.toArray(new String[initialCodebases.size()])[0].equals("")); } @Test @@ -280,4 +285,94 @@ } } + @Test + public void testFilePathArgumentMainArg() { + String[] args = new String[] { "foo" }; + OptionParser optionParser = new OptionParser(args, OptionsDefinitions.getPolicyEditorOptions()); + String result = PolicyEditor.getFilePathArgument(optionParser); + assertTrue(result.equals("foo")); + } + + @Test + public void testFilePathArgumentMainArg2() { + String[] args = new String[] { "-codebase", "http://example.com", "foo" }; + OptionParser optionParser = new OptionParser(args, OptionsDefinitions.getPolicyEditorOptions()); + String result = PolicyEditor.getFilePathArgument(optionParser); + assertTrue(result.equals("foo")); + } + + @Test + public void testFilePathArgumentFileSwitch() { + String[] args = new String[] { "-file", "foo" }; + OptionParser optionParser = new OptionParser(args, OptionsDefinitions.getPolicyEditorOptions()); + String result = PolicyEditor.getFilePathArgument(optionParser); + assertTrue(result.equals("foo")); + } + + @Test + public void testFilePathArgumentFileSwitch2() { + String[] args = new String[] { "-codebase", "http://example.com", "-file", "foo" }; + OptionParser optionParser = new OptionParser(args, OptionsDefinitions.getPolicyEditorOptions()); + String result = PolicyEditor.getFilePathArgument(optionParser); + assertTrue(result.equals("foo")); + } + + @Test + public void testFilePathArgumentDefaultFileSwitch() throws URISyntaxException { + String[] args = new String[] { "-defaultfile" }; + OptionParser optionParser = new OptionParser(args, OptionsDefinitions.getPolicyEditorOptions()); + String result = PolicyEditor.getFilePathArgument(optionParser); + assertTrue(result.equals(new File(new URI(PathsAndFiles.JAVA_POLICY.getFullPath())).getAbsolutePath())); + } + + @Test + public void testFilePathArgumentDefaultFileSwitch2() throws URISyntaxException { + String[] args = new String[] { "-codebase", "http://example.com", "-defaultfile" }; + OptionParser optionParser = new OptionParser(args, OptionsDefinitions.getPolicyEditorOptions()); + String result = PolicyEditor.getFilePathArgument(optionParser); + assertTrue(result.equals(new File(new URI(PathsAndFiles.JAVA_POLICY.getFullPath())).getAbsolutePath())); + } + + @Test(expected = IllegalArgumentException.class) + public void testMainArgAndFileSwitch() { + String[] args = new String[] { "-file", "foo", "bar" }; + OptionParser optionParser = new OptionParser(args, OptionsDefinitions.getPolicyEditorOptions()); + PolicyEditor.getFilePathArgument(optionParser); + } + + @Test(expected = IllegalArgumentException.class) + public void testMainArgAndFileSwitch2() { + String[] args = new String[] { "bar", "-file", "foo" }; + OptionParser optionParser = new OptionParser(args, OptionsDefinitions.getPolicyEditorOptions()); + PolicyEditor.getFilePathArgument(optionParser); + } + + @Test(expected = IllegalArgumentException.class) + public void testDefaultFileSwitchAndMainArg() { + String[] args = new String[] { "-defaultfile", "foo" }; + OptionParser optionParser = new OptionParser(args, OptionsDefinitions.getPolicyEditorOptions()); + PolicyEditor.getFilePathArgument(optionParser); + } + + @Test(expected = IllegalArgumentException.class) + public void testDefaultFileSwitchAndMainArg2() { + String[] args = new String[] { "foo", "-defaultfile" }; + OptionParser optionParser = new OptionParser(args, OptionsDefinitions.getPolicyEditorOptions()); + PolicyEditor.getFilePathArgument(optionParser); + } + + @Test(expected = IllegalArgumentException.class) + public void testDefaultFileSwitchAndMainArgAndFileSwitch() { + String[] args = new String[] { "-defaultfile", "-file", "foo" }; + OptionParser optionParser = new OptionParser(args, OptionsDefinitions.getPolicyEditorOptions()); + PolicyEditor.getFilePathArgument(optionParser); + } + + @Test(expected = IllegalArgumentException.class) + public void testDefaultFileSwitchAndMainArgAndFileSwitch2() { + String[] args = new String[] { "-file", "foo", "-defaultfile" }; + OptionParser optionParser = new OptionParser(args, OptionsDefinitions.getPolicyEditorOptions()); + PolicyEditor.getFilePathArgument(optionParser); + } + }