You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by ba...@apache.org on 2008/03/22 03:49:46 UTC
svn commit: r639941 [17/17] - in /commons/proper/cli/trunk: ./
src/java/org/apache/commons/cli2/ src/java/org/apache/commons/cli2/builder/
src/java/org/apache/commons/cli2/commandline/
src/java/org/apache/commons/cli2/option/ src/java/org/apache/common...
Modified: commons/proper/cli/trunk/src/test/org/apache/commons/cli2/validation/DateValidatorTest.java
URL: http://svn.apache.org/viewvc/commons/proper/cli/trunk/src/test/org/apache/commons/cli2/validation/DateValidatorTest.java?rev=639941&r1=639940&r2=639941&view=diff
==============================================================================
--- commons/proper/cli/trunk/src/test/org/apache/commons/cli2/validation/DateValidatorTest.java (original)
+++ commons/proper/cli/trunk/src/test/org/apache/commons/cli2/validation/DateValidatorTest.java Fri Mar 21 19:49:41 2008
@@ -1,220 +1 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You 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.DateFormat;
-import java.text.DateFormatSymbols;
-import java.text.SimpleDateFormat;
-import java.util.Arrays;
-import java.util.Calendar;
-import java.util.Date;
-import java.util.Iterator;
-import java.util.List;
-
-import junit.framework.Test;
-import junit.framework.TestCase;
-import junit.framework.TestSuite;
-
-import org.apache.commons.cli2.resource.ResourceConstants;
-import org.apache.commons.cli2.resource.ResourceHelper;
-
-/**
- * JUnit test case for DateValidator.
- *
- * @author Rob Oxspring
- * @author John Keyes
- */
-public class DateValidatorTest
- extends TestCase {
- private static final ResourceHelper resources = ResourceHelper.getResourceHelper();
- public static final DateFormat D_M_YY = new SimpleDateFormat("d/M/yy");
- public static final DateFormat YYYY_MM_DD = new SimpleDateFormat("yyyy-MM-dd");
- private List formats = Arrays.asList(new Object[] { D_M_YY, YYYY_MM_DD });
-
- public void testSingleFormatValidate()
- throws InvalidArgumentException {
- final Object[] array = new Object[] { "23/12/03" };
- final List list = Arrays.asList(array);
- final Validator validator = new DateValidator(D_M_YY);
-
- validator.validate(list);
-
- final Iterator i = list.iterator();
- assertEquals("2003-12-23", YYYY_MM_DD.format((Date) i.next()));
- assertFalse(i.hasNext());
- }
-
- public void testDefaultDateFormatValidate()
- throws InvalidArgumentException {
- DateFormatSymbols symbols = new DateFormatSymbols();
- final Object[] array = new Object[] { "23-" + symbols.getShortMonths()[11] + "-2003" };
- final List list = Arrays.asList(array);
- final Validator validator = new DateValidator( new SimpleDateFormat("dd-MMM-yyyy") );
-
- validator.validate(list);
-
- final Iterator i = list.iterator();
- // CLI-40: For some reason, the YYYY_MM_DD object gets quite
- // confused here and returns 2003-12-22. If we make a new one
- // there is no problem.
- assertEquals("2003-12-23", new SimpleDateFormat("yyyy-MM-dd").format((Date) i.next()));
- assertFalse(i.hasNext());
- }
-
- public void testDefaultTimeFormatValidate()
- throws InvalidArgumentException {
- final Object[] array = new Object[] { "18:00:00" };
- final List list = Arrays.asList(array);
- final Validator validator = new DateValidator( new SimpleDateFormat("HH:mm:ss") );
-
- validator.validate(list);
-
- final Iterator i = list.iterator();
- final DateFormat df = new SimpleDateFormat("HH:mm:ss");
- assertEquals("18:00:00", df.format((Date) i.next()));
- assertFalse(i.hasNext());
- }
-
- public void testDefaultDateTimeFormatValidate()
- throws InvalidArgumentException {
- DateFormatSymbols symbols = new DateFormatSymbols();
- final Object[] array = new Object[] { "23-" + symbols.getShortMonths()[0] + "-2003 18:00:00" };
- final List list = Arrays.asList(array);
- final Validator validator = new DateValidator( new SimpleDateFormat("dd-MMM-yyyy HH:mm:ss") );
-
- validator.validate(list);
-
- final Iterator i = list.iterator();
- final DateFormat df = new SimpleDateFormat("yyyy/M/dd HH:mm:ss");
- assertEquals("2003/1/23 18:00:00", df.format((Date) i.next()));
- assertFalse(i.hasNext());
- }
-
- public void testDefaultValidator()
- throws InvalidArgumentException {
- final Object[] array = new Object[] { "23/01/03 18:00" };
- final List list = Arrays.asList(array);
- final Validator validator = new DateValidator(new SimpleDateFormat("dd/MM/yy HH:mm"));
-
- validator.validate(list);
-
- final Iterator i = list.iterator();
- final DateFormat df = new SimpleDateFormat("yyyy/M/dd HH:mm:ss");
- assertEquals("2003/1/23 18:00:00", df.format((Date) i.next()));
- assertFalse(i.hasNext());
- }
-
- public void testValidate()
- throws InvalidArgumentException {
- final Object[] array = new Object[] { "23/12/03", "2002-10-12" };
- final List list = Arrays.asList(array);
- final Validator validator = new DateValidator(formats);
-
- validator.validate(list);
-
- final Iterator i = list.iterator();
- assertEquals("2003-12-23", YYYY_MM_DD.format((Date) i.next()));
- assertEquals("2002-10-12", YYYY_MM_DD.format((Date) i.next()));
- assertFalse(i.hasNext());
- }
-
- public void testMinimumBounds()
- throws InvalidArgumentException {
- final DateValidator validator = new DateValidator(formats);
- final Calendar cal = Calendar.getInstance();
-
- {
- final Object[] array = new Object[] { "23/12/03", "2002-10-12" };
- final List list = Arrays.asList(array);
- cal.set(2002, 1, 12);
-
- final Date min = cal.getTime();
- validator.setMinimum(min);
- assertTrue("maximum bound is set", validator.getMaximum() == null);
- assertEquals("minimum bound is incorrect", min, validator.getMinimum());
- validator.validate(list);
- }
-
- {
- final Object[] array = new Object[] { "23/12/03", "2002-10-12" };
- final List list = Arrays.asList(array);
- cal.set(2003, 1, 12);
-
- final Date min = cal.getTime();
- validator.setMinimum(min);
-
- try {
- validator.validate(list);
- fail("minimum out of bounds exception not caught");
- } catch (final InvalidArgumentException exp) {
- assertEquals(resources.getMessage(ResourceConstants.DATEVALIDATOR_DATE_OUTOFRANGE,
- new Object[] { "2002-10-12" }), exp.getMessage());
- }
- }
- }
-
- public void testFormats()
- throws InvalidArgumentException {
- final DateValidator validator = new DateValidator(formats);
- assertEquals("date format is incorrect", ((SimpleDateFormat) formats.get(0)).toPattern(),
- ((SimpleDateFormat) validator.getFormats()[0]).toPattern());
- assertEquals("date format is incorrect", ((SimpleDateFormat) formats.get(1)).toPattern(),
- ((SimpleDateFormat) validator.getFormats()[1]).toPattern());
- }
-
- public void testMaximumBounds()
- throws InvalidArgumentException {
- final DateValidator validator = new DateValidator(formats);
- final Calendar cal = Calendar.getInstance();
-
- {
- final Object[] array = new Object[] { "23/12/03", "2002-10-12" };
- final List list = Arrays.asList(array);
- cal.set(2004, 1, 12);
-
- final Date max = cal.getTime();
- validator.setMaximum(max);
- assertTrue("minimum bound is set", validator.getMinimum() == null);
- assertEquals("maximum bound is incorrect", max, validator.getMaximum());
- validator.validate(list);
- }
-
- {
- final Object[] array = new Object[] { "23/12/03", "2004-10-12" };
- final List list = Arrays.asList(array);
- cal.set(2004, 1, 12);
-
- final Date max = cal.getTime();
- validator.setMaximum(max);
-
- try {
- validator.validate(list);
- fail("maximum out of bounds exception not caught");
- } catch (final InvalidArgumentException exp) {
- assertEquals(resources.getMessage(ResourceConstants.DATEVALIDATOR_DATE_OUTOFRANGE,
- new Object[] { "2004-10-12" }), exp.getMessage());
- }
- }
- }
-
- public static Test suite() {
- Test result = new TestSuite(DateValidatorTest.class); // default behavior
- result = new TimeZoneTestSuite("EST", result); // ensure it runs in EST timezone
-
- return result;
- }
-}
+/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You 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.DateFormat;import java.text.DateFormatSymbols;import java.text.SimpleDateFormat;import java.util.Arrays;import java.util.Calendar;import java.u
til.Date;import java.util.Iterator;import java.util.List;import junit.framework.Test;import junit.framework.TestCase;import junit.framework.TestSuite;import org.apache.commons.cli2.resource.ResourceConstants;import org.apache.commons.cli2.resource.ResourceHelper;/** * JUnit test case for DateValidator. * * @author Rob Oxspring * @author John Keyes */public class DateValidatorTest extends TestCase { private static final ResourceHelper resources = ResourceHelper.getResourceHelper(); public static final DateFormat D_M_YY = new SimpleDateFormat("d/M/yy"); public static final DateFormat YYYY_MM_DD = new SimpleDateFormat("yyyy-MM-dd"); private List formats = Arrays.asList(new Object[] { D_M_YY, YYYY_MM_DD }); public void testSingleFormatValidate() throws InvalidArgumentException { final Object[] array = new Object[] { "23/12/03" }; final List list = Arrays.asList(array); final Validator validator = new DateValidator(D_M_YY); val
idator.validate(list); final Iterator i = list.iterator(); assertEquals("2003-12-23", YYYY_MM_DD.format((Date) i.next())); assertFalse(i.hasNext()); } public void testDefaultDateFormatValidate() throws InvalidArgumentException { DateFormatSymbols symbols = new DateFormatSymbols(); final Object[] array = new Object[] { "23-" + symbols.getShortMonths()[11] + "-2003" }; final List list = Arrays.asList(array); final Validator validator = new DateValidator( new SimpleDateFormat("dd-MMM-yyyy") ); validator.validate(list); final Iterator i = list.iterator(); // CLI-40: For some reason, the YYYY_MM_DD object gets quite // confused here and returns 2003-12-22. If we make a new one // there is no problem. assertEquals("2003-12-23", new SimpleDateFormat("yyyy-MM-dd").format((Date) i.next())); assertFalse(i.hasNext()); } public void testDefaultTimeFormatValidate()
throws InvalidArgumentException { final Object[] array = new Object[] { "18:00:00" }; final List list = Arrays.asList(array); final Validator validator = new DateValidator( new SimpleDateFormat("HH:mm:ss") ); validator.validate(list); final Iterator i = list.iterator(); final DateFormat df = new SimpleDateFormat("HH:mm:ss"); assertEquals("18:00:00", df.format((Date) i.next())); assertFalse(i.hasNext()); } public void testDefaultDateTimeFormatValidate() throws InvalidArgumentException { DateFormatSymbols symbols = new DateFormatSymbols(); final Object[] array = new Object[] { "23-" + symbols.getShortMonths()[0] + "-2003 18:00:00" }; final List list = Arrays.asList(array); final Validator validator = new DateValidator( new SimpleDateFormat("dd-MMM-yyyy HH:mm:ss") ); validator.validate(list); final Iterator i = list.iterator(); final DateFormat df = new Simple
DateFormat("yyyy/M/dd HH:mm:ss"); assertEquals("2003/1/23 18:00:00", df.format((Date) i.next())); assertFalse(i.hasNext()); } public void testDefaultValidator() throws InvalidArgumentException { final Object[] array = new Object[] { "23/01/03 18:00" }; final List list = Arrays.asList(array); final Validator validator = new DateValidator(new SimpleDateFormat("dd/MM/yy HH:mm")); validator.validate(list); final Iterator i = list.iterator(); final DateFormat df = new SimpleDateFormat("yyyy/M/dd HH:mm:ss"); assertEquals("2003/1/23 18:00:00", df.format((Date) i.next())); assertFalse(i.hasNext()); } public void testValidate() throws InvalidArgumentException { final Object[] array = new Object[] { "23/12/03", "2002-10-12" }; final List list = Arrays.asList(array); final Validator validator = new DateValidator(formats); validator.validate(list); final Ite
rator i = list.iterator(); assertEquals("2003-12-23", YYYY_MM_DD.format((Date) i.next())); assertEquals("2002-10-12", YYYY_MM_DD.format((Date) i.next())); assertFalse(i.hasNext()); } public void testMinimumBounds() throws InvalidArgumentException { final DateValidator validator = new DateValidator(formats); final Calendar cal = Calendar.getInstance(); { final Object[] array = new Object[] { "23/12/03", "2002-10-12" }; final List list = Arrays.asList(array); cal.set(2002, 1, 12); final Date min = cal.getTime(); validator.setMinimum(min); assertTrue("maximum bound is set", validator.getMaximum() == null); assertEquals("minimum bound is incorrect", min, validator.getMinimum()); validator.validate(list); } { final Object[] array = new Object[] { "23/12/03", "2002-10-12" }; final List list = Arrays.asLis
t(array); cal.set(2003, 1, 12); final Date min = cal.getTime(); validator.setMinimum(min); try { validator.validate(list); fail("minimum out of bounds exception not caught"); } catch (final InvalidArgumentException exp) { assertEquals(resources.getMessage(ResourceConstants.DATEVALIDATOR_DATE_OUTOFRANGE, new Object[] { "2002-10-12" }), exp.getMessage()); } } } public void testFormats() throws InvalidArgumentException { final DateValidator validator = new DateValidator(formats); assertEquals("date format is incorrect", ((SimpleDateFormat) formats.get(0)).toPattern(), ((SimpleDateFormat) validator.getFormats()[0]).toPattern()); assertEquals("date format is incorrect", ((SimpleDateFormat) formats.get(1)).toPattern(), ((SimpleDateFormat) valid
ator.getFormats()[1]).toPattern()); } public void testMaximumBounds() throws InvalidArgumentException { final DateValidator validator = new DateValidator(formats); final Calendar cal = Calendar.getInstance(); { final Object[] array = new Object[] { "23/12/03", "2002-10-12" }; final List list = Arrays.asList(array); cal.set(2004, 1, 12); final Date max = cal.getTime(); validator.setMaximum(max); assertTrue("minimum bound is set", validator.getMinimum() == null); assertEquals("maximum bound is incorrect", max, validator.getMaximum()); validator.validate(list); } { final Object[] array = new Object[] { "23/12/03", "2004-10-12" }; final List list = Arrays.asList(array); cal.set(2004, 1, 12); final Date max = cal.getTime(); validator.setMaximum(max); try { validator.
validate(list); fail("maximum out of bounds exception not caught"); } catch (final InvalidArgumentException exp) { assertEquals(resources.getMessage(ResourceConstants.DATEVALIDATOR_DATE_OUTOFRANGE, new Object[] { "2004-10-12" }), exp.getMessage()); } } } public static Test suite() { Test result = new TestSuite(DateValidatorTest.class); // default behavior result = new TimeZoneTestSuite("EST", result); // ensure it runs in EST timezone return result; }}
\ No newline at end of file
Modified: commons/proper/cli/trunk/src/test/org/apache/commons/cli2/validation/EnumValidatorTest.java
URL: http://svn.apache.org/viewvc/commons/proper/cli/trunk/src/test/org/apache/commons/cli2/validation/EnumValidatorTest.java?rev=639941&r1=639940&r2=639941&view=diff
==============================================================================
--- commons/proper/cli/trunk/src/test/org/apache/commons/cli2/validation/EnumValidatorTest.java (original)
+++ commons/proper/cli/trunk/src/test/org/apache/commons/cli2/validation/EnumValidatorTest.java Fri Mar 21 19:49:41 2008
@@ -1,66 +1 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You 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.Arrays;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Set;
-import java.util.TreeSet;
-
-import junit.framework.TestCase;
-
-import org.apache.commons.cli2.resource.ResourceConstants;
-import org.apache.commons.cli2.resource.ResourceHelper;
-
-public class EnumValidatorTest
- extends TestCase {
- private final static ResourceHelper resources = ResourceHelper.getResourceHelper();
- private final Set enumSet = new TreeSet(Arrays.asList(new Object[] { "red", "green", "blue" }));
-
- public void testValidate()
- throws InvalidArgumentException {
- final Object[] array = new Object[] { "red", "green" };
-
- {
- final List list = Arrays.asList(array);
- final EnumValidator validator = new EnumValidator(enumSet);
- assertEquals("valid values are incorrect", enumSet, validator.getValidValues());
- validator.validate(list);
-
- final Iterator i = list.iterator();
- assertEquals("red", i.next());
- assertEquals("green", i.next());
- assertFalse(i.hasNext());
- }
- }
-
- public void testNonMember() {
- final Object[] array = new Object[] { "red", "pink" };
- final List list = Arrays.asList(array);
- final EnumValidator validator = new EnumValidator(enumSet);
-
- try {
- validator.validate(list);
- fail("InvalidArgumentException");
- } catch (InvalidArgumentException e) {
- assertEquals(resources.getMessage(ResourceConstants.ENUM_ILLEGAL_VALUE,
- new Object[] { "pink", validator.getValuesAsString() }),
- e.getMessage());
- }
- }
-}
+/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You 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.Arrays;import java.util.Iterator;import java.util.List;import java.util.Set;import java.util.TreeSet;import junit.framework.TestCase;import org
.apache.commons.cli2.resource.ResourceConstants;import org.apache.commons.cli2.resource.ResourceHelper;public class EnumValidatorTest extends TestCase { private final static ResourceHelper resources = ResourceHelper.getResourceHelper(); private final Set enumSet = new TreeSet(Arrays.asList(new Object[] { "red", "green", "blue" })); public void testValidate() throws InvalidArgumentException { final Object[] array = new Object[] { "red", "green" }; { final List list = Arrays.asList(array); final EnumValidator validator = new EnumValidator(enumSet); assertEquals("valid values are incorrect", enumSet, validator.getValidValues()); validator.validate(list); final Iterator i = list.iterator(); assertEquals("red", i.next()); assertEquals("green", i.next()); assertFalse(i.hasNext()); } } public void testNonMember() { final Object[] array = new O
bject[] { "red", "pink" }; final List list = Arrays.asList(array); final EnumValidator validator = new EnumValidator(enumSet); try { validator.validate(list); fail("InvalidArgumentException"); } catch (InvalidArgumentException e) { assertEquals(resources.getMessage(ResourceConstants.ENUM_ILLEGAL_VALUE, new Object[] { "pink", validator.getValuesAsString() }), e.getMessage()); } }}
\ No newline at end of file
Modified: commons/proper/cli/trunk/src/test/org/apache/commons/cli2/validation/FileValidatorTest.java
URL: http://svn.apache.org/viewvc/commons/proper/cli/trunk/src/test/org/apache/commons/cli2/validation/FileValidatorTest.java?rev=639941&r1=639940&r2=639941&view=diff
==============================================================================
--- commons/proper/cli/trunk/src/test/org/apache/commons/cli2/validation/FileValidatorTest.java (original)
+++ commons/proper/cli/trunk/src/test/org/apache/commons/cli2/validation/FileValidatorTest.java Fri Mar 21 19:49:41 2008
@@ -1,196 +1 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You 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());
- }
- }
-}
+/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You 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;/** * JUn
it 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.getEx
istingFileInstance(); 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(a
rray); 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( "attr
ib.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()); } }}
\ No newline at end of file
Modified: commons/proper/cli/trunk/src/test/org/apache/commons/cli2/validation/NumberValidatorTest.java
URL: http://svn.apache.org/viewvc/commons/proper/cli/trunk/src/test/org/apache/commons/cli2/validation/NumberValidatorTest.java?rev=639941&r1=639940&r2=639941&view=diff
==============================================================================
--- commons/proper/cli/trunk/src/test/org/apache/commons/cli2/validation/NumberValidatorTest.java (original)
+++ commons/proper/cli/trunk/src/test/org/apache/commons/cli2/validation/NumberValidatorTest.java Fri Mar 21 19:49:41 2008
@@ -1,168 +1 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You 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());
- }
- }
-}
+/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You 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, ((N
umber) 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 NumberFo
rmat 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 Valid
ator 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 NumberVa
lidator 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()); } }}
\ No newline at end of file
Modified: commons/proper/cli/trunk/src/test/org/apache/commons/cli2/validation/TimeZoneTestSuite.java
URL: http://svn.apache.org/viewvc/commons/proper/cli/trunk/src/test/org/apache/commons/cli2/validation/TimeZoneTestSuite.java?rev=639941&r1=639940&r2=639941&view=diff
==============================================================================
--- commons/proper/cli/trunk/src/test/org/apache/commons/cli2/validation/TimeZoneTestSuite.java (original)
+++ commons/proper/cli/trunk/src/test/org/apache/commons/cli2/validation/TimeZoneTestSuite.java Fri Mar 21 19:49:41 2008
@@ -1,46 +1 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You 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
- }
- }
-}
+/** * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You 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 } }}
\ No newline at end of file
Modified: commons/proper/cli/trunk/src/test/org/apache/commons/cli2/validation/UrlValidatorTest.java
URL: http://svn.apache.org/viewvc/commons/proper/cli/trunk/src/test/org/apache/commons/cli2/validation/UrlValidatorTest.java?rev=639941&r1=639940&r2=639941&view=diff
==============================================================================
--- commons/proper/cli/trunk/src/test/org/apache/commons/cli2/validation/UrlValidatorTest.java (original)
+++ commons/proper/cli/trunk/src/test/org/apache/commons/cli2/validation/UrlValidatorTest.java Fri Mar 21 19:49:41 2008
@@ -1,93 +1 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You 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());
- }
- }
- }
-}
+/** * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You 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.TestCa
se;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()); } } { f
inal 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()); } } }}
\ No newline at end of file
Modified: commons/proper/cli/trunk/src/test/org/apache/commons/cli2/validation/protect/ProtectedClass.java
URL: http://svn.apache.org/viewvc/commons/proper/cli/trunk/src/test/org/apache/commons/cli2/validation/protect/ProtectedClass.java?rev=639941&r1=639940&r2=639941&view=diff
==============================================================================
--- commons/proper/cli/trunk/src/test/org/apache/commons/cli2/validation/protect/ProtectedClass.java (original)
+++ commons/proper/cli/trunk/src/test/org/apache/commons/cli2/validation/protect/ProtectedClass.java Fri Mar 21 19:49:41 2008
@@ -1,23 +1 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You 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???
- }
-}
+/** * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You 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??? }}
\ No newline at end of file