From: <gca...@us...> - 2010-06-11 14:39:28
|
Revision: 2647 http://openutils.svn.sourceforge.net/openutils/?rev=2647&view=rev Author: gcatania Date: 2010-06-11 14:39:22 +0000 (Fri, 11 Jun 2010) Log Message: ----------- TEST-1 cleanup, added tests for dateAssert Modified Paths: -------------- trunk/openutils-testing/src/main/java/it/openutils/testing/DateAssert.java trunk/openutils-testing/src/main/java/it/openutils/testing/DbUnitExecution.java trunk/openutils-testing/src/main/java/it/openutils/testing/DbUnitTestContext.java trunk/openutils-testing/src/main/java/it/openutils/testing/TestUtils.java trunk/openutils-testing/src/main/java/it/openutils/testing/collections/CollectionAssert.java trunk/openutils-testing/src/main/java/it/openutils/testing/collections/MapAssert.java Added Paths: ----------- trunk/openutils-testing/src/test/java/it/openutils/testing/DateAssertTest.java Modified: trunk/openutils-testing/src/main/java/it/openutils/testing/DateAssert.java =================================================================== --- trunk/openutils-testing/src/main/java/it/openutils/testing/DateAssert.java 2010-06-11 08:00:38 UTC (rev 2646) +++ trunk/openutils-testing/src/main/java/it/openutils/testing/DateAssert.java 2010-06-11 14:39:22 UTC (rev 2647) @@ -139,4 +139,37 @@ performComparison(expectedDateAsString, date.getTime(), dtf); } + /** + * Asserts that either two dates are null or the comparison between them is zero. + * @param expectedDate the expected date. + * @param actualDate the actual date + */ + public static void assertEquals(Date expectedDate, Date actualDate) + { + if (expectedDate == null) + { + if (actualDate == null) + { + return; + } + } + else if (actualDate != null && actualDate.compareTo(expectedDate) == 0) + { + return; + } + throw new AssertionError("Expected <" + expectedDate + ">, found <" + actualDate + ">"); + } + + /** + * Asserts that either two calendars are null or the comparison between them is zero. + * @param expectedDate the expected date. + * @param actualDate the actual date. + */ + public static void assertEquals(Calendar expectedDate, Calendar actualDate) + { + Date expected = expectedDate != null ? expectedDate.getTime() : null; + Date actual = actualDate != null ? actualDate.getTime() : null; + assertEquals(expected, actual); + } + } Modified: trunk/openutils-testing/src/main/java/it/openutils/testing/DbUnitExecution.java =================================================================== --- trunk/openutils-testing/src/main/java/it/openutils/testing/DbUnitExecution.java 2010-06-11 08:00:38 UTC (rev 2646) +++ trunk/openutils-testing/src/main/java/it/openutils/testing/DbUnitExecution.java 2010-06-11 14:39:22 UTC (rev 2647) @@ -105,11 +105,11 @@ * A list of dbunit features that should be enabled or disabled on the connection. See * http://www.dbunit.org/properties.html. */ - DbUnitFeature[] features() default {}; + DbUnitFeature[] features() default { }; /** * A list of dbunit properties that should be set on the connection. See http://www.dbunit.org/properties.html. */ - DbUnitProperty[] properties() default {}; + DbUnitProperty[] properties() default { }; } \ No newline at end of file Modified: trunk/openutils-testing/src/main/java/it/openutils/testing/DbUnitTestContext.java =================================================================== --- trunk/openutils-testing/src/main/java/it/openutils/testing/DbUnitTestContext.java 2010-06-11 08:00:38 UTC (rev 2646) +++ trunk/openutils-testing/src/main/java/it/openutils/testing/DbUnitTestContext.java 2010-06-11 14:39:22 UTC (rev 2647) @@ -411,7 +411,6 @@ * @param name datasource name. * @return Datasource instance */ - @SuppressWarnings("unchecked") protected DataSource getDatasource(String name) { if (StringUtils.isEmpty(name)) Modified: trunk/openutils-testing/src/main/java/it/openutils/testing/TestUtils.java =================================================================== --- trunk/openutils-testing/src/main/java/it/openutils/testing/TestUtils.java 2010-06-11 08:00:38 UTC (rev 2646) +++ trunk/openutils-testing/src/main/java/it/openutils/testing/TestUtils.java 2010-06-11 14:39:22 UTC (rev 2647) @@ -25,16 +25,18 @@ package it.openutils.testing; -import java.util.ArrayList; -import java.util.HashSet; +import it.openutils.testing.collections.CollectionBuilder; + import java.util.List; import java.util.Set; /** + * @deprecated in favor of {@link CollectionBuilder} * @author fgiust * @version $Id$ */ +@Deprecated public final class TestUtils { @@ -50,12 +52,7 @@ */ public static <T> Set<T> setWith(T... elements) { - Set<T> newSet = new HashSet<T>(elements.length); - for (T element : elements) - { - newSet.add(element); - } - return newSet; + return CollectionBuilder.s(elements); } /** @@ -66,11 +63,6 @@ */ public static <T> List<T> listWith(T... elements) { - List<T> newList = new ArrayList<T>(elements.length); - for (T element : elements) - { - newList.add(element); - } - return newList; + return CollectionBuilder.l(elements); } } Modified: trunk/openutils-testing/src/main/java/it/openutils/testing/collections/CollectionAssert.java =================================================================== --- trunk/openutils-testing/src/main/java/it/openutils/testing/collections/CollectionAssert.java 2010-06-11 08:00:38 UTC (rev 2646) +++ trunk/openutils-testing/src/main/java/it/openutils/testing/collections/CollectionAssert.java 2010-06-11 14:39:22 UTC (rev 2647) @@ -87,7 +87,6 @@ /** * Asserts that a collection is not null * @param c the collection - * @param message a custom error message * @throws AssertionError if assertion fails */ public static void assertNotNull(Collection< ? > c) throws AssertionError Modified: trunk/openutils-testing/src/main/java/it/openutils/testing/collections/MapAssert.java =================================================================== --- trunk/openutils-testing/src/main/java/it/openutils/testing/collections/MapAssert.java 2010-06-11 08:00:38 UTC (rev 2646) +++ trunk/openutils-testing/src/main/java/it/openutils/testing/collections/MapAssert.java 2010-06-11 14:39:22 UTC (rev 2647) @@ -83,7 +83,6 @@ /** * Asserts that a map is not null * @param m the map - * @param message a custom error message * @throws AssertionError if assertion fails */ public static void assertNotNull(Map< ? , ? > m) throws AssertionError Added: trunk/openutils-testing/src/test/java/it/openutils/testing/DateAssertTest.java =================================================================== --- trunk/openutils-testing/src/test/java/it/openutils/testing/DateAssertTest.java (rev 0) +++ trunk/openutils-testing/src/test/java/it/openutils/testing/DateAssertTest.java 2010-06-11 14:39:22 UTC (rev 2647) @@ -0,0 +1,76 @@ +/** + * + * Openutils testing library (http://www.openmindlab.com/products/testing.html) + * + * Copyright(C) 2005-2010, Openmind S.r.l. http://www.openmindonline.it + * + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * You may obtain a copy of the License at + * + * http://www.gnu.org/licenses/lgpl-2.1.html + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +package it.openutils.testing; + +import java.util.Calendar; +import java.util.GregorianCalendar; + +import org.testng.annotations.Test; + + +/** + * @author gcatania + */ +public class DateAssertTest +{ + + @Test + public void testAssertSuccess() + { + DateAssert.assertEquals((Calendar) null, (Calendar) null); + Calendar c1 = new GregorianCalendar(2010, 3, 4, 5, 6, 8); + Calendar c2 = new GregorianCalendar(2010, 3, 4, 5, 6, 8); + DateAssert.assertEquals(c1, c2); + c1.setLenient(true); + c2.setLenient(false); + DateAssert.assertEquals(c1, c2); + c1.setFirstDayOfWeek(3); + c1.setFirstDayOfWeek(4); + DateAssert.assertEquals(c1, c2); + } + + @Test(expectedExceptions = AssertionError.class) + public void testAssertFailsForNullActual() + { + DateAssert.assertEquals(Calendar.getInstance(), null); + } + + @Test(expectedExceptions = AssertionError.class) + public void testAssertFailsForNullExpected() + { + DateAssert.assertEquals(null, Calendar.getInstance()); + } + + @Test(expectedExceptions = AssertionError.class) + public void testAssertFailsForDifferent() + { + Calendar c1 = new GregorianCalendar(2010, 3, 4, 5, 6, 8); + Calendar c2 = new GregorianCalendar(2010, 3, 4, 5, 6, 8); + c2.set(Calendar.MILLISECOND, 3); + DateAssert.assertEquals(c1, c2); + } + +} Property changes on: trunk/openutils-testing/src/test/java/it/openutils/testing/DateAssertTest.java ___________________________________________________________________ Added: svn:mime-type + text/plain Added: svn:keywords + Author Date Id Revision Added: svn:eol-style + native This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |