http://git-wip-us.apache.org/repos/asf/commons-cli/blob/9e65354f/src/test/org/apache/commons/cli2/validation/FileValidatorTest.java ---------------------------------------------------------------------- diff --git a/src/test/org/apache/commons/cli2/validation/FileValidatorTest.java b/src/test/org/apache/commons/cli2/validation/FileValidatorTest.java deleted file mode 100644 index 1506064..0000000 --- a/src/test/org/apache/commons/cli2/validation/FileValidatorTest.java +++ /dev/null @@ -1,195 +0,0 @@ -/* - * Copyright 2004-2005 The Apache Software Foundation - * - * 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 org.apache.commons.cli2.validation; - -import java.io.File; -import java.io.IOException; -import java.util.Arrays; -import java.util.Iterator; -import java.util.List; - -import junit.framework.TestCase; - -/** - * JUnit test case for the FileValidator. - * - * @author Rob Oxspring - * @author John Keyes - */ -public class FileValidatorTest extends TestCase { - - public void testValidate() throws InvalidArgumentException { - final Object[] array = new Object[] { "src", "project.xml", - "veryunlikelyfilename" }; - final List list = Arrays.asList(array); - final FileValidator validator = new FileValidator(); - - validator.validate(list); - - final Iterator i = list.iterator(); - assertEquals(new File("src"), i.next()); - assertEquals(new File("project.xml"), i.next()); - assertEquals(new File("veryunlikelyfilename"), i.next()); - assertFalse(i.hasNext()); - } - - public void testValidate_Directory() { - final Object[] array = new Object[] { "src", "project.xml" }; - final List list = Arrays.asList(array); - final FileValidator validator = FileValidator - .getExistingDirectoryInstance(); - - assertTrue("is a directory validator", validator.isDirectory()); - assertFalse("is not a file validator", validator.isFile()); - assertTrue("is an existing file validator", validator.isExisting()); - assertFalse("is not a hidden file validator", validator.isHidden()); - - try { - validator.validate(list); - fail("InvalidArgumentException"); - } catch (InvalidArgumentException e) { - assertEquals("project.xml", e.getMessage()); - } - } - - public void testValidate_ReadableFile() { - // make file readonly - File file = new File("src/test/data/readable.txt"); - file.setReadOnly(); - - final Object[] array = new Object[] { "src/test/data/readable.txt", - "src/test/data/notreadable.txt" }; - final List list = Arrays.asList(array); - final FileValidator validator = FileValidator.getExistingFileInstance(); - validator.setReadable(true); - - assertFalse("is not a directory validator", validator.isDirectory()); - assertTrue("is a file validator", validator.isFile()); - assertTrue("is an existing file validator", validator.isExisting()); - assertFalse("is not a hidden file validator", validator.isHidden()); - assertTrue("is a readable file validator", validator.isReadable()); - assertFalse("is not a writable file validator", validator.isWritable()); - - try { - validator.validate(list); - fail("InvalidArgumentException"); - } catch (InvalidArgumentException e) { - assertEquals("src/test/data/notreadable.txt", e.getMessage()); - } - } - - public void testValidate_WritableFile() { - // make file readonly - File file = new File("src/test/data/readable.txt"); - file.setReadOnly(); - - final Object[] array = new Object[] { "src/test/data/writable.txt", - "src/test/data/readable.txt" }; - final List list = Arrays.asList(array); - final FileValidator validator = FileValidator.getExistingFileInstance(); - validator.setWritable(true); - - assertFalse("is not a directory validator", validator.isDirectory()); - assertTrue("is a file validator", validator.isFile()); - assertTrue("is an existing file validator", validator.isExisting()); - assertFalse("is not a hidden file validator", validator.isHidden()); - assertFalse("is not a readable file validator", validator.isReadable()); - assertTrue("is a writable file validator", validator.isWritable()); - - try { - validator.validate(list); - fail("InvalidArgumentException"); - } catch (InvalidArgumentException e) { - assertEquals("src/test/data/readable.txt", e.getMessage()); - } - } - - public void testValidate_HiddenFile() throws InvalidArgumentException { - // make file hidden on Windows - attribute("H"); - - final Object[] array = new Object[] { "src/test/data/.hidden.txt", "src" }; - final List list = Arrays.asList(array); - final FileValidator validator = FileValidator.getExistingFileInstance(); - validator.setHidden(true); - - assertFalse("is not a directory validator", validator.isDirectory()); - assertTrue("is a file validator", validator.isFile()); - assertTrue("is an existing file validator", validator.isExisting()); - assertTrue("is a hidden file validator", validator.isHidden()); - - try { - validator.validate(list); - fail("InvalidArgumentException"); - } catch (InvalidArgumentException e) { - assertEquals("src", e.getMessage()); - } - } - - private void attribute(String attr) { - final String os = System.getProperty("os.name").toLowerCase(); - - // if the test is run on windows, run the attrib program - // to set the hidden attribute - if (os.indexOf("windows") != -1) { - // windows - try { - Process proc = Runtime.getRuntime().exec( - "attrib.exe +" + attr + " src/test/data/.hidden.txt", - null, new File(".")); - proc.waitFor(); - } catch (InterruptedException e) { - System.out.println(e.getMessage()); - e.printStackTrace(); - } catch (IOException e) { - System.out.println(e.getMessage()); - e.printStackTrace(); - } - } - } - - public void testValidate_Existing() { - final Object[] array = new Object[] { "project.xml", - "veryunlikelyfilename" }; - final List list = Arrays.asList(array); - final FileValidator validator = FileValidator.getExistingInstance(); - - assertFalse("is not a directory validator", validator.isDirectory()); - assertFalse("is not a file validator", validator.isFile()); - assertTrue("is an existing file validator", validator.isExisting()); - assertFalse("is not a hidden file validator", validator.isHidden()); - - try { - validator.validate(list); - fail("InvalidArgumentException"); - } catch (InvalidArgumentException e) { - assertEquals("veryunlikelyfilename", e.getMessage()); - } - } - - public void testValidate_File() { - final Object[] array = new Object[] { "project.xml", "src" }; - final List list = Arrays.asList(array); - final Validator validator = FileValidator.getExistingFileInstance(); - - try { - validator.validate(list); - fail("InvalidArgumentException"); - } catch (InvalidArgumentException e) { - assertEquals("src", e.getMessage()); - } - } -}
http://git-wip-us.apache.org/repos/asf/commons-cli/blob/9e65354f/src/test/org/apache/commons/cli2/validation/NumberValidatorTest.java ---------------------------------------------------------------------- diff --git a/src/test/org/apache/commons/cli2/validation/NumberValidatorTest.java b/src/test/org/apache/commons/cli2/validation/NumberValidatorTest.java deleted file mode 100644 index b698ba7..0000000 --- a/src/test/org/apache/commons/cli2/validation/NumberValidatorTest.java +++ /dev/null @@ -1,167 +0,0 @@ -/* - * Copyright 2003-2005 The Apache Software Foundation - * - * 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 org.apache.commons.cli2.validation; - -import java.text.NumberFormat; - -import java.util.Arrays; -import java.util.Iterator; -import java.util.List; - -import junit.framework.TestCase; - -import org.apache.commons.cli2.resource.ResourceConstants; -import org.apache.commons.cli2.resource.ResourceHelper; - -/** - * JUnit test case for NumberValidator. - * - * @author Rob Oxspring - * @author John Keyes - */ -public class NumberValidatorTest - extends TestCase { - private static final ResourceHelper resources = ResourceHelper.getResourceHelper(); - - public void testValidate_Number() - throws InvalidArgumentException { - final NumberFormat format = NumberFormat.getNumberInstance(); - - final Object[] array = - new Object[] { format.format(1d), format.format(1.07d), format.format(-.45d) }; - - { - final List list = Arrays.asList(array); - final Validator validator = NumberValidator.getNumberInstance(); - - validator.validate(list); - - final Iterator i = list.iterator(); - assertEquals(1d, ((Number) i.next()).doubleValue(), 0.0001); - assertEquals(1.07d, ((Number) i.next()).doubleValue(), 0.0001); - assertEquals(-.45d, ((Number) i.next()).doubleValue(), 0.0001); - assertFalse(i.hasNext()); - } - } - - public void testValidate_Currency() - throws InvalidArgumentException { - NumberFormat format = NumberFormat.getCurrencyInstance(); - final Object[] array = - new Object[] { format.format(1d), format.format(1.07), format.format(-0.45) }; - final List list = Arrays.asList(array); - - final NumberValidator validator = NumberValidator.getCurrencyInstance(); - assertEquals("incorrect currency format", format, validator.getFormat()); - - validator.validate(list); - - final Iterator i = list.iterator(); - assertEquals(1d, ((Number) i.next()).doubleValue(), 0.0001); - assertEquals(1.07d, ((Number) i.next()).doubleValue(), 0.0001); - assertEquals(-.45d, ((Number) i.next()).doubleValue(), 0.0001); - assertFalse(i.hasNext()); - } - - public void testValidate_Percent() - throws InvalidArgumentException { - final NumberFormat format = NumberFormat.getPercentInstance(); - - final Object[] array = - new Object[] { - format.format(.01), format.format(1.07), format.format(-.45), - format.format(0.001) - }; - final List list = Arrays.asList(array); - final Validator validator = NumberValidator.getPercentInstance(); - - validator.validate(list); - - final Iterator i = list.iterator(); - assertEquals(0.01d, ((Number) i.next()).doubleValue(), 0.0001); - assertEquals(1.07d, ((Number) i.next()).doubleValue(), 0.0001); - assertEquals(-.45d, ((Number) i.next()).doubleValue(), 0.0001); - assertEquals(0.00001d, ((Number) i.next()).doubleValue(), 0.0001); - assertFalse(i.hasNext()); - } - - public void testValidate_Integer() - throws InvalidArgumentException { - final Object[] array = new Object[] { "1", "107", "-45" }; - final List list = Arrays.asList(array); - final Validator validator = NumberValidator.getIntegerInstance(); - - validator.validate(list); - - final Iterator i = list.iterator(); - assertEquals(1d, ((Number) i.next()).doubleValue(), 0.0001); - assertEquals(107d, ((Number) i.next()).doubleValue(), 0.0001); - assertEquals(-45d, ((Number) i.next()).doubleValue(), 0.0001); - assertFalse(i.hasNext()); - } - - public void testValidate_ExcessChars() { - final Object[] array = new Object[] { "10DowningStreet" }; - final List list = Arrays.asList(array); - final Validator validator = NumberValidator.getIntegerInstance(); - - try { - validator.validate(list); - fail("InvalidArgumentException"); - } catch (InvalidArgumentException e) { - assertEquals("10DowningStreet", e.getMessage()); - } - } - - public void testValidate_Maximum() { - final Object[] array = new Object[] { "1", "107" }; - final List list = Arrays.asList(array); - final NumberValidator validator = NumberValidator.getIntegerInstance(); - Integer max = new Integer(100); - - validator.setMaximum(max); - - assertTrue("no minimum set", validator.getMinimum() == null); - assertEquals("incorrect maximum value", max, validator.getMaximum()); - - try { - validator.validate(list); - fail("107 too big"); - } catch (InvalidArgumentException ive) { - assertEquals(resources.getMessage(ResourceConstants.NUMBERVALIDATOR_NUMBER_OUTOFRANGE, - "107"), ive.getMessage()); - } - } - - public void testValidate_Minimum() { - final Object[] array = new Object[] { "107", "1" }; - final List list = Arrays.asList(array); - final NumberValidator validator = NumberValidator.getIntegerInstance(); - Integer min = new Integer(100); - validator.setMinimum(min); - - assertTrue("no maximum set", validator.getMaximum() == null); - assertEquals("incorrect minimum value", min, validator.getMinimum()); - - try { - validator.validate(list); - fail("1 too small"); - } catch (InvalidArgumentException ive) { - assertEquals(resources.getMessage(ResourceConstants.NUMBERVALIDATOR_NUMBER_OUTOFRANGE, - "1"), ive.getMessage()); - } - } -} http://git-wip-us.apache.org/repos/asf/commons-cli/blob/9e65354f/src/test/org/apache/commons/cli2/validation/TimeZoneTestSuite.java ---------------------------------------------------------------------- diff --git a/src/test/org/apache/commons/cli2/validation/TimeZoneTestSuite.java b/src/test/org/apache/commons/cli2/validation/TimeZoneTestSuite.java deleted file mode 100644 index 238de62..0000000 --- a/src/test/org/apache/commons/cli2/validation/TimeZoneTestSuite.java +++ /dev/null @@ -1,45 +0,0 @@ -/** - * Copyright 2005 The Apache Software Foundation - * - * 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 org.apache.commons.cli2.validation; - -import java.util.TimeZone; - -import junit.extensions.TestDecorator; - -import junit.framework.Test; -import junit.framework.TestResult; - -public class TimeZoneTestSuite - extends TestDecorator { - private final TimeZone timeZone; - private final TimeZone originalTimeZone; - - public TimeZoneTestSuite(String timeZone, - Test test) { - super(test); - this.timeZone = TimeZone.getTimeZone(timeZone); - this.originalTimeZone = TimeZone.getDefault(); - } - - public void run(TestResult testResult) { - try { - TimeZone.setDefault(timeZone); - super.run(testResult); - } finally { - TimeZone.setDefault(originalTimeZone); // cleanup - } - } -} http://git-wip-us.apache.org/repos/asf/commons-cli/blob/9e65354f/src/test/org/apache/commons/cli2/validation/UrlValidatorTest.java ---------------------------------------------------------------------- diff --git a/src/test/org/apache/commons/cli2/validation/UrlValidatorTest.java b/src/test/org/apache/commons/cli2/validation/UrlValidatorTest.java deleted file mode 100644 index 7725fc5..0000000 --- a/src/test/org/apache/commons/cli2/validation/UrlValidatorTest.java +++ /dev/null @@ -1,92 +0,0 @@ -/** - * Copyright 2004 The Apache Software Foundation - * - * 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 org.apache.commons.cli2.validation; - -import java.net.MalformedURLException; -import java.net.URL; - -import java.util.Arrays; -import java.util.Iterator; -import java.util.List; - -import junit.framework.TestCase; - -import org.apache.commons.cli2.resource.ResourceConstants; -import org.apache.commons.cli2.resource.ResourceHelper; - -public class UrlValidatorTest - extends TestCase { - private static final ResourceHelper resources = ResourceHelper.getResourceHelper(); - - public void testValidate() - throws InvalidArgumentException, MalformedURLException { - final Object[] array = new Object[] { "http://www.apache.org/", "file:///etc" }; - final List list = Arrays.asList(array); - final Validator validator = new UrlValidator(); - - validator.validate(list); - - final Iterator i = list.iterator(); - assertEquals(new URL("http://www.apache.org/"), i.next()); - assertEquals(new URL("file:///etc"), i.next()); - assertFalse(i.hasNext()); - } - - public void testMalformedURL() - throws InvalidArgumentException, MalformedURLException { - final Object[] array = new Object[] { "www.apache.org" }; - final List list = Arrays.asList(array); - final Validator validator = new UrlValidator(); - - try { - validator.validate(list); - } catch (InvalidArgumentException e) { - assertEquals(resources.getMessage(ResourceConstants.URLVALIDATOR_MALFORMED_URL, - new Object[] { "www.apache.org" }), e.getMessage()); - } - } - - public void testBadProtocol() { - { - final Object[] array = new Object[] { "http://www.apache.org/", "file:///etc" }; - final List list = Arrays.asList(array); - final UrlValidator validator = new UrlValidator(); - validator.setProtocol("http"); - - assertEquals("incorrect protocol", "http", validator.getProtocol()); - - try { - validator.validate(list); - fail("Expected InvalidArgumentException"); - } catch (InvalidArgumentException e) { - assertEquals("file:///etc", e.getMessage()); - } - } - - { - final Object[] array = new Object[] { "http://www.apache.org/", "file:///etc" }; - final List list = Arrays.asList(array); - final UrlValidator validator = new UrlValidator("http"); - - try { - validator.validate(list); - fail("Expected InvalidArgumentException"); - } catch (InvalidArgumentException e) { - assertEquals("file:///etc", e.getMessage()); - } - } - } -} http://git-wip-us.apache.org/repos/asf/commons-cli/blob/9e65354f/src/test/org/apache/commons/cli2/validation/protect/ProtectedClass.java ---------------------------------------------------------------------- diff --git a/src/test/org/apache/commons/cli2/validation/protect/ProtectedClass.java b/src/test/org/apache/commons/cli2/validation/protect/ProtectedClass.java deleted file mode 100644 index fdac80f..0000000 --- a/src/test/org/apache/commons/cli2/validation/protect/ProtectedClass.java +++ /dev/null @@ -1,22 +0,0 @@ -/** - * Copyright 2003-2004 The Apache Software Foundation - * - * 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 org.apache.commons.cli2.validation.protect; - -class ProtectedClass { - protected ProtectedClass() { - // used to test something??? - } -}
