Revision: 5926
http://squirrel-sql.svn.sourceforge.net/squirrel-sql/?rev=5926&view=rev
Author: manningr
Date: 2010-10-17 19:19:21 +0000 (Sun, 17 Oct 2010)
Log Message:
-----------
Combined the two test case classes into one with different test methods. Now, the private static propertiesAlreadyLoaded flag is reset in the tests requiring different configuration of DTProperties. Since all tests run within the same JVM from the command-line in Maven, this was causing certain tests to fail when run together. Now these tests run fine together in the same JVM.
Modified Paths:
--------------
trunk/sql12/fw/src/test/java/net/sourceforge/squirrel_sql/fw/datasetviewer/cellcomponent/DataTypeDateTest.java
Removed Paths:
-------------
trunk/sql12/fw/src/test/java/net/sourceforge/squirrel_sql/fw/datasetviewer/cellcomponent/DataTypeDateWithCustomDateFormatTest.java
Modified: trunk/sql12/fw/src/test/java/net/sourceforge/squirrel_sql/fw/datasetviewer/cellcomponent/DataTypeDateTest.java
===================================================================
--- trunk/sql12/fw/src/test/java/net/sourceforge/squirrel_sql/fw/datasetviewer/cellcomponent/DataTypeDateTest.java 2010-10-17 17:10:15 UTC (rev 5925)
+++ trunk/sql12/fw/src/test/java/net/sourceforge/squirrel_sql/fw/datasetviewer/cellcomponent/DataTypeDateTest.java 2010-10-17 19:19:21 UTC (rev 5926)
@@ -1,12 +1,13 @@
package net.sourceforge.squirrel_sql.fw.datasetviewer.cellcomponent;
-import static org.junit.Assert.*;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+import java.lang.reflect.Field;
import java.sql.Date;
+import java.text.DateFormat;
-import javax.swing.JTextArea;
-import javax.swing.JTextField;
-
import net.sourceforge.squirrel_sql.fw.datasetviewer.ColumnDisplayDefinition;
import org.junit.Before;
@@ -38,6 +39,7 @@
*/
public class DataTypeDateTest extends AbstractDataTypeComponentTest
{
+ private static int userDefinedDateFormat = DateFormat.MEDIUM;
@Before
public void setUp() throws Exception
@@ -54,25 +56,42 @@
@Test
public void testGetReadDateAsTimestamp()
{
+ DTProperties.put(DataTypeDate.class.getName(), "readDateAsTimestamp", "false");
assertFalse("Expected default value to be false for read date as timestamp",
DataTypeDate.getReadDateAsTimestamp());
+
+ DTProperties.put(DataTypeDate.class.getName(), "readDateAsTimestamp", "true");
+ assertTrue("Expected the user specified value", DataTypeDate.getReadDateAsTimestamp());
}
-
-
+
/**
- * Ensure, that the Bug 3086444 is solved.
- * If the user didn't choose a custom DateFormat, then we must use the default.
+ * Ensure, that the Bug 3086444 is solved. If the user didn't choose a custom DateFormat, then we must use
+ * the default.
*/
@Test
- public void testUseCustomDateFormatAfterLoadingProperties()
+ public void testUseDefaultDateFormatAfterLoadingProperties() throws Exception
{
-
- Date currentDate = Date.valueOf("2010-10-15");
-
-
+ resetPropertiesLoadedFlag();
+ DTProperties.put(DataTypeDate.class.getName(), "useJavaDefaultFormat", "true");
+ classUnderTest = new DataTypeDate(null, getMockColumnDisplayDefinition());
+ Date currentDate = Date.valueOf("2010-10-15");
String renderedDate = classUnderTest.renderObject(currentDate);
assertEquals("Must use the default format", "2010-10-15", renderedDate);
+ }
+
+ @Test
+ public void testUseCustomDateFormatAfterLoadingProperties() throws Exception
+ {
+ resetPropertiesLoadedFlag();
+ DTProperties.put(DataTypeDate.class.getName(), "useJavaDefaultFormat", "false");
+ DTProperties.put(DataTypeDate.class.getName(), "localeFormat", "" + DateFormat.MEDIUM);
+ DTProperties.put(DataTypeDate.class.getName(), "lenient", "false");
+ classUnderTest = new DataTypeDate(null, getMockColumnDisplayDefinition());
+ Date currentDate = Date.valueOf("2010-10-15");
+ String expectedDate = DateFormat.getDateInstance(userDefinedDateFormat).format(currentDate);
+ String renderedDate = classUnderTest.renderObject(currentDate);
+ assertEquals("Must use the user defined format", expectedDate, renderedDate);
}
@Override
@@ -80,5 +99,11 @@
{
return new Date(System.currentTimeMillis());
}
+
+ private void resetPropertiesLoadedFlag() throws Exception {
+ Field field = DataTypeDate.class.getDeclaredField("propertiesAlreadyLoaded");
+ field.setAccessible(true);
+ field.set(null, false);
+ }
}
Deleted: trunk/sql12/fw/src/test/java/net/sourceforge/squirrel_sql/fw/datasetviewer/cellcomponent/DataTypeDateWithCustomDateFormatTest.java
===================================================================
--- trunk/sql12/fw/src/test/java/net/sourceforge/squirrel_sql/fw/datasetviewer/cellcomponent/DataTypeDateWithCustomDateFormatTest.java 2010-10-17 17:10:15 UTC (rev 5925)
+++ trunk/sql12/fw/src/test/java/net/sourceforge/squirrel_sql/fw/datasetviewer/cellcomponent/DataTypeDateWithCustomDateFormatTest.java 2010-10-17 19:19:21 UTC (rev 5926)
@@ -1,99 +0,0 @@
-package net.sourceforge.squirrel_sql.fw.datasetviewer.cellcomponent;
-
-import static org.junit.Assert.*;
-
-import java.sql.Date;
-import java.text.DateFormat;
-
-import javax.swing.JTextArea;
-import javax.swing.JTextField;
-
-import net.sourceforge.squirrel_sql.fw.datasetviewer.ColumnDisplayDefinition;
-
-import org.junit.Before;
-import org.junit.Test;
-
-/*
- *
- * 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.
- *
- * 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-
-/**
- * JUnit test for DataTypeDate class when using custom properties.
- *
- * @author Stefan Willinger
- */
-public class DataTypeDateWithCustomDateFormatTest extends AbstractDataTypeComponentTest
-{
-
- private static int userDefinedDateFormat = DateFormat.MEDIUM;
-
- /**
- * Setup the test case with user defined properties
- * @see net.sourceforge.squirrel_sql.fw.datasetviewer.cellcomponent.AbstractDataTypeComponentTest#setUp()
- */
- @Before
- public void setUp() throws Exception
- {
- DTProperties.put(DataTypeDate.class.getName(), "useJavaDefaultFormat", "false");
- DTProperties.put(DataTypeDate.class.getName(), "localeFormat", ""+DateFormat.MEDIUM);
- DTProperties.put(DataTypeDate.class.getName(), "lenient", "false");
- DTProperties.put(DataTypeDate.class.getName(), "readDateAsTimestamp", "true");
-
-
- ColumnDisplayDefinition columnDisplayDefinition = getMockColumnDisplayDefinition();
- mockHelper.replayAll();
- classUnderTest = new DataTypeDate(null, columnDisplayDefinition);
- mockHelper.resetAll();
- super.setUp();
- }
-
- /**
- *1757076 (DATE column seen as TIMESTAMP, update in editable mode fails)
- * Ensure that we use the user specified value
- * */
- @Test
- public void testGetReadDateAsTimestamp()
- {
- assertTrue("Expected the user specified value",
- DataTypeDate.getReadDateAsTimestamp());
- }
-
-
- /**
- * Ensure, that the Bug 3086444 is solved.
- * If the user defines a custom DateFormat, then we must use this after reading the
- * properties at startup.
- */
- @Test
- public void testUseCustomDateFormatAfterLoadingProperties()
- {
-
- Date currentDate = Date.valueOf("2010-10-15");
-
- String expectedDate = DateFormat.getDateInstance(userDefinedDateFormat).format(currentDate);
-
- String renderedDate = classUnderTest.renderObject(currentDate);
- assertEquals("Must use the user defined format", expectedDate, renderedDate);
-
- }
-
- @Override
- protected Object getEqualsTestObject()
- {
- return new Date(System.currentTimeMillis());
- }
-
-}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|