Author: svenmeier Date: Fri Jul 8 16:15:45 2011 New Revision: 1144374 URL: http://svn.apache.org/viewvc?rev=1144374&view=rev Log: moved wicket-util tests from wicket-core
Added: wicket/trunk/wicket-core/src/test/java/org/apache/wicket/ConverterLocatorTest.java (contents, props changed) - copied, changed from r1143986, wicket/trunk/wicket-core/src/test/java/org/apache/wicket/util/convert/converters/ConvertersTest.java wicket/trunk/wicket-core/src/test/java/org/apache/wicket/util/lang/WicketObjectsTest.java (contents, props changed) - copied, changed from r1143986, wicket/trunk/wicket-core/src/test/java/org/apache/wicket/util/lang/ObjectsTest.java wicket/trunk/wicket-util/src/test/java/org/apache/wicket/util/collections/MicroMapTest.java - copied unchanged from r1143986, wicket/trunk/wicket-core/src/test/java/org/apache/wicket/util/collections/MicroMapTest.java wicket/trunk/wicket-util/src/test/java/org/apache/wicket/util/collections/MiniMapTest.java - copied unchanged from r1143986, wicket/trunk/wicket-core/src/test/java/org/apache/wicket/util/collections/MiniMapTest.java wicket/trunk/wicket-util/src/test/java/org/apache/wicket/util/convert/ wicket/trunk/wicket-util/src/test/java/org/apache/wicket/util/convert/converters/ wicket/trunk/wicket-util/src/test/java/org/apache/wicket/util/convert/converters/ConvertersTest.java (with props) wicket/trunk/wicket-util/src/test/java/org/apache/wicket/util/crypt/ - copied from r1143986, wicket/trunk/wicket-core/src/test/java/org/apache/wicket/util/crypt/ wicket/trunk/wicket-util/src/test/java/org/apache/wicket/util/io/XmlReaderTest.java - copied unchanged from r1143986, wicket/trunk/wicket-core/src/test/java/org/apache/wicket/util/io/XmlReaderTest.java wicket/trunk/wicket-util/src/test/java/org/apache/wicket/util/io/test_1.html - copied unchanged from r1143986, wicket/trunk/wicket-core/src/test/java/org/apache/wicket/util/io/test_1.html wicket/trunk/wicket-util/src/test/java/org/apache/wicket/util/io/test_2.html - copied unchanged from r1143986, wicket/trunk/wicket-core/src/test/java/org/apache/wicket/util/io/test_2.html wicket/trunk/wicket-util/src/test/java/org/apache/wicket/util/io/test_3.html - copied unchanged from r1143986, wicket/trunk/wicket-core/src/test/java/org/apache/wicket/util/io/test_3.html wicket/trunk/wicket-util/src/test/java/org/apache/wicket/util/io/test_4.html - copied unchanged from r1143986, wicket/trunk/wicket-core/src/test/java/org/apache/wicket/util/io/test_4.html wicket/trunk/wicket-util/src/test/java/org/apache/wicket/util/io/test_5.html - copied unchanged from r1143986, wicket/trunk/wicket-core/src/test/java/org/apache/wicket/util/io/test_5.html wicket/trunk/wicket-util/src/test/java/org/apache/wicket/util/io/test_6.html - copied unchanged from r1143986, wicket/trunk/wicket-core/src/test/java/org/apache/wicket/util/io/test_6.html wicket/trunk/wicket-util/src/test/java/org/apache/wicket/util/io/test_7.html - copied unchanged from r1143986, wicket/trunk/wicket-core/src/test/java/org/apache/wicket/util/io/test_7.html wicket/trunk/wicket-util/src/test/java/org/apache/wicket/util/lang/ObjectsTest.java (with props) wicket/trunk/wicket-util/src/test/java/org/apache/wicket/util/lang/PrimitivesTest.java - copied unchanged from r1143986, wicket/trunk/wicket-core/src/test/java/org/apache/wicket/util/lang/PrimitivesTest.java wicket/trunk/wicket-util/src/test/java/org/apache/wicket/util/parse/ - copied from r1143986, wicket/trunk/wicket-core/src/test/java/org/apache/wicket/util/parse/ wicket/trunk/wicket-util/src/test/java/org/apache/wicket/util/size/ - copied from r1143986, wicket/trunk/wicket-core/src/test/java/org/apache/wicket/util/size/ wicket/trunk/wicket-util/src/test/java/org/apache/wicket/util/string/AppendingStringBufferTest.java - copied unchanged from r1143986, wicket/trunk/wicket-core/src/test/java/org/apache/wicket/util/string/AppendingStringBufferTest.java wicket/trunk/wicket-util/src/test/java/org/apache/wicket/util/string/PrependingStringBufferTest.java - copied unchanged from r1143986, wicket/trunk/wicket-core/src/test/java/org/apache/wicket/util/string/PrependingStringBufferTest.java wicket/trunk/wicket-util/src/test/java/org/apache/wicket/util/string/StringListTest.java - copied unchanged from r1143986, wicket/trunk/wicket-core/src/test/java/org/apache/wicket/util/string/StringListTest.java wicket/trunk/wicket-util/src/test/java/org/apache/wicket/util/string/interpolator/ - copied from r1143986, wicket/trunk/wicket-core/src/test/java/org/apache/wicket/util/string/interpolator/ wicket/trunk/wicket-util/src/test/java/org/apache/wicket/util/value/ValueMapTest.java - copied, changed from r1143986, wicket/trunk/wicket-core/src/test/java/org/apache/wicket/util/value/ValueMapTest.java Removed: wicket/trunk/wicket-core/src/test/java/org/apache/wicket/util/collections/ wicket/trunk/wicket-core/src/test/java/org/apache/wicket/util/convert/converters/ wicket/trunk/wicket-core/src/test/java/org/apache/wicket/util/crypt/ wicket/trunk/wicket-core/src/test/java/org/apache/wicket/util/io/XmlReaderTest.java wicket/trunk/wicket-core/src/test/java/org/apache/wicket/util/io/test_1.html wicket/trunk/wicket-core/src/test/java/org/apache/wicket/util/io/test_2.html wicket/trunk/wicket-core/src/test/java/org/apache/wicket/util/io/test_3.html wicket/trunk/wicket-core/src/test/java/org/apache/wicket/util/io/test_4.html wicket/trunk/wicket-core/src/test/java/org/apache/wicket/util/io/test_5.html wicket/trunk/wicket-core/src/test/java/org/apache/wicket/util/io/test_6.html wicket/trunk/wicket-core/src/test/java/org/apache/wicket/util/io/test_7.html wicket/trunk/wicket-core/src/test/java/org/apache/wicket/util/lang/ObjectsTest.java wicket/trunk/wicket-core/src/test/java/org/apache/wicket/util/lang/PrimitivesTest.java wicket/trunk/wicket-core/src/test/java/org/apache/wicket/util/parse/ wicket/trunk/wicket-core/src/test/java/org/apache/wicket/util/size/ wicket/trunk/wicket-core/src/test/java/org/apache/wicket/util/string/AppendingStringBufferTest.java wicket/trunk/wicket-core/src/test/java/org/apache/wicket/util/string/PrependingStringBufferTest.java wicket/trunk/wicket-core/src/test/java/org/apache/wicket/util/string/StringListTest.java wicket/trunk/wicket-core/src/test/java/org/apache/wicket/util/string/interpolator/VariableInterpolatorTest.java wicket/trunk/wicket-core/src/test/java/org/apache/wicket/util/value/ wicket/trunk/wicket-util/src/test/java/org/apache/wicket/util/string/interpolator/PropertyVariableInterpolatorTest.java Modified: wicket/trunk/wicket-core/src/test/java/org/apache/wicket/util/io/SerializableCheckerTest.java wicket/trunk/wicket-util/src/test/java/org/apache/wicket/util/crypt/Base64Test.java wicket/trunk/wicket-util/src/test/java/org/apache/wicket/util/parse/metapattern/MetaPatternTest.java wicket/trunk/wicket-util/src/test/java/org/apache/wicket/util/size/BytesTest.java wicket/trunk/wicket-util/src/test/java/org/apache/wicket/util/string/interpolator/VariableInterpolatorTest.java Copied: wicket/trunk/wicket-core/src/test/java/org/apache/wicket/ConverterLocatorTest.java (from r1143986, wicket/trunk/wicket-core/src/test/java/org/apache/wicket/util/convert/converters/ConvertersTest.java) URL: http://svn.apache.org/viewvc/wicket/trunk/wicket-core/src/test/java/org/apache/wicket/ConverterLocatorTest.java?p2=wicket/trunk/wicket-core/src/test/java/org/apache/wicket/ConverterLocatorTest.java&p1=wicket/trunk/wicket-core/src/test/java/org/apache/wicket/util/convert/converters/ConvertersTest.java&r1=1143986&r2=1144374&rev=1144374&view=diff ============================================================================== --- wicket/trunk/wicket-core/src/test/java/org/apache/wicket/util/convert/converters/ConvertersTest.java (original) +++ wicket/trunk/wicket-core/src/test/java/org/apache/wicket/ConverterLocatorTest.java Fri Jul 8 16:15:45 2011 @@ -14,35 +14,18 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.wicket.util.convert.converters; +package org.apache.wicket; -import java.math.BigDecimal; -import java.util.Calendar; -import java.util.Date; import java.util.Locale; import junit.framework.TestCase; -import org.apache.wicket.ConverterLocator; -import org.apache.wicket.IConverterLocator; -import org.apache.wicket.util.convert.ConversionException; -import org.apache.wicket.util.convert.converter.BigDecimalConverter; -import org.apache.wicket.util.convert.converter.BooleanConverter; -import org.apache.wicket.util.convert.converter.ByteConverter; -import org.apache.wicket.util.convert.converter.CalendarConverter; -import org.apache.wicket.util.convert.converter.DateConverter; -import org.apache.wicket.util.convert.converter.DoubleConverter; -import org.apache.wicket.util.convert.converter.FloatConverter; -import org.apache.wicket.util.convert.converter.IntegerConverter; -import org.apache.wicket.util.convert.converter.LongConverter; -import org.apache.wicket.util.convert.converter.ShortConverter; - /** - * Tests for the base converters. + * Tests for converter locators. * * @author Eelco Hillenius */ -public final class ConvertersTest extends TestCase +public final class ConverterLocatorTest extends TestCase { /** Dutch locale for localized testing. */ private static final Locale DUTCH_LOCALE = new Locale("nl", "NL"); @@ -50,7 +33,7 @@ public final class ConvertersTest extend /** * Construct. */ - public ConvertersTest() + public ConverterLocatorTest() { super(); } @@ -60,7 +43,7 @@ public final class ConvertersTest extend * * @param name */ - public ConvertersTest(String name) + public ConverterLocatorTest(String name) { super(name); } @@ -68,370 +51,13 @@ public final class ConvertersTest extend /** * Test generalized conversion */ - public void testConversion() - { - final IConverterLocator converter = new ConverterLocator(); - assertEquals("7", converter.getConverter(Integer.class).convertToString(7, Locale.US)); - assertEquals("7.1", converter.getConverter(Double.class).convertToString(7.1, Locale.US)); - assertEquals("7,1", converter.getConverter(Double.class).convertToString(7.1, DUTCH_LOCALE)); - - Calendar cal = Calendar.getInstance(DUTCH_LOCALE); - cal.clear(); - cal.set(2002, Calendar.OCTOBER, 24); - Date date = cal.getTime(); - - assertEquals(date, - converter.getConverter(Date.class).convertToObject("24-10-02", DUTCH_LOCALE)); - assertEquals("24-10-02", - converter.getConverter(Date.class).convertToString(date, DUTCH_LOCALE)); - - // empty strings should return null, NOT throw NPEs - assertNull(converter.getConverter(Integer.class).convertToObject("", Locale.US)); - assertNull(converter.getConverter(Byte.class).convertToObject("", Locale.US)); - assertNull(converter.getConverter(Character.class).convertToObject("", Locale.US)); - assertNull(converter.getConverter(Float.class).convertToObject("", Locale.US)); - assertNull(converter.getConverter(Long.class).convertToObject("", Locale.US)); - assertNull(converter.getConverter(Short.class).convertToObject("", Locale.US)); - assertNull(converter.getConverter(Date.class).convertToObject("", Locale.US)); - assertNull(converter.getConverter(Double.class).convertToObject("", Locale.US)); - assertEquals(Boolean.FALSE, - converter.getConverter(Boolean.class).convertToObject("", Locale.US)); - assertNotNull(converter.getConverter(String.class).convertToObject("", Locale.US)); - } - - /** - * @throws Exception - */ - public void testThousandSeperator() throws Exception - { - BigDecimalConverter bdc = new BigDecimalConverter(); - assertEquals(new BigDecimal(3000), bdc.convertToObject("3 000", Locale.FRENCH)); - - DoubleConverter dc = new DoubleConverter(); - assertEquals((double)3000, dc.convertToObject("3 000", Locale.FRENCH)); - - } - - /** - * @throws Exception - * WICKET-1344 public void testBigDecimalRounding() throws Exception { - * BigDecimalConverter bdc = new BigDecimalConverter(); assertEquals("123.45", - * bdc.convertToObject("123.45", Locale.ENGLISH).toString()); } - */ - - /** - * Test boolean conversions. - */ - public void testBooleanConversions() - { - BooleanConverter booleanConverter = new BooleanConverter(); - assertEquals("true", booleanConverter.convertToString(Boolean.TRUE, Locale.getDefault())); - assertEquals("false", booleanConverter.convertToString(Boolean.FALSE, Locale.getDefault())); - assertEquals(Boolean.TRUE, booleanConverter.convertToObject("true", Locale.getDefault())); - assertEquals(Boolean.FALSE, booleanConverter.convertToObject("false", Locale.getDefault())); - try - { - booleanConverter.convertToObject("whatever", Locale.getDefault()); - fail("Conversion should have thrown an exception"); - } - catch (ConversionException e) - { - // this is correct - } - } - - /** - * Test byte conversions. - */ - public void testByteConversions() - { - ByteConverter converter = new ByteConverter(); - assertEquals(new Byte((byte)10), converter.convertToObject("10", Locale.US)); - assertEquals("10", converter.convertToString((byte)10, Locale.US)); - try - { - converter.convertToObject("whatever", Locale.US); - fail("Conversion should have thrown an exception"); - } - catch (ConversionException e) - { - // This is correct - } - try - { - converter.convertToObject("10whatever", Locale.US); - fail("Conversion should have thrown an exception"); - } - catch (ConversionException e) - { - // This is correct - } - try - { - converter.convertToObject("256", Locale.US); - fail("Conversion should have thrown an exception"); - } - catch (ConversionException e) - { - // This is correct - } - } - - /** - * Test double conversions. - */ - public void testDoubleConversions() - { - DoubleConverter converter = new DoubleConverter(); - assertEquals(1.1, converter.convertToObject("1.1", Locale.US)); - assertEquals("1.1", converter.convertToString(1.1, Locale.US)); - try - { - converter.convertToObject("whatever", Locale.US); - fail("Conversion should have thrown an exception"); - } - catch (ConversionException e) - { - // this is correct - } - try - { - converter.convertToObject("1.1whatever", Locale.US); - fail("Conversion should have thrown an exception"); - } - catch (ConversionException e) - { - // this is correct - } - } - - /** - * Test float conversions. - */ - public void testFloatConversions() - { - FloatConverter converter = new FloatConverter(); - assertEquals(new Float(1.1), converter.convertToObject("1.1", Locale.US)); - assertEquals("1.1", converter.convertToString(new Float(1.1), Locale.US)); - try - { - converter.convertToObject("whatever", Locale.US); - fail("Conversion should have thrown an exception"); - } - catch (ConversionException e) - { - // this is correct - } - try - { - converter.convertToObject("1.1whatever", Locale.US); - fail("Conversion should have thrown an exception"); - } - catch (ConversionException e) - { - // this is correct - } - } - - /** - * Test integer conversions. - */ - public void testIntegerConversions() - { - IntegerConverter converter = new IntegerConverter(); - assertEquals(new Integer(10), converter.convertToObject("10", Locale.US)); - assertEquals("10", converter.convertToString(10, Locale.US)); - try - { - converter.convertToObject("whatever", Locale.US); - fail("Conversion should have thrown an exception"); - } - catch (ConversionException e) - { - // This is correct - } - try - { - converter.convertToObject("10whatever", Locale.US); - fail("Conversion should have thrown an exception"); - } - catch (ConversionException e) - { - // This is correct - } - try - { - converter.convertToObject("" + ((long)Integer.MAX_VALUE + 1), Locale.US); - fail("Conversion should have thrown an exception"); - } - catch (ConversionException e) - { - // This is correct - } - } - - /** - * Test long conversions. - */ - public void testLongConversions() - { - LongConverter converter = new LongConverter(); - assertEquals(new Long(10), converter.convertToObject("10", Locale.US)); - assertEquals("10", converter.convertToString((long)10, Locale.US)); - try - { - converter.convertToObject("whatever", Locale.US); - fail("Conversion should have thrown an exception"); - } - catch (ConversionException e) - { - // This is correct - } - try - { - converter.convertToObject("10whatever", Locale.US); - fail("Conversion should have thrown an exception"); - } - catch (ConversionException e) - { - // This is correct - } - try - { - converter.convertToObject("" + Long.MAX_VALUE + "0", Locale.US); - fail("Conversion should have thrown an exception"); - } - catch (ConversionException e) - { - // This is correct - } - } - - /** - * Test short conversions - */ - public void testShortConversions() - { - ShortConverter converter = new ShortConverter(); - assertEquals(new Short((short)10), converter.convertToObject("10", Locale.US)); - assertEquals("10", converter.convertToString((short)10, Locale.US)); - try - { - converter.convertToObject("whatever", Locale.US); - fail("Conversion should have thrown an exception"); - } - catch (ConversionException e) - { - // This is correct - } - try - { - converter.convertToObject("10whatever", Locale.US); - fail("Conversion should have thrown an exception"); - } - catch (ConversionException e) - { - // This is correct - } - try - { - converter.convertToObject("" + (Short.MAX_VALUE + 1), Locale.US); - fail("Conversion should have thrown an exception"); - } - catch (ConversionException e) - { - // This is correct - } - } - - /** - * Test date locale conversions. - */ - public void testDateConverter() - { - DateConverter converter = new DateConverter(); - - Calendar cal = Calendar.getInstance(DUTCH_LOCALE); - cal.clear(); - cal.set(2002, Calendar.OCTOBER, 24); - Date date = cal.getTime(); - - assertEquals("24-10-02", converter.convertToString(date, DUTCH_LOCALE)); - assertEquals(date, converter.convertToObject("24-10-02", DUTCH_LOCALE)); - - assertEquals("10/24/02", converter.convertToString(date, Locale.US)); - assertEquals(date, converter.convertToObject("10/24/02", Locale.US)); - - try - { - converter.convertToObject("whatever", Locale.US); - fail("Conversion should have thrown an exception"); - } - catch (ConversionException e) - { - // this is correct - } - try - { - converter.convertToObject("10/24/02whatever", Locale.US); - fail("Conversion should have thrown an exception"); - } - catch (ConversionException e) - { - // this is correct - } - } - - /** - * Test calendar locale conversions. - */ - public void testCalendarConverter() - { - CalendarConverter converter = new CalendarConverter(); - - Calendar cal = Calendar.getInstance(DUTCH_LOCALE); - cal.clear(); - cal.set(2011, Calendar.MAY, 1); - - assertEquals("1-5-11", converter.convertToString(cal, DUTCH_LOCALE)); - assertEquals(cal, converter.convertToObject("1-5-11", DUTCH_LOCALE)); - - cal = Calendar.getInstance(Locale.US); - cal.clear(); - cal.set(2011, Calendar.MAY, 1); - assertEquals("5/1/11", converter.convertToString(cal, Locale.US)); - assertEquals(cal, converter.convertToObject("5/1/11", Locale.US)); - - try - { - converter.convertToObject("whatever", Locale.US); - fail("Conversion should have thrown an exception"); - } - catch (ConversionException e) - { - // this is correct - } - try - { - converter.convertToObject("5/1/11whatever", Locale.US); - fail("Conversion should have thrown an exception"); - } - catch (ConversionException e) - { - // this is correct - } - } - - /** - * See WICKET-2878 and - * http://java.sun.com/j2se/1.4.2/docs/api/java/math/BigDecimal.html#BigDecimal%28double%29 - */ - public void testBigDecimalsDoubles() + public void test() { - BigDecimal bd = new BigDecimalConverter().convertToObject("0.1", Locale.US); - assertTrue(bd.doubleValue() == 0.1d); + final IConverterLocator locator = new ConverterLocator(); + assertNotNull(locator.getConverter(Integer.class)); + assertNotNull(locator.getConverter(Double.class)); - bd = new BigDecimalConverter().convertToObject("0,1", Locale.GERMAN); - assertTrue(bd.doubleValue() == 0.1d); + // default converter + assertNotNull(locator.getConverter(String.class).convertToObject("", Locale.US)); } } \ No newline at end of file Propchange: wicket/trunk/wicket-core/src/test/java/org/apache/wicket/ConverterLocatorTest.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: wicket/trunk/wicket-core/src/test/java/org/apache/wicket/ConverterLocatorTest.java ------------------------------------------------------------------------------ svn:keywords = Author Date Id Revision Modified: wicket/trunk/wicket-core/src/test/java/org/apache/wicket/util/io/SerializableCheckerTest.java URL: http://svn.apache.org/viewvc/wicket/trunk/wicket-core/src/test/java/org/apache/wicket/util/io/SerializableCheckerTest.java?rev=1144374&r1=1144373&r2=1144374&view=diff ============================================================================== --- wicket/trunk/wicket-core/src/test/java/org/apache/wicket/util/io/SerializableCheckerTest.java (original) +++ wicket/trunk/wicket-core/src/test/java/org/apache/wicket/util/io/SerializableCheckerTest.java Fri Jul 8 16:15:45 2011 @@ -27,6 +27,7 @@ import org.apache.log4j.LogManager; import org.apache.log4j.Logger; import org.apache.wicket.util.Log4jEventHistory; import org.apache.wicket.util.io.SerializableChecker.WicketNotSerializableException; +import org.apache.wicket.util.value.ValueMap; /** * @author Pedro Santos @@ -35,6 +36,17 @@ public class SerializableCheckerTest ext { /** + * Test {@link ValueMap} serializability. + * + * @throws IOException + */ + public void testValueMap() throws IOException + { + SerializableChecker checker = new SerializableChecker(new NotSerializableException()); + checker.writeObject(new ValueMap()); + } + + /** * Asserting an meaningful message get logged on console when serializable checker is testing * problematic {@link Object#equals(Object)} method implementations. * Copied: wicket/trunk/wicket-core/src/test/java/org/apache/wicket/util/lang/WicketObjectsTest.java (from r1143986, wicket/trunk/wicket-core/src/test/java/org/apache/wicket/util/lang/ObjectsTest.java) URL: http://svn.apache.org/viewvc/wicket/trunk/wicket-core/src/test/java/org/apache/wicket/util/lang/WicketObjectsTest.java?p2=wicket/trunk/wicket-core/src/test/java/org/apache/wicket/util/lang/WicketObjectsTest.java&p1=wicket/trunk/wicket-core/src/test/java/org/apache/wicket/util/lang/ObjectsTest.java&r1=1143986&r2=1144374&rev=1144374&view=diff ============================================================================== --- wicket/trunk/wicket-core/src/test/java/org/apache/wicket/util/lang/ObjectsTest.java (original) +++ wicket/trunk/wicket-core/src/test/java/org/apache/wicket/util/lang/WicketObjectsTest.java Fri Jul 8 16:15:45 2011 @@ -25,11 +25,11 @@ import org.apache.wicket.model.PropertyM /** - * Tests the Objects class. + * Tests the WicketObjects class. * * @author Martijn Dashorst */ -public class ObjectsTest extends WicketTestCase +public class WicketObjectsTest extends WicketTestCase { /** @@ -37,32 +37,12 @@ public class ObjectsTest extends WicketT * * @param name */ - public ObjectsTest(String name) + public WicketObjectsTest(String name) { super(name); } /** - * Test method for 'org.apache.wicket.util.lang.Objects.equal(Object, Object)' - */ - public void testEqual() - { - Object object = new Object(); - assertTrue(Objects.equal(object, object)); - - assertFalse(Objects.equal(null, object)); - assertFalse(Objects.equal(object, null)); - assertTrue(Objects.equal(null, null)); - - assertFalse(Objects.equal(new Object(), new Object())); - assertTrue(Objects.equal(1, 1)); - assertFalse(Objects.equal("1", 1)); - assertFalse(Objects.equal(1, "1")); - assertTrue(Objects.equal("1", Integer.toString(1))); - assertTrue(Objects.equal(Integer.toString(1), "1")); - } - - /** * Test method for 'org.apache.wicket.util.lang.Objects.clone(Object)' */ public void testCloneNull() Propchange: wicket/trunk/wicket-core/src/test/java/org/apache/wicket/util/lang/WicketObjectsTest.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: wicket/trunk/wicket-core/src/test/java/org/apache/wicket/util/lang/WicketObjectsTest.java ------------------------------------------------------------------------------ svn:keywords = Author Date Id Revision Added: wicket/trunk/wicket-util/src/test/java/org/apache/wicket/util/convert/converters/ConvertersTest.java URL: http://svn.apache.org/viewvc/wicket/trunk/wicket-util/src/test/java/org/apache/wicket/util/convert/converters/ConvertersTest.java?rev=1144374&view=auto ============================================================================== --- wicket/trunk/wicket-util/src/test/java/org/apache/wicket/util/convert/converters/ConvertersTest.java (added) +++ wicket/trunk/wicket-util/src/test/java/org/apache/wicket/util/convert/converters/ConvertersTest.java Fri Jul 8 16:15:45 2011 @@ -0,0 +1,436 @@ +/* + * 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.wicket.util.convert.converters; + +import java.math.BigDecimal; +import java.util.Calendar; +import java.util.Date; +import java.util.Locale; + +import junit.framework.TestCase; + +import org.apache.wicket.util.convert.ConversionException; +import org.apache.wicket.util.convert.converter.BigDecimalConverter; +import org.apache.wicket.util.convert.converter.BooleanConverter; +import org.apache.wicket.util.convert.converter.ByteConverter; +import org.apache.wicket.util.convert.converter.CalendarConverter; +import org.apache.wicket.util.convert.converter.CharacterConverter; +import org.apache.wicket.util.convert.converter.DateConverter; +import org.apache.wicket.util.convert.converter.DoubleConverter; +import org.apache.wicket.util.convert.converter.FloatConverter; +import org.apache.wicket.util.convert.converter.IntegerConverter; +import org.apache.wicket.util.convert.converter.LongConverter; +import org.apache.wicket.util.convert.converter.ShortConverter; + +/** + * Tests for the base converters. + * + * @author Eelco Hillenius + */ +public final class ConvertersTest extends TestCase +{ + /** Dutch locale for localized testing. */ + private static final Locale DUTCH_LOCALE = new Locale("nl", "NL"); + + /** + * Construct. + */ + public ConvertersTest() + { + super(); + } + + /** + * Construct. + * + * @param name + */ + public ConvertersTest(String name) + { + super(name); + } + + /** + * @throws Exception + */ + public void testThousandSeperator() throws Exception + { + BigDecimalConverter bdc = new BigDecimalConverter(); + assertEquals(new BigDecimal(3000), bdc.convertToObject("3 000", Locale.FRENCH)); + + DoubleConverter dc = new DoubleConverter(); + assertEquals((double)3000, dc.convertToObject("3 000", Locale.FRENCH)); + + } + + /** + * @throws Exception + * WICKET-1344 public void testBigDecimalRounding() throws Exception { + * BigDecimalConverter bdc = new BigDecimalConverter(); assertEquals("123.45", + * bdc.convertToObject("123.45", Locale.ENGLISH).toString()); } + */ + + /** + * Test boolean conversions. + */ + public void testBooleanConversions() + { + BooleanConverter converter = new BooleanConverter(); + assertEquals(Boolean.FALSE, converter.convertToObject("", Locale.US)); + assertEquals("true", converter.convertToString(Boolean.TRUE, Locale.getDefault())); + assertEquals("false", converter.convertToString(Boolean.FALSE, Locale.getDefault())); + assertEquals(Boolean.TRUE, converter.convertToObject("true", Locale.getDefault())); + assertEquals(Boolean.FALSE, converter.convertToObject("false", Locale.getDefault())); + try + { + converter.convertToObject("whatever", Locale.getDefault()); + fail("Conversion should have thrown an exception"); + } + catch (ConversionException e) + { + // this is correct + } + } + + /** + * Test byte conversions. + */ + public void testByteConversions() + { + ByteConverter converter = new ByteConverter(); + assertNull(converter.convertToObject("", Locale.US)); + assertEquals(new Byte((byte)10), converter.convertToObject("10", Locale.US)); + assertEquals("10", converter.convertToString((byte)10, Locale.US)); + try + { + converter.convertToObject("whatever", Locale.US); + fail("Conversion should have thrown an exception"); + } + catch (ConversionException e) + { + // This is correct + } + try + { + converter.convertToObject("10whatever", Locale.US); + fail("Conversion should have thrown an exception"); + } + catch (ConversionException e) + { + // This is correct + } + try + { + converter.convertToObject("256", Locale.US); + fail("Conversion should have thrown an exception"); + } + catch (ConversionException e) + { + // This is correct + } + } + + /** + * Test double conversions. + */ + public void testDoubleConversions() + { + DoubleConverter converter = new DoubleConverter(); + assertEquals("7.1", converter.convertToString(7.1, Locale.US)); + assertEquals("7,1", converter.convertToString(7.1, DUTCH_LOCALE)); + assertNull(converter.convertToObject("", Locale.US)); + assertEquals(1.1, converter.convertToObject("1.1", Locale.US)); + assertEquals("1.1", converter.convertToString(1.1, Locale.US)); + try + { + converter.convertToObject("whatever", Locale.US); + fail("Conversion should have thrown an exception"); + } + catch (ConversionException e) + { + // this is correct + } + try + { + converter.convertToObject("1.1whatever", Locale.US); + fail("Conversion should have thrown an exception"); + } + catch (ConversionException e) + { + // this is correct + } + } + + /** + * Test float conversions. + */ + public void testFloatConversions() + { + FloatConverter converter = new FloatConverter(); + assertNull(converter.convertToObject("", Locale.US)); + assertEquals(new Float(1.1), converter.convertToObject("1.1", Locale.US)); + assertEquals("1.1", converter.convertToString(new Float(1.1), Locale.US)); + try + { + converter.convertToObject("whatever", Locale.US); + fail("Conversion should have thrown an exception"); + } + catch (ConversionException e) + { + // this is correct + } + try + { + converter.convertToObject("1.1whatever", Locale.US); + fail("Conversion should have thrown an exception"); + } + catch (ConversionException e) + { + // this is correct + } + } + + /** + * Test integer conversions. + */ + public void testIntegerConversions() + { + IntegerConverter converter = new IntegerConverter(); + assertEquals("7", converter.convertToString(7, Locale.US)); + assertNull(converter.convertToObject("", Locale.US)); + assertEquals(new Integer(10), converter.convertToObject("10", Locale.US)); + assertEquals("10", converter.convertToString(10, Locale.US)); + try + { + converter.convertToObject("whatever", Locale.US); + fail("Conversion should have thrown an exception"); + } + catch (ConversionException e) + { + // This is correct + } + try + { + converter.convertToObject("10whatever", Locale.US); + fail("Conversion should have thrown an exception"); + } + catch (ConversionException e) + { + // This is correct + } + try + { + converter.convertToObject("" + ((long)Integer.MAX_VALUE + 1), Locale.US); + fail("Conversion should have thrown an exception"); + } + catch (ConversionException e) + { + // This is correct + } + } + + /** + * Test long conversions. + */ + public void testLongConversions() + { + LongConverter converter = new LongConverter(); + assertNull(converter.convertToObject("", Locale.US)); + assertEquals(new Long(10), converter.convertToObject("10", Locale.US)); + assertEquals("10", converter.convertToString((long)10, Locale.US)); + try + { + converter.convertToObject("whatever", Locale.US); + fail("Conversion should have thrown an exception"); + } + catch (ConversionException e) + { + // This is correct + } + try + { + converter.convertToObject("10whatever", Locale.US); + fail("Conversion should have thrown an exception"); + } + catch (ConversionException e) + { + // This is correct + } + try + { + converter.convertToObject("" + Long.MAX_VALUE + "0", Locale.US); + fail("Conversion should have thrown an exception"); + } + catch (ConversionException e) + { + // This is correct + } + } + + /** + * Test short conversions + */ + public void testShortConversions() + { + ShortConverter converter = new ShortConverter(); + assertNull(converter.convertToObject("", Locale.US)); + assertEquals(new Short((short)10), converter.convertToObject("10", Locale.US)); + assertEquals("10", converter.convertToString((short)10, Locale.US)); + try + { + converter.convertToObject("whatever", Locale.US); + fail("Conversion should have thrown an exception"); + } + catch (ConversionException e) + { + // This is correct + } + try + { + converter.convertToObject("10whatever", Locale.US); + fail("Conversion should have thrown an exception"); + } + catch (ConversionException e) + { + // This is correct + } + try + { + converter.convertToObject("" + (Short.MAX_VALUE + 1), Locale.US); + fail("Conversion should have thrown an exception"); + } + catch (ConversionException e) + { + // This is correct + } + } + + /** + * Test for character locale conversions. + */ + public void testCharacterConverter() + { + CharacterConverter converter = new CharacterConverter(); + + assertNull(converter.convertToObject("", Locale.US)); + assertEquals("A", converter.convertToString('A', DUTCH_LOCALE)); + assertEquals((Object)'A', converter.convertToObject("A", DUTCH_LOCALE)); + + try + { + converter.convertToObject("AA", Locale.US); + fail("Conversion should have thrown an exception"); + } + catch (ConversionException e) + { + // this is correct + } + } + + /** + * Test date locale conversions. + */ + public void testDateConverter() + { + DateConverter converter = new DateConverter(); + + assertNull(new DateConverter().convertToObject("", Locale.US)); + + Calendar cal = Calendar.getInstance(DUTCH_LOCALE); + cal.clear(); + cal.set(2002, Calendar.OCTOBER, 24); + Date date = cal.getTime(); + + assertEquals("24-10-02", converter.convertToString(date, DUTCH_LOCALE)); + assertEquals(date, converter.convertToObject("24-10-02", DUTCH_LOCALE)); + + assertEquals("10/24/02", converter.convertToString(date, Locale.US)); + assertEquals(date, converter.convertToObject("10/24/02", Locale.US)); + + try + { + converter.convertToObject("whatever", Locale.US); + fail("Conversion should have thrown an exception"); + } + catch (ConversionException e) + { + // this is correct + } + try + { + converter.convertToObject("10/24/02whatever", Locale.US); + fail("Conversion should have thrown an exception"); + } + catch (ConversionException e) + { + // this is correct + } + } + + /** + * Test calendar locale conversions. + */ + public void testCalendarConverter() + { + CalendarConverter converter = new CalendarConverter(); + + Calendar cal = Calendar.getInstance(DUTCH_LOCALE); + cal.clear(); + cal.set(2011, Calendar.MAY, 1); + + assertEquals("1-5-11", converter.convertToString(cal, DUTCH_LOCALE)); + assertEquals(cal, converter.convertToObject("1-5-11", DUTCH_LOCALE)); + + cal = Calendar.getInstance(Locale.US); + cal.clear(); + cal.set(2011, Calendar.MAY, 1); + assertEquals("5/1/11", converter.convertToString(cal, Locale.US)); + assertEquals(cal, converter.convertToObject("5/1/11", Locale.US)); + + try + { + converter.convertToObject("whatever", Locale.US); + fail("Conversion should have thrown an exception"); + } + catch (ConversionException e) + { + // this is correct + } + try + { + converter.convertToObject("5/1/11whatever", Locale.US); + fail("Conversion should have thrown an exception"); + } + catch (ConversionException e) + { + // this is correct + } + } + + /** + * See WICKET-2878 and + * http://java.sun.com/j2se/1.4.2/docs/api/java/math/BigDecimal.html#BigDecimal%28double%29 + */ + public void testBigDecimalsDoubles() + { + BigDecimal bd = new BigDecimalConverter().convertToObject("0.1", Locale.US); + assertTrue(bd.doubleValue() == 0.1d); + + bd = new BigDecimalConverter().convertToObject("0,1", Locale.GERMAN); + assertTrue(bd.doubleValue() == 0.1d); + } +} \ No newline at end of file Propchange: wicket/trunk/wicket-util/src/test/java/org/apache/wicket/util/convert/converters/ConvertersTest.java ------------------------------------------------------------------------------ svn:mime-type = text/plain Modified: wicket/trunk/wicket-util/src/test/java/org/apache/wicket/util/crypt/Base64Test.java URL: http://svn.apache.org/viewvc/wicket/trunk/wicket-util/src/test/java/org/apache/wicket/util/crypt/Base64Test.java?rev=1144374&r1=1143986&r2=1144374&view=diff ============================================================================== --- wicket/trunk/wicket-util/src/test/java/org/apache/wicket/util/crypt/Base64Test.java (original) +++ wicket/trunk/wicket-util/src/test/java/org/apache/wicket/util/crypt/Base64Test.java Fri Jul 8 16:15:45 2011 @@ -22,9 +22,6 @@ import java.util.Random; import junit.framework.TestCase; -import org.apache.wicket.settings.ISecuritySettings; -import org.apache.wicket.util.tester.WicketTester; - /** * * @author Juergen Donnerstag @@ -137,7 +134,7 @@ public class Base64Test extends TestCase public void test_3() throws IOException { String input = "wicket:interface=:2:entityTree:node:node:0:node:nodeLink::IBehaviorListener"; - ICrypt crypt = new CachingSunJceCryptFactory(ISecuritySettings.DEFAULT_ENCRYPTION_KEY).newCrypt(); + ICrypt crypt = new CachingSunJceCryptFactory("WiCkEt-FRAMEwork").newCrypt(); String s = crypt.encryptUrlSafe(input); String output = crypt.decryptUrlSafe(s); @@ -237,19 +234,6 @@ public class Base64Test extends TestCase /** * @throws IOException */ - public void test_UrlSafe_3() throws IOException - { - String input = "wicket:interface=:2:entityTree:node:node:0:node:nodeLink::IBehaviorListener"; - ICrypt crypt = new CachingSunJceCryptFactory(ISecuritySettings.DEFAULT_ENCRYPTION_KEY).newCrypt(); - String s = crypt.encryptUrlSafe(input); - - String output = crypt.decryptUrlSafe(s); - assertEquals(input, output); - } - - /** - * @throws IOException - */ public void test_4() throws IOException { String input = "wicket-sep-wicket"; @@ -269,8 +253,7 @@ public class Base64Test extends TestCase */ public void test_5() throws IOException { - WicketTester tester = new WicketTester(); - ICrypt crypt = tester.getApplication().getSecuritySettings().getCryptFactory().newCrypt(); + ICrypt crypt = new CachingSunJceCryptFactory("WiCkEt-FRAMEwork").newCrypt(); String input = "wicket-sep-wicket"; for (int i = input.length(); i >= 0; i--) @@ -281,7 +264,5 @@ public class Base64Test extends TestCase String output = crypt.decryptUrlSafe(encrypted); assertEquals(in, output); } - - tester.destroy(); } } Added: wicket/trunk/wicket-util/src/test/java/org/apache/wicket/util/lang/ObjectsTest.java URL: http://svn.apache.org/viewvc/wicket/trunk/wicket-util/src/test/java/org/apache/wicket/util/lang/ObjectsTest.java?rev=1144374&view=auto ============================================================================== --- wicket/trunk/wicket-util/src/test/java/org/apache/wicket/util/lang/ObjectsTest.java (added) +++ wicket/trunk/wicket-util/src/test/java/org/apache/wicket/util/lang/ObjectsTest.java Fri Jul 8 16:15:45 2011 @@ -0,0 +1,59 @@ +/* + * 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.wicket.util.lang; + +import junit.framework.TestCase; + + +/** + * Tests the Objects class. + * + * @author Martijn Dashorst + */ +public class ObjectsTest extends TestCase +{ + + /** + * Construct. + * + * @param name + */ + public ObjectsTest(String name) + { + super(name); + } + + /** + * Test method for 'org.apache.wicket.util.lang.Objects.equal(Object, Object)' + */ + public void testEqual() + { + Object object = new Object(); + assertTrue(Objects.equal(object, object)); + + assertFalse(Objects.equal(null, object)); + assertFalse(Objects.equal(object, null)); + assertTrue(Objects.equal(null, null)); + + assertFalse(Objects.equal(new Object(), new Object())); + assertTrue(Objects.equal(1, 1)); + assertFalse(Objects.equal("1", 1)); + assertFalse(Objects.equal(1, "1")); + assertTrue(Objects.equal("1", Integer.toString(1))); + assertTrue(Objects.equal(Integer.toString(1), "1")); + } +} Propchange: wicket/trunk/wicket-util/src/test/java/org/apache/wicket/util/lang/ObjectsTest.java ------------------------------------------------------------------------------ svn:mime-type = text/plain Modified: wicket/trunk/wicket-util/src/test/java/org/apache/wicket/util/parse/metapattern/MetaPatternTest.java URL: http://svn.apache.org/viewvc/wicket/trunk/wicket-util/src/test/java/org/apache/wicket/util/parse/metapattern/MetaPatternTest.java?rev=1144374&r1=1143986&r2=1144374&view=diff ============================================================================== --- wicket/trunk/wicket-util/src/test/java/org/apache/wicket/util/parse/metapattern/MetaPatternTest.java (original) +++ wicket/trunk/wicket-util/src/test/java/org/apache/wicket/util/parse/metapattern/MetaPatternTest.java Fri Jul 8 16:15:45 2011 @@ -41,10 +41,9 @@ public final class MetaPatternTest exten // Parse "variable = <number>" final Group variable = new Group(MetaPattern.VARIABLE_NAME); final IntegerGroup value = new IntegerGroup(MetaPattern.INTEGER); - final MetaPattern variableAssignment = new MetaPattern( - variable, - MetaPattern.OPTIONAL_WHITESPACE, MetaPattern.EQUALS, - MetaPattern.OPTIONAL_WHITESPACE, value); + final MetaPattern variableAssignment = new MetaPattern(variable, + MetaPattern.OPTIONAL_WHITESPACE, MetaPattern.EQUALS, MetaPattern.OPTIONAL_WHITESPACE, + value); final Matcher matcher = variableAssignment.matcher("foo = 9"); assertTrue(matcher.matches()); @@ -162,4 +161,4 @@ public final class MetaPatternTest exten parser = new TagNameParser(tag); assertEquals(false, parser.matcher().matches()); } -} +} \ No newline at end of file Modified: wicket/trunk/wicket-util/src/test/java/org/apache/wicket/util/size/BytesTest.java URL: http://svn.apache.org/viewvc/wicket/trunk/wicket-util/src/test/java/org/apache/wicket/util/size/BytesTest.java?rev=1144374&r1=1143986&r2=1144374&view=diff ============================================================================== --- wicket/trunk/wicket-util/src/test/java/org/apache/wicket/util/size/BytesTest.java (original) +++ wicket/trunk/wicket-util/src/test/java/org/apache/wicket/util/size/BytesTest.java Fri Jul 8 16:15:45 2011 @@ -65,6 +65,7 @@ public final class BytesTest extends Tes Assert.assertTrue(Bytes.bytes(1024 * 1024).equals(Bytes.megabytes(1))); Assert.assertTrue("1G".equals(Bytes.gigabytes(1).toString())); + final Bytes b = Bytes.kilobytes(7.3); Assert.assertTrue(b.equals(Bytes.kilobytes(7.3))); Modified: wicket/trunk/wicket-util/src/test/java/org/apache/wicket/util/string/interpolator/VariableInterpolatorTest.java URL: http://svn.apache.org/viewvc/wicket/trunk/wicket-util/src/test/java/org/apache/wicket/util/string/interpolator/VariableInterpolatorTest.java?rev=1144374&r1=1143986&r2=1144374&view=diff ============================================================================== --- wicket/trunk/wicket-util/src/test/java/org/apache/wicket/util/string/interpolator/VariableInterpolatorTest.java (original) +++ wicket/trunk/wicket-util/src/test/java/org/apache/wicket/util/string/interpolator/VariableInterpolatorTest.java Fri Jul 8 16:15:45 2011 @@ -77,4 +77,4 @@ public class VariableInterpolatorTest ex MapVariableInterpolator in = new MapVariableInterpolator("aaa $${key} bbb", params); assertEquals("aaa ${key} bbb", in.toString()); } -} +} \ No newline at end of file Copied: wicket/trunk/wicket-util/src/test/java/org/apache/wicket/util/value/ValueMapTest.java (from r1143986, wicket/trunk/wicket-core/src/test/java/org/apache/wicket/util/value/ValueMapTest.java) URL: http://svn.apache.org/viewvc/wicket/trunk/wicket-util/src/test/java/org/apache/wicket/util/value/ValueMapTest.java?p2=wicket/trunk/wicket-util/src/test/java/org/apache/wicket/util/value/ValueMapTest.java&p1=wicket/trunk/wicket-core/src/test/java/org/apache/wicket/util/value/ValueMapTest.java&r1=1143986&r2=1144374&rev=1144374&view=diff ============================================================================== --- wicket/trunk/wicket-core/src/test/java/org/apache/wicket/util/value/ValueMapTest.java (original) +++ wicket/trunk/wicket-util/src/test/java/org/apache/wicket/util/value/ValueMapTest.java Fri Jul 8 16:15:45 2011 @@ -16,11 +16,8 @@ */ package org.apache.wicket.util.value; -import java.io.NotSerializableException; - import junit.framework.TestCase; -import org.apache.wicket.util.io.SerializableChecker; import org.apache.wicket.util.time.Duration; import org.apache.wicket.util.time.Time; @@ -242,17 +239,6 @@ public class ValueMapTest extends TestCa } /** - * Make sure that ValueMap is serializable. - * - * @throws Exception - */ - public void testSerializable() throws Exception - { - SerializableChecker checker = new SerializableChecker(new NotSerializableException()); - checker.writeObject(new ValueMap()); - } - - /** * */ public void testArray2()