From: <fg...@us...> - 2008-02-17 09:03:02
|
Revision: 618 http://openutils.svn.sourceforge.net/openutils/?rev=618&view=rev Author: fgiust Date: 2008-02-17 01:03:04 -0800 (Sun, 17 Feb 2008) Log Message: ----------- minor improvements to DateAssert Modified Paths: -------------- trunk/openutils-testing/src/main/java/it/openutils/testing/DateAssert.java trunk/openutils-testing/src/site/changes/changes.xml Modified: trunk/openutils-testing/src/main/java/it/openutils/testing/DateAssert.java =================================================================== --- trunk/openutils-testing/src/main/java/it/openutils/testing/DateAssert.java 2008-02-14 16:06:03 UTC (rev 617) +++ trunk/openutils-testing/src/main/java/it/openutils/testing/DateAssert.java 2008-02-17 09:03:04 UTC (rev 618) @@ -43,18 +43,22 @@ } /** - * Asserts that two dates are equal. - * @param expectedDateAsString date formatted as "YYYYMMDD" - * @param date actual date - * @throws IllegalArgumentException if <code>expectedDateAsString</code> is not a valid date format + * @param expectedDateAsString + * @param date + * @param format + * @throws AssertionError */ - public static void dateEqual(String expectedDateAsString, Calendar date) throws IllegalArgumentException + private static void performComparison(String expectedDateAsString, Date date, DateFormat format) + throws AssertionError { Date expected; try { - expected = df.parse(expectedDateAsString); + synchronized (format) + { + expected = format.parse(expectedDateAsString); + } } catch (ParseException e) { @@ -65,40 +69,51 @@ { throw new AssertionError("Date is null"); } - if (!date.getTime().equals(expected)) + if (!date.equals(expected)) { - throw new AssertionError("Expected <" + expected + ">, actual <" + date.getTime() + ">"); + synchronized (format) + { + throw new AssertionError("Expected <" + + format.format(expected) + + ">, actual <" + + format.format(date) + + ">"); + } } } /** * Asserts that two dates are equal. + * @param expectedDateAsString date formatted as "YYYYMMDD" + * @param date actual date + * @throws IllegalArgumentException if <code>expectedDateAsString</code> is not a valid date format + */ + public static void dateEqual(String expectedDateAsString, Calendar date) throws IllegalArgumentException + { + performComparison(expectedDateAsString, date.getTime(), df); + } + + /** + * Asserts that two dates are equal. + * @param expectedDateAsString date formatted as "YYYYMMDD" + * @param date actual date + * @throws IllegalArgumentException if <code>expectedDateAsString</code> is not a valid date format + */ + public static void dateEqual(String expectedDateAsString, Date date) throws IllegalArgumentException + { + performComparison(expectedDateAsString, date, df); + } + + /** + * Asserts that two dates are equal. * @param expectedDateAsString date formatted as "yyyyMMdd HH:mm" * @param date actual date * @throws IllegalArgumentException if <code>expectedDateAsString</code> is not a valid date format */ public static void dateTimeEqual(String expectedDateAsString, Date date) throws IllegalArgumentException { - Date expected; - try - { - expected = dtf.parse(expectedDateAsString); - } - catch (ParseException e) - { - throw new IllegalArgumentException("Unparseable date String: [" + expectedDateAsString + "]"); - } - - if (date == null) - { - throw new AssertionError("Date is null"); - } - - if (date.getTime() != expected.getTime()) - { - throw new AssertionError("Expected <" + expected + ">, actual <" + date + ">"); - } + performComparison(expectedDateAsString, date, dtf); } /** Modified: trunk/openutils-testing/src/site/changes/changes.xml =================================================================== --- trunk/openutils-testing/src/site/changes/changes.xml 2008-02-14 16:06:03 UTC (rev 617) +++ trunk/openutils-testing/src/site/changes/changes.xml 2008-02-17 09:03:04 UTC (rev 618) @@ -8,7 +8,12 @@ <author email="fgiust(at)users.sourceforge.net">Fabrizio Giustina</author> </properties> <body> - <release version="2.0.2" date="in svn" description="2.0.2"> + <release version="2.0.3" date="in svn" description="2.0.2"> + <action type="update" dev="fgiust"> + it.openutils.testing.DateAssert is now thread safe. Failure messages have been improved. + </action> + </release> + <release version="2.0.2" date="2008-01-31" description="2.0.2"> <action type="add" dev="fgiust"> New dbunit operation classes for mssql and mysql (extension of standard dbunit operation, but refactored so that they can be used in annotations). See the javadocs in the it.openutils.testing.dbunit package This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |