Modified: harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/java/sql/StatementTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/java/sql/StatementTest.java?view=diff&rev=556562&r1=556561&r2=556562
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/java/sql/StatementTest.java (original)
+++ harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/java/sql/StatementTest.java Mon Jul 16 02:02:56 2007
@@ -25,68 +25,68 @@
public class StatementTest extends TestCase {
- /*
- * Public statics test
- */
- public void testPublicStatics() {
-
- HashMap<String, Integer> thePublicStatics = new HashMap<String, Integer>();
- thePublicStatics.put("NO_GENERATED_KEYS", new Integer(2));
- thePublicStatics.put("RETURN_GENERATED_KEYS", new Integer(1));
- thePublicStatics.put("EXECUTE_FAILED", new Integer(-3));
- thePublicStatics.put("SUCCESS_NO_INFO", new Integer(-2));
- thePublicStatics.put("CLOSE_ALL_RESULTS", new Integer(3));
- thePublicStatics.put("KEEP_CURRENT_RESULT", new Integer(2));
- thePublicStatics.put("CLOSE_CURRENT_RESULT", new Integer(1));
-
- /*
- * System.out.println( "NO_GENERATED_KEYS: " +
- * Statement.NO_GENERATED_KEYS ); System.out.println(
- * "RETURN_GENERATED_KEYS: " + Statement.RETURN_GENERATED_KEYS );
- * System.out.println( "EXECUTE_FAILED: " + Statement.EXECUTE_FAILED );
- * System.out.println( "SUCCESS_NO_INFO: " + Statement.SUCCESS_NO_INFO );
- * System.out.println( "CLOSE_ALL_RESULTS: " +
- * Statement.CLOSE_ALL_RESULTS ); System.out.println(
- * "KEEP_CURRENT_RESULT: " + Statement.KEEP_CURRENT_RESULT );
- * System.out.println( "CLOSE_CURRENT_RESULT: " +
- * Statement.CLOSE_CURRENT_RESULT );
- */
-
- Class<?> statementClass;
- try {
- statementClass = Class.forName("java.sql.Statement");
- } catch (ClassNotFoundException e) {
- fail("java.sql.Statement class not found!");
- return;
- } // end try
-
- Field[] theFields = statementClass.getDeclaredFields();
- int requiredModifier = Modifier.PUBLIC + Modifier.STATIC
- + Modifier.FINAL;
-
- int countPublicStatics = 0;
- for (Field element : theFields) {
- String fieldName = element.getName();
- int theMods = element.getModifiers();
- if (Modifier.isPublic(theMods) && Modifier.isStatic(theMods)) {
- try {
- Object fieldValue = element.get(null);
- Object expectedValue = thePublicStatics.get(fieldName);
- if (expectedValue == null) {
- fail("Field " + fieldName + " missing!");
- } // end
- assertEquals("Field " + fieldName + " value mismatch: ",
- expectedValue, fieldValue);
- assertEquals("Field " + fieldName + " modifier mismatch: ",
- requiredModifier, theMods);
- countPublicStatics++;
- } catch (IllegalAccessException e) {
- fail("Illegal access to Field " + fieldName);
- } // end try
- } // end if
- } // end for
+ /*
+ * Public statics test
+ */
+ public void testPublicStatics() {
+
+ HashMap<String, Integer> thePublicStatics = new HashMap<String, Integer>();
+ thePublicStatics.put("NO_GENERATED_KEYS", new Integer(2));
+ thePublicStatics.put("RETURN_GENERATED_KEYS", new Integer(1));
+ thePublicStatics.put("EXECUTE_FAILED", new Integer(-3));
+ thePublicStatics.put("SUCCESS_NO_INFO", new Integer(-2));
+ thePublicStatics.put("CLOSE_ALL_RESULTS", new Integer(3));
+ thePublicStatics.put("KEEP_CURRENT_RESULT", new Integer(2));
+ thePublicStatics.put("CLOSE_CURRENT_RESULT", new Integer(1));
+
+ /*
+ * System.out.println( "NO_GENERATED_KEYS: " +
+ * Statement.NO_GENERATED_KEYS ); System.out.println(
+ * "RETURN_GENERATED_KEYS: " + Statement.RETURN_GENERATED_KEYS );
+ * System.out.println( "EXECUTE_FAILED: " + Statement.EXECUTE_FAILED );
+ * System.out.println( "SUCCESS_NO_INFO: " + Statement.SUCCESS_NO_INFO );
+ * System.out.println( "CLOSE_ALL_RESULTS: " +
+ * Statement.CLOSE_ALL_RESULTS ); System.out.println(
+ * "KEEP_CURRENT_RESULT: " + Statement.KEEP_CURRENT_RESULT );
+ * System.out.println( "CLOSE_CURRENT_RESULT: " +
+ * Statement.CLOSE_CURRENT_RESULT );
+ */
+
+ Class<?> statementClass;
+ try {
+ statementClass = Class.forName("java.sql.Statement");
+ } catch (ClassNotFoundException e) {
+ fail("java.sql.Statement class not found!");
+ return;
+ } // end try
+
+ Field[] theFields = statementClass.getDeclaredFields();
+ int requiredModifier = Modifier.PUBLIC + Modifier.STATIC
+ + Modifier.FINAL;
+
+ int countPublicStatics = 0;
+ for (Field element : theFields) {
+ String fieldName = element.getName();
+ int theMods = element.getModifiers();
+ if (Modifier.isPublic(theMods) && Modifier.isStatic(theMods)) {
+ try {
+ Object fieldValue = element.get(null);
+ Object expectedValue = thePublicStatics.get(fieldName);
+ if (expectedValue == null) {
+ fail("Field " + fieldName + " missing!");
+ } // end
+ assertEquals("Field " + fieldName + " value mismatch: ",
+ expectedValue, fieldValue);
+ assertEquals("Field " + fieldName + " modifier mismatch: ",
+ requiredModifier, theMods);
+ countPublicStatics++;
+ } catch (IllegalAccessException e) {
+ fail("Illegal access to Field " + fieldName);
+ } // end try
+ } // end if
+ } // end for
- } // end method testPublicStatics
+ } // end method testPublicStatics
} // end class StatementTest
Modified: harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/java/sql/TestHelper_ClassLoader.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/java/sql/TestHelper_ClassLoader.java?view=diff&rev=556562&r1=556561&r2=556562
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/java/sql/TestHelper_ClassLoader.java (original)
+++ harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/java/sql/TestHelper_ClassLoader.java Mon Jul 16 02:02:56 2007
@@ -26,194 +26,197 @@
public class TestHelper_ClassLoader extends ClassLoader {
- public TestHelper_ClassLoader() {
- super(null);
- }
-
- /**
- * Loads a class specified by its name
- * <p>
- * This classloader makes the assumption that any class it is asked to load
- * is in the current directory....
- */
- @Override
+ public TestHelper_ClassLoader() {
+ super(null);
+ }
+
+ /**
+ * Loads a class specified by its name
+ * <p>
+ * This classloader makes the assumption that any class it is asked to load
+ * is in the current directory....
+ */
+ @Override
public Class<?> findClass(String className) throws ClassNotFoundException {
- Class<?> theClass = null;
+ Class<?> theClass = null;
- if (!className.equals("org.apache.harmony.sql.tests.java.sql.TestHelper_DriverManager")) {
+ if (!className
+ .equals("org.apache.harmony.sql.tests.java.sql.TestHelper_DriverManager")) {
return null;
}
- String classNameAsFile = className.replace('.', '/') + ".class";
- // System.out.println("findClass - class filename = " + classNameAsFile
- // );
-
- String classPath = System.getProperty("java.class.path");
- // System.out.println("Test class loader - classpath = " + classPath );
-
- String theSeparator = String.valueOf(File.pathSeparatorChar);
- String[] theClassPaths = classPath.split(theSeparator);
- for (int i = 0; (i < theClassPaths.length) && (theClass == null); i++) {
- // Ignore jar files...
- if (theClassPaths[i].endsWith(".jar")) {
- theClass = loadClassFromJar(theClassPaths[i], className,
- classNameAsFile);
- } else {
- theClass = loadClassFromFile(theClassPaths[i], className,
- classNameAsFile);
- } // end if
- } // end for
+ String classNameAsFile = className.replace('.', '/') + ".class";
+ // System.out.println("findClass - class filename = " + classNameAsFile
+ // );
+
+ String classPath = System.getProperty("java.class.path");
+ // System.out.println("Test class loader - classpath = " + classPath );
+
+ String theSeparator = String.valueOf(File.pathSeparatorChar);
+ String[] theClassPaths = classPath.split(theSeparator);
+ for (int i = 0; (i < theClassPaths.length) && (theClass == null); i++) {
+ // Ignore jar files...
+ if (theClassPaths[i].endsWith(".jar")) {
+ theClass = loadClassFromJar(theClassPaths[i], className,
+ classNameAsFile);
+ } else {
+ theClass = loadClassFromFile(theClassPaths[i], className,
+ classNameAsFile);
+ } // end if
+ } // end for
- return theClass;
- } // end method findClass( String )
+ return theClass;
+ } // end method findClass( String )
- @Override
+ @Override
public Class<?> loadClass(String className) throws ClassNotFoundException {
- // Allowed classes:
- String[] disallowedClasses = { "org.apache.harmony.sql.tests.java.sql.TestHelper_Driver1",
- "org.apache.harmony.sql.tests.java.sql.TestHelper_Driver2",
- "org.apache.harmony.sql.tests.java.sql.TestHelper_Driver4",
- "org.apache.harmony.sql.tests.java.sql.TestHelper_Driver5" };
+ // Allowed classes:
+ String[] disallowedClasses = {
+ "org.apache.harmony.sql.tests.java.sql.TestHelper_Driver1",
+ "org.apache.harmony.sql.tests.java.sql.TestHelper_Driver2",
+ "org.apache.harmony.sql.tests.java.sql.TestHelper_Driver4",
+ "org.apache.harmony.sql.tests.java.sql.TestHelper_Driver5" };
- Class<?> theClass;
+ Class<?> theClass;
- theClass = findLoadedClass(className);
- if (theClass != null) {
+ theClass = findLoadedClass(className);
+ if (theClass != null) {
return theClass;
}
- theClass = this.findClass(className);
+ theClass = this.findClass(className);
- if (theClass == null) {
- for (String element : disallowedClasses) {
- if (element.equals(className)) {
- return null;
- } // end if
- } // end for
- theClass = Class.forName(className);
- } // end if
-
- return theClass;
- } // end method loadClass( String )
-
- private Class<?> loadClassFromFile(String pathName, String className,
- String classNameAsFile) {
- Class<?> theClass = null;
- FileInputStream theInput = null;
- File theFile = null;
- try {
- theFile = new File(pathName, classNameAsFile);
- if (theFile.exists()) {
- int length = (int) theFile.length();
- theInput = new FileInputStream(theFile);
- byte[] theBytes = new byte[length + 100];
- int dataRead = 0;
- while (dataRead < length) {
- int count = theInput.read(theBytes, dataRead,
- theBytes.length - dataRead);
- if (count == -1) {
+ if (theClass == null) {
+ for (String element : disallowedClasses) {
+ if (element.equals(className)) {
+ return null;
+ } // end if
+ } // end for
+ theClass = Class.forName(className);
+ } // end if
+
+ return theClass;
+ } // end method loadClass( String )
+
+ private Class<?> loadClassFromFile(String pathName, String className,
+ String classNameAsFile) {
+ Class<?> theClass = null;
+ FileInputStream theInput = null;
+ File theFile = null;
+ try {
+ theFile = new File(pathName, classNameAsFile);
+ if (theFile.exists()) {
+ int length = (int) theFile.length();
+ theInput = new FileInputStream(theFile);
+ byte[] theBytes = new byte[length + 100];
+ int dataRead = 0;
+ while (dataRead < length) {
+ int count = theInput.read(theBytes, dataRead,
+ theBytes.length - dataRead);
+ if (count == -1) {
break;
}
- dataRead += count;
- }
+ dataRead += count;
+ }
- if (dataRead > 0) {
- // Create the class from the bytes read in...
- theClass = this.defineClass(className, theBytes, 0, dataRead);
- ClassLoader testClassLoader = theClass.getClassLoader();
- if (testClassLoader != this) {
- System.out.println("findClass - wrong classloader!!");
- }
- }
- }
- } catch (Exception e) {
- System.out.println("findClass - exception reading class file.");
- e.printStackTrace();
- } finally {
- try {
- if (theInput != null) {
+ if (dataRead > 0) {
+ // Create the class from the bytes read in...
+ theClass = this.defineClass(className, theBytes, 0,
+ dataRead);
+ ClassLoader testClassLoader = theClass.getClassLoader();
+ if (testClassLoader != this) {
+ System.out.println("findClass - wrong classloader!!");
+ }
+ }
+ }
+ } catch (Exception e) {
+ System.out.println("findClass - exception reading class file.");
+ e.printStackTrace();
+ } finally {
+ try {
+ if (theInput != null) {
theInput.close();
}
- } catch (Exception e) {
- }
- }
- return theClass;
- }
-
- /*
- * Loads a named class from a specified JAR file
- */
- private Class<?> loadClassFromJar(String jarfileName, String className,
- String classNameAsFile) {
- Class<?> theClass = null;
-
- // First, try to open the Jar file
- JarFile theJar = null;
- try {
- theJar = new JarFile(jarfileName);
- JarEntry theEntry = theJar.getJarEntry(classNameAsFile);
-
- if (theEntry == null) {
- // System.out.println("TestHelper_Classloader - did not find
- // class file in Jar " + jarfileName );
- return theClass;
- } // end if
+ } catch (Exception e) {
+ }
+ }
+ return theClass;
+ }
+
+ /*
+ * Loads a named class from a specified JAR file
+ */
+ private Class<?> loadClassFromJar(String jarfileName, String className,
+ String classNameAsFile) {
+ Class<?> theClass = null;
+
+ // First, try to open the Jar file
+ JarFile theJar = null;
+ try {
+ theJar = new JarFile(jarfileName);
+ JarEntry theEntry = theJar.getJarEntry(classNameAsFile);
+
+ if (theEntry == null) {
+ // System.out.println("TestHelper_Classloader - did not find
+ // class file in Jar " + jarfileName );
+ return theClass;
+ } // end if
- theEntry.getMethod();
- InputStream theStream = theJar.getInputStream(theEntry);
+ theEntry.getMethod();
+ InputStream theStream = theJar.getInputStream(theEntry);
- long size = theEntry.getSize();
- if (size < 0) {
+ long size = theEntry.getSize();
+ if (size < 0) {
size = 100000;
}
- byte[] theBytes = new byte[(int) size + 100];
+ byte[] theBytes = new byte[(int) size + 100];
- int dataRead = 0;
- while (dataRead < size) {
- int count = theStream.read(theBytes, dataRead, theBytes.length
- - dataRead);
- if (count == -1) {
+ int dataRead = 0;
+ while (dataRead < size) {
+ int count = theStream.read(theBytes, dataRead, theBytes.length
+ - dataRead);
+ if (count == -1) {
break;
}
- dataRead += count;
- } // end while
+ dataRead += count;
+ } // end while
- // System.out.println("loadClassFromJar: read " + dataRead + " bytes
- // from class file");
- if (dataRead > 0) {
- // Create the class from the bytes read in...
- theClass = this.defineClass(className, theBytes, 0, dataRead);
- /* System.out.println("findClass: created Class object."); */
- ClassLoader testClassLoader = theClass.getClassLoader();
- if (testClassLoader != this) {
- System.out.println("findClass - wrong classloader!!");
- } else {
- System.out
- .println("Testclassloader loaded class from jar: "
- + className);
- } // end if
- } // end if
- } catch (IOException ie) {
- System.out
- .println("TestHelper_ClassLoader: IOException opening Jar "
- + jarfileName);
- } catch (Exception e) {
- System.out
- .println("TestHelper_ClassLoader: Exception loading class from Jar ");
- } catch (ClassFormatError ce) {
- System.out
- .println("TestHelper_ClassLoader: ClassFormatException loading class from Jar ");
- } finally {
- try {
- if (theJar != null) {
+ // System.out.println("loadClassFromJar: read " + dataRead + " bytes
+ // from class file");
+ if (dataRead > 0) {
+ // Create the class from the bytes read in...
+ theClass = this.defineClass(className, theBytes, 0, dataRead);
+ /* System.out.println("findClass: created Class object."); */
+ ClassLoader testClassLoader = theClass.getClassLoader();
+ if (testClassLoader != this) {
+ System.out.println("findClass - wrong classloader!!");
+ } else {
+ System.out
+ .println("Testclassloader loaded class from jar: "
+ + className);
+ } // end if
+ } // end if
+ } catch (IOException ie) {
+ System.out
+ .println("TestHelper_ClassLoader: IOException opening Jar "
+ + jarfileName);
+ } catch (Exception e) {
+ System.out
+ .println("TestHelper_ClassLoader: Exception loading class from Jar ");
+ } catch (ClassFormatError ce) {
+ System.out
+ .println("TestHelper_ClassLoader: ClassFormatException loading class from Jar ");
+ } finally {
+ try {
+ if (theJar != null) {
theJar.close();
}
- } catch (Exception e) {
- } // end try
- } // end try
+ } catch (Exception e) {
+ } // end try
+ } // end try
- return theClass;
- } // end method loadClassFromJar(
+ return theClass;
+ } // end method loadClassFromJar(
} // end class TestHelper_ClassLoader
Modified: harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/java/sql/TestHelper_Connection1.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/java/sql/TestHelper_Connection1.java?view=diff&rev=556562&r1=556561&r2=556562
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/java/sql/TestHelper_Connection1.java (original)
+++ harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/java/sql/TestHelper_Connection1.java Mon Jul 16 02:02:56 2007
@@ -46,8 +46,9 @@
return null;
}
- public Statement createStatement(int resultSetType, int resultSetConcurrency,
- int resultSetHoldability) throws SQLException {
+ public Statement createStatement(int resultSetType,
+ int resultSetConcurrency, int resultSetHoldability)
+ throws SQLException {
return null;
}
@@ -97,12 +98,13 @@
}
public CallableStatement prepareCall(String sql, int resultSetType,
- int resultSetConcurrency, int resultSetHoldability) throws SQLException {
+ int resultSetConcurrency, int resultSetHoldability)
+ throws SQLException {
return null;
}
- public CallableStatement prepareCall(String sql, int resultSetType, int resultSetConcurrency)
- throws SQLException {
+ public CallableStatement prepareCall(String sql, int resultSetType,
+ int resultSetConcurrency) throws SQLException {
return null;
}
@@ -111,7 +113,8 @@
}
public PreparedStatement prepareStatement(String sql, int resultSetType,
- int resultSetConcurrency, int resultSetHoldability) throws SQLException {
+ int resultSetConcurrency, int resultSetHoldability)
+ throws SQLException {
return null;
}
Modified: harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/java/sql/TestHelper_Driver1.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/java/sql/TestHelper_Driver1.java?view=diff&rev=556562&r1=556561&r2=556562
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/java/sql/TestHelper_Driver1.java (original)
+++ harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/java/sql/TestHelper_Driver1.java Mon Jul 16 02:02:56 2007
@@ -104,7 +104,8 @@
public DriverPropertyInfo[] getPropertyInfo(String url, Properties info)
throws SQLException {
- DriverPropertyInfo[] theInfos = { new DriverPropertyInfo(userProperty, "*"),
+ DriverPropertyInfo[] theInfos = {
+ new DriverPropertyInfo(userProperty, "*"),
new DriverPropertyInfo(passwordProperty, "*"), };
return theInfos;
}
Modified: harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/java/sql/TestHelper_Driver2.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/java/sql/TestHelper_Driver2.java?view=diff&rev=556562&r1=556561&r2=556562
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/java/sql/TestHelper_Driver2.java (original)
+++ harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/java/sql/TestHelper_Driver2.java Mon Jul 16 02:02:56 2007
@@ -27,24 +27,24 @@
*/
public class TestHelper_Driver2 extends TestHelper_Driver1 {
- static {
- Driver theDriver = new TestHelper_Driver2();
- /*
- * System.out.println("Driver2 classloader: " +
- * theDriver.getClass().getClassLoader() ); System.out.println("Driver2
- * object is: " + theDriver );
- */
- try {
- DriverManager.registerDriver(theDriver);
- } catch (SQLException e) {
- System.out.println("Failed to register driver!");
- }
- } // end static block initializer
+ static {
+ Driver theDriver = new TestHelper_Driver2();
+ /*
+ * System.out.println("Driver2 classloader: " +
+ * theDriver.getClass().getClassLoader() ); System.out.println("Driver2
+ * object is: " + theDriver );
+ */
+ try {
+ DriverManager.registerDriver(theDriver);
+ } catch (SQLException e) {
+ System.out.println("Failed to register driver!");
+ }
+ } // end static block initializer
- protected TestHelper_Driver2() {
- super();
- baseURL = "jdbc:mikes2";
- } // end constructor TestHelper_Driver1()
+ protected TestHelper_Driver2() {
+ super();
+ baseURL = "jdbc:mikes2";
+ } // end constructor TestHelper_Driver1()
} // end class TestHelper_Driver2
Modified: harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/java/sql/TestHelper_Driver3.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/java/sql/TestHelper_Driver3.java?view=diff&rev=556562&r1=556561&r2=556562
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/java/sql/TestHelper_Driver3.java (original)
+++ harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/java/sql/TestHelper_Driver3.java Mon Jul 16 02:02:56 2007
@@ -17,20 +17,19 @@
package org.apache.harmony.sql.tests.java.sql;
-
/**
* TODO Type description
*
*/
public class TestHelper_Driver3 extends TestHelper_Driver1 {
- /*
- * This driver does NOT automatically register itself...
- */
+ /*
+ * This driver does NOT automatically register itself...
+ */
- public TestHelper_Driver3() {
- super();
- baseURL = "jdbc:mikes3";
- } // end constructor TestHelper_Driver1()
+ public TestHelper_Driver3() {
+ super();
+ baseURL = "jdbc:mikes3";
+ } // end constructor TestHelper_Driver1()
} // end class TestHelper_Driver3
Modified: harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/java/sql/TestHelper_Driver4.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/java/sql/TestHelper_Driver4.java?view=diff&rev=556562&r1=556561&r2=556562
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/java/sql/TestHelper_Driver4.java (original)
+++ harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/java/sql/TestHelper_Driver4.java Mon Jul 16 02:02:56 2007
@@ -92,10 +92,13 @@
String user = (String) info.get(userProperty);
String password = (String) info.get(passwordProperty);
if (user == null || password == null) {
- throw new SQLException("Userid and/or password not supplied");
+ throw new SQLException(
+ "Userid and/or password not supplied");
}
- if (!user.equals(validuser) || !password.equals(validpassword)) {
- throw new SQLException("Userid and/or password not valid");
+ if (!user.equals(validuser)
+ || !password.equals(validpassword)) {
+ throw new SQLException(
+ "Userid and/or password not valid");
} // end if
} // end if
// It all checks out - so return a connection
@@ -117,7 +120,8 @@
public DriverPropertyInfo[] getPropertyInfo(String url, Properties info)
throws SQLException {
- DriverPropertyInfo[] theInfos = { new DriverPropertyInfo(userProperty, "*"),
+ DriverPropertyInfo[] theInfos = {
+ new DriverPropertyInfo(userProperty, "*"),
new DriverPropertyInfo(passwordProperty, "*"), };
return theInfos;
}
Modified: harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/java/sql/TestHelper_Driver5.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/java/sql/TestHelper_Driver5.java?view=diff&rev=556562&r1=556561&r2=556562
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/java/sql/TestHelper_Driver5.java (original)
+++ harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/java/sql/TestHelper_Driver5.java Mon Jul 16 02:02:56 2007
@@ -27,18 +27,18 @@
*/
public class TestHelper_Driver5 extends TestHelper_Driver4 {
- static {
- Driver theDriver = new TestHelper_Driver5();
- try {
- DriverManager.registerDriver(theDriver);
- } catch (SQLException e) {
- System.out.println("Failed to register driver!");
- }
- } // end static block initializer
+ static {
+ Driver theDriver = new TestHelper_Driver5();
+ try {
+ DriverManager.registerDriver(theDriver);
+ } catch (SQLException e) {
+ System.out.println("Failed to register driver!");
+ }
+ } // end static block initializer
- protected TestHelper_Driver5() {
- super();
- baseURL = "jdbc:mikes5";
- } // end constructor TestHelper_Driver5()
+ protected TestHelper_Driver5() {
+ super();
+ baseURL = "jdbc:mikes5";
+ } // end constructor TestHelper_Driver5()
} // end class TestHelper_Driver5
Modified: harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/java/sql/TestHelper_DriverManager.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/java/sql/TestHelper_DriverManager.java?view=diff&rev=556562&r1=556561&r2=556562
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/java/sql/TestHelper_DriverManager.java (original)
+++ harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/java/sql/TestHelper_DriverManager.java Mon Jul 16 02:02:56 2007
@@ -31,83 +31,80 @@
*/
public class TestHelper_DriverManager extends TestCase {
- static Driver testDriver = null;
+ static Driver testDriver = null;
- static TestHelper_DriverManager theHelper;
+ static TestHelper_DriverManager theHelper;
- static {
- theHelper = new TestHelper_DriverManager();
- // theHelper.testDeregister();
- } // end static
-
- public TestHelper_DriverManager() {
- super();
- } // end constructor TestHelper_DriverManager()
-
- public static void setDriver(Driver theDriver) {
- testDriver = theDriver;
- // System.out.println("TestHelper_DriverManager: Test Driver set!");
-
- theHelper.checkDeregister();
- } // end method setDriver( Driver )
-
- public void checkDeregister() {
-
- String baseURL = "jdbc:mikes1";
-
- // System.out.println("Calling checkDeregister in
- // TestHelper_DriverManager....");
-
- Driver aDriver;
-
- // System.out.println("checkDeregister classloader: " +
- // this.getClass().getClassLoader() );
-
- // Try to get a driver from the general pool... this should fail
- try {
- aDriver = DriverManager.getDriver(baseURL);
- fail(
- "testDeregisterDriver: Didn't get exception when getting valid driver from other classloader.");
- } catch (SQLException e) {
- // e.printStackTrace();
- assertTrue(
- "testDeregisterDriver: Got exception when getting valid driver from other classloader.",
- true);
- // return;
- } // end try
-
- // OK, now THIS driver was loaded by someone else....
- aDriver = testDriver;
-
- // printClassLoader( aDriver );
-
- // Deregister this driver
- try {
- DriverManager.deregisterDriver(aDriver);
- // We shouldn't get here - but if we do, we need to re-register the
- // driver to
- // prevent subsequent tests from failing due to inability to get to
- // this driver...
- DriverManager.registerDriver(aDriver);
- fail(
- "checkDeregisterDriver: Didn't get Security Exception deregistering invalid driver.");
- } catch (SecurityException s) {
- // This is the exception we should get...
- // System.out.println("checkDeregisterDriver: got expected Security
- // Exception");
- } catch (Exception e) {
- fail(
- "checkDeregisterDriver: Got wrong exception type when deregistering invalid driver.");
- } // end try
-
- } // end method testDeRegister
-
- static void printClassLoader(Object theObject) {
- Class<? extends Object> theClass = theObject.getClass();
- ClassLoader theClassLoader = theClass.getClassLoader();
- System.out.println("ClassLoader is: " + theClassLoader.toString()
- + " for object: " + theObject.toString());
- } // end method printClassLoader( Object )
+ static {
+ theHelper = new TestHelper_DriverManager();
+ // theHelper.testDeregister();
+ } // end static
+
+ public TestHelper_DriverManager() {
+ super();
+ } // end constructor TestHelper_DriverManager()
+
+ public static void setDriver(Driver theDriver) {
+ testDriver = theDriver;
+ // System.out.println("TestHelper_DriverManager: Test Driver set!");
+
+ theHelper.checkDeregister();
+ } // end method setDriver( Driver )
+
+ public void checkDeregister() {
+
+ String baseURL = "jdbc:mikes1";
+
+ // System.out.println("Calling checkDeregister in
+ // TestHelper_DriverManager....");
+
+ Driver aDriver;
+
+ // System.out.println("checkDeregister classloader: " +
+ // this.getClass().getClassLoader() );
+
+ // Try to get a driver from the general pool... this should fail
+ try {
+ aDriver = DriverManager.getDriver(baseURL);
+ fail("testDeregisterDriver: Didn't get exception when getting valid driver from other classloader.");
+ } catch (SQLException e) {
+ // e.printStackTrace();
+ assertTrue(
+ "testDeregisterDriver: Got exception when getting valid driver from other classloader.",
+ true);
+ // return;
+ } // end try
+
+ // OK, now THIS driver was loaded by someone else....
+ aDriver = testDriver;
+
+ // printClassLoader( aDriver );
+
+ // Deregister this driver
+ try {
+ DriverManager.deregisterDriver(aDriver);
+ // We shouldn't get here - but if we do, we need to re-register the
+ // driver to
+ // prevent subsequent tests from failing due to inability to get to
+ // this driver...
+ DriverManager.registerDriver(aDriver);
+ fail("checkDeregisterDriver: Didn't get Security Exception deregistering invalid driver.");
+ } catch (SecurityException s) {
+ // This is the exception we should get...
+ // System.out.println("checkDeregisterDriver: got expected Security
+ // Exception");
+ } catch (Exception e) {
+ fail("checkDeregisterDriver: Got wrong exception type when deregistering invalid driver.");
+ } // end try
+
+ } // end method testDeRegister
+
+ static void printClassLoader(Object theObject) {
+ Class<? extends Object> theClass = theObject.getClass();
+ ClassLoader theClassLoader = theClass.getClassLoader();
+ System.out.println("ClassLoader is: " + theClassLoader.toString()
+ + " for object: " + theObject.toString());
+ } // end method printClassLoader( Object )
} // end class TestHelper_DriverManager
Modified: harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/java/sql/TestMainForDriver.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/java/sql/TestMainForDriver.java?view=diff&rev=556562&r1=556561&r2=556562
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/java/sql/TestMainForDriver.java (original)
+++ harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/java/sql/TestMainForDriver.java Mon Jul 16 02:02:56 2007
@@ -26,9 +26,9 @@
// Install SecurityManager
System.setSecurityManager(new SecurityManager());
// Load java.sql.DriverManager and it will invoke its <clinit> method
- try{
+ try {
Class.forName("java.sql.DriverManager");
- }catch (ExceptionInInitializerError e){
+ } catch (ExceptionInInitializerError e) {
// ExceptionInInitializerError is caused by AccessControlException
throw e.getException();
}
Modified: harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/java/sql/TimeTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/java/sql/TimeTest.java?view=diff&rev=556562&r1=556561&r2=556562
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/java/sql/TimeTest.java (original)
+++ harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/java/sql/TimeTest.java Mon Jul 16 02:02:56 2007
@@ -28,277 +28,276 @@
*/
public class TimeTest extends TestCase {
- static long TIME_TEST1 = 38720000; // 10:45:20 GMT
+ static long TIME_TEST1 = 38720000; // 10:45:20 GMT
- static long TIME_TEST2 = 80279000; // 22:17:59 GMT
+ static long TIME_TEST2 = 80279000; // 22:17:59 GMT
- static long TIME_TEST3 = -38720000; // 13:14:40 GMT
+ static long TIME_TEST3 = -38720000; // 13:14:40 GMT
- static String STRING_TEST1 = "10:45:20";
+ static String STRING_TEST1 = "10:45:20";
- static String STRING_TEST2 = "22:17:59";
+ static String STRING_TEST2 = "22:17:59";
- static String STRING_TEST3 = "13:14:40";
+ static String STRING_TEST3 = "13:14:40";
- static String STRING_INVALID1 = "ABCDEFGHI";
+ static String STRING_INVALID1 = "ABCDEFGHI";
- static String STRING_INVALID2 = "233104";
+ static String STRING_INVALID2 = "233104";
- static String STRING_INVALID3 = "21-43-48";
+ static String STRING_INVALID3 = "21-43-48";
- static String STRING_OUTRANGE = "35:99:66";
+ static String STRING_OUTRANGE = "35:99:66";
- static long[] TIME_ARRAY = { TIME_TEST1, TIME_TEST2, TIME_TEST3 };
+ static long[] TIME_ARRAY = { TIME_TEST1, TIME_TEST2, TIME_TEST3 };
- static String[] STRING_GMT_ARRAY = { STRING_TEST1, STRING_TEST2,
- STRING_TEST3 };
+ static String[] STRING_GMT_ARRAY = { STRING_TEST1, STRING_TEST2,
+ STRING_TEST3 };
- static String[] STRING_LA_ARRAY = { "02:45:20", "14:17:59", "05:14:40" };
+ static String[] STRING_LA_ARRAY = { "02:45:20", "14:17:59", "05:14:40" };
- static String[] STRING_JP_ARRAY = { "19:45:20", "07:17:59", "22:14:40" };
+ static String[] STRING_JP_ARRAY = { "19:45:20", "07:17:59", "22:14:40" };
- static String[] INVALID_STRINGS = { STRING_INVALID1, STRING_INVALID2,
- STRING_INVALID3 };
+ static String[] INVALID_STRINGS = { STRING_INVALID1, STRING_INVALID2,
+ STRING_INVALID3 };
- // Timezones
- static String TZ_LONDON = "GMT"; // GMT (!) PS London != GMT (?!?)
+ // Timezones
+ static String TZ_LONDON = "GMT"; // GMT (!) PS London != GMT (?!?)
- static String TZ_PACIFIC = "America/Los_Angeles"; // GMT - 8
+ static String TZ_PACIFIC = "America/Los_Angeles"; // GMT - 8
- static String TZ_JAPAN = "Asia/Tokyo"; // GMT + 9
+ static String TZ_JAPAN = "Asia/Tokyo"; // GMT + 9
- static String[] TIMEZONES = { TZ_LONDON, TZ_PACIFIC, TZ_JAPAN };
+ static String[] TIMEZONES = { TZ_LONDON, TZ_PACIFIC, TZ_JAPAN };
- static String[][] STRING_ARRAYS = { STRING_GMT_ARRAY, STRING_LA_ARRAY,
- STRING_JP_ARRAY };
+ static String[][] STRING_ARRAYS = { STRING_GMT_ARRAY, STRING_LA_ARRAY,
+ STRING_JP_ARRAY };
- @SuppressWarnings("deprecation")
+ @SuppressWarnings("deprecation")
public void testTimeintintint() {
- Time theTime = new Time(10, 45, 20);
+ Time theTime = new Time(10, 45, 20);
- // The date should have been created
- assertNotNull(theTime);
- } // end method testTimeintintint()
-
- public void testTime() {
- Time theTime = new Time(TIME_TEST1);
-
- // The date should have been created
- assertNotNull(theTime);
- } // end method testTime()
-
- public void testToString() {
- // Loop through the timezones testing the String conversion for each
- for (int i = 0; i < TIME_ARRAY.length; i++) {
- testToString(TIMEZONES[i], TIME_ARRAY, STRING_ARRAYS[i]);
- } // end for
-
- } // end method test
-
- private void testToString(String timeZone, long[] theTimes,
- String[] theTimeStrings) {
- // Set the timezone
- TimeZone.setDefault(TimeZone.getTimeZone(timeZone));
-
- for (int i = 0; i < theTimes.length; i++) {
- // Create the Time object
- Time theTime = new Time(theTimes[i]);
- // Convert to a time string ... and compare
- String JDBCString = theTime.toString();
- assertEquals(theTimeStrings[i], JDBCString);
- } // end for
-
- } // end testToString( String, long[], String[] )
-
- /*
- * Method test for valueOf
- */
- public void testValueOfString() {
- TimeZone.setDefault(TimeZone.getTimeZone("GMT"));
-
-
- Time[] theReturns = { new Time(38720000), new Time(80279000),
- new Time(47680000)};
- String[] validTime = { "10:45:20", "22:17:59", "13:14:40", };
+ // The date should have been created
+ assertNotNull(theTime);
+ } // end method testTimeintintint()
+
+ public void testTime() {
+ Time theTime = new Time(TIME_TEST1);
+
+ // The date should have been created
+ assertNotNull(theTime);
+ } // end method testTime()
+
+ public void testToString() {
+ // Loop through the timezones testing the String conversion for each
+ for (int i = 0; i < TIME_ARRAY.length; i++) {
+ testToString(TIMEZONES[i], TIME_ARRAY, STRING_ARRAYS[i]);
+ } // end for
+
+ } // end method test
+
+ private void testToString(String timeZone, long[] theTimes,
+ String[] theTimeStrings) {
+ // Set the timezone
+ TimeZone.setDefault(TimeZone.getTimeZone(timeZone));
+
+ for (int i = 0; i < theTimes.length; i++) {
+ // Create the Time object
+ Time theTime = new Time(theTimes[i]);
+ // Convert to a time string ... and compare
+ String JDBCString = theTime.toString();
+ assertEquals(theTimeStrings[i], JDBCString);
+ } // end for
+
+ } // end testToString( String, long[], String[] )
+
+ /*
+ * Method test for valueOf
+ */
+ public void testValueOfString() {
+ TimeZone.setDefault(TimeZone.getTimeZone("GMT"));
+
+ Time[] theReturns = { new Time(38720000), new Time(80279000),
+ new Time(47680000) };
+ String[] validTime = { "10:45:20", "22:17:59", "13:14:40", };
String[] invalidTime = { null, "ABCDEFGHI", "233104", "21-43-48" };
-
- for (int i = 0; i < validTime.length; i++) {
+
+ for (int i = 0; i < validTime.length; i++) {
Time theReturn = Time.valueOf(validTime[i]);
- assertEquals(theReturns[i], theReturn);
- } // end for
-
+ assertEquals(theReturns[i], theReturn);
+ } // end for
+
for (String element : invalidTime) {
try {
Time.valueOf(element);
fail("Should throw IllegalArgumentException");
} catch (IllegalArgumentException e) {
- //expected
+ // expected
}
}
- } // end method testValueOfString
+ } // end method testValueOfString
- public void testSetTime() {
- // Ensure that the timezone is set to GMT
- TimeZone.setDefault(TimeZone.getTimeZone("GMT"));
+ public void testSetTime() {
+ // Ensure that the timezone is set to GMT
+ TimeZone.setDefault(TimeZone.getTimeZone("GMT"));
- Time theTime = new Time(TIME_TEST1);
+ Time theTime = new Time(TIME_TEST1);
assertEquals(STRING_TEST1, theTime.toString());
- theTime.setTime(TIME_TEST2);
+ theTime.setTime(TIME_TEST2);
assertEquals(STRING_TEST2, theTime.toString());
- } // end method testSetTime()
+ } // end method testSetTime()
- @SuppressWarnings("deprecation")
+ @SuppressWarnings("deprecation")
public void testSetDate() {
- Time theTime = new Time(TIME_TEST1);
+ Time theTime = new Time(TIME_TEST1);
- try {
- theTime.setDate(10);
+ try {
+ theTime.setDate(10);
fail("Should throw IllegalArgumentException.");
- } catch (IllegalArgumentException e) {
- //expected
- } // end try
- } // end method testSetDate()
+ } catch (IllegalArgumentException e) {
+ // expected
+ } // end try
+ } // end method testSetDate()
- @SuppressWarnings("deprecation")
+ @SuppressWarnings("deprecation")
public void testSetMonth() {
- Time theTime = new Time(TIME_TEST1);
+ Time theTime = new Time(TIME_TEST1);
- try {
- theTime.setMonth(2);
+ try {
+ theTime.setMonth(2);
fail("Should throw IllegalArgumentException.");
- } catch (IllegalArgumentException e) {
- //expected
- } // end try
- } // end method testSetMonth()
+ } catch (IllegalArgumentException e) {
+ // expected
+ } // end try
+ } // end method testSetMonth()
- @SuppressWarnings("deprecation")
+ @SuppressWarnings("deprecation")
public void testSetYear() {
- Time theTime = new Time(TIME_TEST1);
+ Time theTime = new Time(TIME_TEST1);
- try {
- theTime.setYear(99);
+ try {
+ theTime.setYear(99);
fail("Should throw IllegalArgumentException.");
- } catch (IllegalArgumentException e) {
- //expected
- } // end try
- } // end method testSetYear()
+ } catch (IllegalArgumentException e) {
+ // expected
+ } // end try
+ } // end method testSetYear()
- @SuppressWarnings("deprecation")
+ @SuppressWarnings("deprecation")
public void testGetDate() {
- Time theTime = new Time(TIME_TEST1);
+ Time theTime = new Time(TIME_TEST1);
- try {
- theTime.getDate();
+ try {
+ theTime.getDate();
fail("Should throw IllegalArgumentException.");
- } catch (IllegalArgumentException e) {
- //expected
- } // end try
- } // end method test
+ } catch (IllegalArgumentException e) {
+ // expected
+ } // end try
+ } // end method test
- @SuppressWarnings("deprecation")
+ @SuppressWarnings("deprecation")
public void testGetDay() {
- Time theTime = new Time(TIME_TEST1);
+ Time theTime = new Time(TIME_TEST1);
- try {
- theTime.getDay();
+ try {
+ theTime.getDay();
fail("Should throw IllegalArgumentException.");
- } catch (IllegalArgumentException e) {
- //expected
- } // end try
- } // end method test
+ } catch (IllegalArgumentException e) {
+ // expected
+ } // end try
+ } // end method test
- @SuppressWarnings("deprecation")
+ @SuppressWarnings("deprecation")
public void testGetMonth() {
- Time theTime = new Time(TIME_TEST1);
+ Time theTime = new Time(TIME_TEST1);
- try {
- theTime.getMonth();
+ try {
+ theTime.getMonth();
fail("Should throw IllegalArgumentException.");
- } catch (IllegalArgumentException e) {
- //expected
- } // end try
- } // end method test
+ } catch (IllegalArgumentException e) {
+ // expected
+ } // end try
+ } // end method test
- @SuppressWarnings("deprecation")
+ @SuppressWarnings("deprecation")
public void testGetYear() {
- Time theTime = new Time(TIME_TEST1);
+ Time theTime = new Time(TIME_TEST1);
- try {
- theTime.getYear();
+ try {
+ theTime.getYear();
fail("Should throw IllegalArgumentException.");
- } catch (IllegalArgumentException e) {
- //expected
- } // end try
- } // end method test
-
+ } catch (IllegalArgumentException e) {
+ // expected
+ } // end try
+ } // end method test
+
/**
* @tests java.sql.Time#valueOf(String )
*/
- public void test_valueOf_IllegalArgumentException() {
- try{
- Time.valueOf("15:43:12:34");
- fail("should throw NumberFormatException");
- } catch (NumberFormatException e) {
- //expected
- }
-
- try{
- Time.valueOf(":10:07:01");
- fail("should throw IllegalArgumentException");
- } catch (IllegalArgumentException e) {
- //expected
- }
-
- try{
- Time.valueOf("::01");
- fail("should throw IllegalArgumentException");
- } catch (IllegalArgumentException e) {
- //expected
- }
-
- try{
- Time.valueOf("11::");
- fail("should throw IllegalArgumentException");
- } catch (IllegalArgumentException e) {
- //expected
- }
-
- try{
- Time.valueOf(":01:");
- fail("should throw IllegalArgumentException");
- } catch (IllegalArgumentException e) {
- //expected
- }
-
- try{
- Time.valueOf(":10:w2:01");
- fail("should throw IllegalArgumentException");
- } catch (IllegalArgumentException e) {
- //expected
- }
-
- try{
- Time.valueOf("07:w2:");
- fail("should throw IllegalArgumentException");
- } catch (IllegalArgumentException e) {
- //expected
- }
-
- try{
- Time.valueOf("17:w2:w2");
- fail("should throw NumberFormatException");
- } catch (NumberFormatException e) {
- //expected
- }
-
- try{
- Time.valueOf("16::01");
- fail("should throw NumberFormatException");
- } catch (NumberFormatException e) {
- //expected
- }
+ public void test_valueOf_IllegalArgumentException() {
+ try {
+ Time.valueOf("15:43:12:34");
+ fail("should throw NumberFormatException");
+ } catch (NumberFormatException e) {
+ // expected
+ }
+
+ try {
+ Time.valueOf(":10:07:01");
+ fail("should throw IllegalArgumentException");
+ } catch (IllegalArgumentException e) {
+ // expected
+ }
+
+ try {
+ Time.valueOf("::01");
+ fail("should throw IllegalArgumentException");
+ } catch (IllegalArgumentException e) {
+ // expected
+ }
+
+ try {
+ Time.valueOf("11::");
+ fail("should throw IllegalArgumentException");
+ } catch (IllegalArgumentException e) {
+ // expected
+ }
+
+ try {
+ Time.valueOf(":01:");
+ fail("should throw IllegalArgumentException");
+ } catch (IllegalArgumentException e) {
+ // expected
+ }
+
+ try {
+ Time.valueOf(":10:w2:01");
+ fail("should throw IllegalArgumentException");
+ } catch (IllegalArgumentException e) {
+ // expected
+ }
+
+ try {
+ Time.valueOf("07:w2:");
+ fail("should throw IllegalArgumentException");
+ } catch (IllegalArgumentException e) {
+ // expected
+ }
+
+ try {
+ Time.valueOf("17:w2:w2");
+ fail("should throw NumberFormatException");
+ } catch (NumberFormatException e) {
+ // expected
+ }
+
+ try {
+ Time.valueOf("16::01");
+ fail("should throw NumberFormatException");
+ } catch (NumberFormatException e) {
+ // expected
}
+ }
} // end class TimeTest
Modified: harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/java/sql/TimestampTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/java/sql/TimestampTest.java?view=diff&rev=556562&r1=556561&r2=556562
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/java/sql/TimestampTest.java (original)
+++ harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/java/sql/TimestampTest.java Mon Jul 16 02:02:56 2007
@@ -31,134 +31,133 @@
public class TimestampTest extends TestCase {
- static long TIME_TEST1 = 38720231; // 10:45:20.231 GMT
+ static long TIME_TEST1 = 38720231; // 10:45:20.231 GMT
- static long TIME_TEST2 = 80279000; // 22:17:59.000 GMT
+ static long TIME_TEST2 = 80279000; // 22:17:59.000 GMT
- static long TIME_TEST3 = -38720691; // 13:14:39.309 GMT
+ static long TIME_TEST3 = -38720691; // 13:14:39.309 GMT
- static long TIME_COMPARE = 123498845;
+ static long TIME_COMPARE = 123498845;
- static long TIME_EARLY = -2347889122L;// A time well before the Epoch
+ static long TIME_EARLY = -2347889122L;// A time well before the Epoch
- static long TIME_LATE = 2347889122L; // A time well after the Epoch
+ static long TIME_LATE = 2347889122L; // A time well after the Epoch
- static String STRING_TEST1 = "1970-01-01 10:45:20.231"; // "1970-01-01
- // 10:45:20.231000000";
+ static String STRING_TEST1 = "1970-01-01 10:45:20.231"; // "1970-01-01
- static String STRING_TEST2 = "1970-01-01 22:17:59.0"; // "1970-01-01
- // 22:17:59.000000000";
+ // 10:45:20.231000000";
- static String STRING_TEST3 = "1969-12-31 13:14:39.309"; // "1969-12-31
- // 13:14:39.309000000";
+ static String STRING_TEST2 = "1970-01-01 22:17:59.0"; // "1970-01-01
- static String STRING_INVALID1 = "ABCDEFGHI";
+ // 22:17:59.000000000";
- static String STRING_INVALID2 = "233104";
+ static String STRING_TEST3 = "1969-12-31 13:14:39.309"; // "1969-12-31
- static String STRING_INVALID3 = "21-43-48";
+ // 13:14:39.309000000";
- // A timepoint in the correct format but with numeric values out of range
- // ...this is accepted despite being a crazy date specification
- // ...it is treated as the correct format date 3000-06-08 12:40:06.875 !!
- static String STRING_OUTRANGE = "2999-15-99 35:99:66.875";
+ static String STRING_INVALID1 = "ABCDEFGHI";
- static long[] TIME_ARRAY = { TIME_TEST1, TIME_TEST2, TIME_TEST3 };
+ static String STRING_INVALID2 = "233104";
- static int[] YEAR_ARRAY = { 70, 70, 69 };
+ static String STRING_INVALID3 = "21-43-48";
- static int[] MONTH_ARRAY = { 0, 0, 11 };
+ // A timepoint in the correct format but with numeric values out of range
+ // ...this is accepted despite being a crazy date specification
+ // ...it is treated as the correct format date 3000-06-08 12:40:06.875 !!
+ static String STRING_OUTRANGE = "2999-15-99 35:99:66.875";
- static int[] DATE_ARRAY = { 1, 1, 31 };
+ static long[] TIME_ARRAY = { TIME_TEST1, TIME_TEST2, TIME_TEST3 };
- static int[] HOURS_ARRAY = { 10, 22, 13 };
+ static int[] YEAR_ARRAY = { 70, 70, 69 };
- static int[] MINUTES_ARRAY = { 45, 17, 14 };
+ static int[] MONTH_ARRAY = { 0, 0, 11 };
- static int[] SECONDS_ARRAY = { 20, 59, 39 };
+ static int[] DATE_ARRAY = { 1, 1, 31 };
- static int[] NANOS_ARRAY = { 231000000, 000000000, 309000000 };
+ static int[] HOURS_ARRAY = { 10, 22, 13 };
- static int[] NANOS_ARRAY2 = { 137891990, 635665198, 109985421 };
+ static int[] MINUTES_ARRAY = { 45, 17, 14 };
- static String[] STRING_NANOS_ARRAY = { "1970-01-01 10:45:20.13789199",
- "1970-01-01 22:17:59.635665198", "1969-12-31 13:14:39.109985421" };
+ static int[] SECONDS_ARRAY = { 20, 59, 39 };
- static String[] STRING_GMT_ARRAY = { STRING_TEST1, STRING_TEST2,
- STRING_TEST3 };
+ static int[] NANOS_ARRAY = { 231000000, 000000000, 309000000 };
- static String[] STRING_LA_ARRAY = { "02:45:20", "14:17:59", "05:14:40" };
+ static int[] NANOS_ARRAY2 = { 137891990, 635665198, 109985421 };
- static String[] STRING_JP_ARRAY = { "19:45:20", "07:17:59", "22:14:40" };
+ static String[] STRING_NANOS_ARRAY = { "1970-01-01 10:45:20.13789199",
+ "1970-01-01 22:17:59.635665198", "1969-12-31 13:14:39.109985421" };
- static String[] INVALID_STRINGS = { STRING_INVALID1, STRING_INVALID2,
- STRING_INVALID3 };
+ static String[] STRING_GMT_ARRAY = { STRING_TEST1, STRING_TEST2,
+ STRING_TEST3 };
- // Timezones
- static String TZ_LONDON = "GMT"; // GMT (!) PS London != GMT (?!?)
+ static String[] STRING_LA_ARRAY = { "02:45:20", "14:17:59", "05:14:40" };
- static String TZ_PACIFIC = "America/Los_Angeles"; // GMT - 8
+ static String[] STRING_JP_ARRAY = { "19:45:20", "07:17:59", "22:14:40" };
- static String TZ_JAPAN = "Asia/Tokyo"; // GMT + 9
+ static String[] INVALID_STRINGS = { STRING_INVALID1, STRING_INVALID2,
+ STRING_INVALID3 };
- static String[] TIMEZONES = { TZ_LONDON, TZ_PACIFIC, TZ_JAPAN };
+ // Timezones
+ static String TZ_LONDON = "GMT"; // GMT (!) PS London != GMT (?!?)
- static String[][] STRING_ARRAYS = { STRING_GMT_ARRAY, STRING_LA_ARRAY,
- STRING_JP_ARRAY };
+ static String TZ_PACIFIC = "America/Los_Angeles"; // GMT - 8
- /*
- * Constructor test
- */
- public void testTimestamplong() {
- Timestamp theTimestamp = new Timestamp(TIME_TEST1);
+ static String TZ_JAPAN = "Asia/Tokyo"; // GMT + 9
- // The Timestamp should have been created
- assertNotNull(theTimestamp);
- } // end method testTimestamplong
+ static String[] TIMEZONES = { TZ_LONDON, TZ_PACIFIC, TZ_JAPAN };
- /*
- * Constructor test
- */
- @SuppressWarnings("deprecation")
+ static String[][] STRING_ARRAYS = { STRING_GMT_ARRAY, STRING_LA_ARRAY,
+ STRING_JP_ARRAY };
+
+ /*
+ * Constructor test
+ */
+ public void testTimestamplong() {
+ Timestamp theTimestamp = new Timestamp(TIME_TEST1);
+
+ // The Timestamp should have been created
+ assertNotNull(theTimestamp);
+ } // end method testTimestamplong
+
+ /*
+ * Constructor test
+ */
+ @SuppressWarnings("deprecation")
public void testTimestampintintintintintintint() {
- int[][] valid = { { 99, 2, 14, 17, 52, 3, 213577212 }, // 0 valid
- { 0, 0, 1, 0, 0, 0, 0 }, // 1 valid
- { 106, 11, 31, 23, 59, 59, 999999999 }, // 2 valid
- { 106, 11, 31, 23, 59, 61, 999999999 }, // 5 Seconds out of
- // range
- { 106, 11, 31, 23, 59, -1, 999999999 }, // 6 Seconds out of
- // range
- { 106, 11, 31, 23, 61, 59, 999999999 }, // 7 Minutes out of
- // range
- { 106, 11, 31, 23, -1, 59, 999999999 }, // 8 Minutes out of
- // range
- { 106, 11, 31, 25, 59, 59, 999999999 }, // 9 Hours out of range
- { 106, 11, 31, -1, 59, 59, 999999999 }, // 10 Hours out of range
- { 106, 11, 35, 23, 59, 59, 999999999 }, // 11 Days out of range
- { 106, 11, -1, 23, 59, 59, 999999999 }, // 12 Days out of range
- { 106, 15, 31, 23, 59, 59, 999999999 }, // 13 Months out of
- // range
- { 106, -1, 31, 23, 59, 59, 999999999 }, // 14 Months out of
- // range
- { -10, 11, 31, 23, 59, 59, 999999999 }, // 15 valid - Years
- // negative
- };
-
- for (int[] element : valid) {
- Timestamp theTimestamp = new Timestamp(element[0],
- element[1], element[2], element[3],
- element[4], element[5], element[6]);
+ int[][] valid = { { 99, 2, 14, 17, 52, 3, 213577212 }, // 0 valid
+ { 0, 0, 1, 0, 0, 0, 0 }, // 1 valid
+ { 106, 11, 31, 23, 59, 59, 999999999 }, // 2 valid
+ { 106, 11, 31, 23, 59, 61, 999999999 }, // 5 Seconds out of
+ // range
+ { 106, 11, 31, 23, 59, -1, 999999999 }, // 6 Seconds out of
+ // range
+ { 106, 11, 31, 23, 61, 59, 999999999 }, // 7 Minutes out of
+ // range
+ { 106, 11, 31, 23, -1, 59, 999999999 }, // 8 Minutes out of
+ // range
+ { 106, 11, 31, 25, 59, 59, 999999999 }, // 9 Hours out of range
+ { 106, 11, 31, -1, 59, 59, 999999999 }, // 10 Hours out of range
+ { 106, 11, 35, 23, 59, 59, 999999999 }, // 11 Days out of range
+ { 106, 11, -1, 23, 59, 59, 999999999 }, // 12 Days out of range
+ { 106, 15, 31, 23, 59, 59, 999999999 }, // 13 Months out of
+ // range
+ { 106, -1, 31, 23, 59, 59, 999999999 }, // 14 Months out of
+ // range
+ { -10, 11, 31, 23, 59, 59, 999999999 }, // 15 valid - Years
+ // negative
+ };
+
+ for (int[] element : valid) {
+ Timestamp theTimestamp = new Timestamp(element[0], element[1],
+ element[2], element[3], element[4], element[5], element[6]);
assertNotNull("Timestamp not generated: ", theTimestamp);
} // end for
-
- int[][] invalid = {
- { 106, 11, 31, 23, 59, 59, 1999999999 },
- { 106, 11, 31, 23, 59, 59, -999999999 },
- };
+
+ int[][] invalid = { { 106, 11, 31, 23, 59, 59, 1999999999 },
+ { 106, 11, 31, 23, 59, 59, -999999999 }, };
for (int[] element : invalid) {
try {
- new Timestamp(element[0],
- element[1], element[2], element[3],
+ new Timestamp(element[0], element[1], element[2], element[3],
element[4], element[5], element[6]);
fail("Should throw IllegalArgumentException");
} catch (IllegalArgumentException e) {
@@ -166,376 +165,368 @@
}
}
- } // end method testTimestampintintintintintintint
+ } // end method testTimestampintintintintintintint
- /*
- * Method test for setTime
- */
- public void testSetTimelong() {
- // First set the timezone to GMT
- TimeZone.setDefault(TimeZone.getTimeZone("GMT"));
+ /*
+ * Method test for setTime
+ */
+ public void testSetTimelong() {
+ // First set the timezone to GMT
+ TimeZone.setDefault(TimeZone.getTimeZone("GMT"));
- Timestamp theTimestamp = new Timestamp(TIME_TEST1);
+ Timestamp theTimestamp = new Timestamp(TIME_TEST1);
- for (int i = 0; i < TIME_ARRAY.length; i++) {
- theTimestamp.setTime(TIME_ARRAY[i]);
+ for (int i = 0; i < TIME_ARRAY.length; i++) {
+ theTimestamp.setTime(TIME_ARRAY[i]);
- assertEquals(TIME_ARRAY[i], theTimestamp.getTime());
+ assertEquals(TIME_ARRAY[i], theTimestamp.getTime());
assertEquals(NANOS_ARRAY[i], theTimestamp.getNanos());
- } // end for
+ } // end for
- } // end method testsetTimelong
+ } // end method testsetTimelong
- /*
- * Method test for getTime
- */
- public void testGetTime() {
- // First set the timezone to GMT
- TimeZone.setDefault(TimeZone.getTimeZone("GMT"));
+ /*
+ * Method test for getTime
+ */
+ public void testGetTime() {
+ // First set the timezone to GMT
+ TimeZone.setDefault(TimeZone.getTimeZone("GMT"));
- for (long element : TIME_ARRAY) {
- Timestamp theTimestamp = new Timestamp(element);
+ for (long element : TIME_ARRAY) {
+ Timestamp theTimestamp = new Timestamp(element);
assertEquals(element, theTimestamp.getTime());
- } // end for
+ } // end for
- } // end method testgetTime
+ } // end method testgetTime
- /*
- * Method test for getYear
- */
- @SuppressWarnings("deprecation")
+ /*
+ * Method test for getYear
+ */
+ @SuppressWarnings("deprecation")
public void testGetYear() {
- for (int i = 0; i < TIME_ARRAY.length; i++) {
- Timestamp theTimestamp = new Timestamp(TIME_ARRAY[i]);
+ for (int i = 0; i < TIME_ARRAY.length; i++) {
+ Timestamp theTimestamp = new Timestamp(TIME_ARRAY[i]);
assertEquals(YEAR_ARRAY[i], theTimestamp.getYear());
- } // end for
+ } // end for
- } // end method testgetYear
+ } // end method testgetYear
- /*
- * Method test for getMonth
- */
- @SuppressWarnings("deprecation")
+ /*
+ * Method test for getMonth
+ */
+ @SuppressWarnings("deprecation")
public void testGetMonth() {
- for (int i = 0; i < TIME_ARRAY.length; i++) {
- Timestamp theTimestamp = new Timestamp(TIME_ARRAY[i]);
+ for (int i = 0; i < TIME_ARRAY.length; i++) {
+ Timestamp theTimestamp = new Timestamp(TIME_ARRAY[i]);
assertEquals(MONTH_ARRAY[i], theTimestamp.getMonth());
- } // end for
+ } // end for
- } // end method testgetMonth
+ } // end method testgetMonth
- /*
- * Method test for getDate
- */
- @SuppressWarnings("deprecation")
+ /*
+ * Method test for getDate
+ */
+ @SuppressWarnings("deprecation")
public void testGetDate() {
- for (int i = 0; i < TIME_ARRAY.length; i++) {
- Timestamp theTimestamp = new Timestamp(TIME_ARRAY[i]);
+ for (int i = 0; i < TIME_ARRAY.length; i++) {
+ Timestamp theTimestamp = new Timestamp(TIME_ARRAY[i]);
assertEquals(DATE_ARRAY[i], theTimestamp.getDate());
- } // end for
+ } // end for
- } // end method testgetDate
+ } // end method testgetDate
- /*
- * Method test for getHours
- */
- @SuppressWarnings("deprecation")
+ /*
+ * Method test for getHours
+ */
+ @SuppressWarnings("deprecation")
public void testGetHours() {
- for (int i = 0; i < TIME_ARRAY.length; i++) {
- Timestamp theTimestamp = new Timestamp(TIME_ARRAY[i]);
+ for (int i = 0; i < TIME_ARRAY.length; i++) {
+ Timestamp theTimestamp = new Timestamp(TIME_ARRAY[i]);
assertEquals(HOURS_ARRAY[i], theTimestamp.getHours());
- } // end for
+ } // end for
- } // end method testgetHours
+ } // end method testgetHours
- /*
- * Method test for getMinutes
- */
- @SuppressWarnings("deprecation")
+ /*
+ * Method test for getMinutes
+ */
+ @SuppressWarnings("deprecation")
public void testGetMinutes() {
- for (int i = 0; i < TIME_ARRAY.length; i++) {
- Timestamp theTimestamp = new Timestamp(TIME_ARRAY[i]);
+ for (int i = 0; i < TIME_ARRAY.length; i++) {
+ Timestamp theTimestamp = new Timestamp(TIME_ARRAY[i]);
assertEquals(MINUTES_ARRAY[i], theTimestamp.getMinutes());
- } // end for
+ } // end for
- } // end method testgetMinutes
+ } // end method testgetMinutes
- /*
- * Method test for getSeconds
- */
- @SuppressWarnings("deprecation")
+ /*
+ * Method test for getSeconds
+ */
+ @SuppressWarnings("deprecation")
public void testGetSeconds() {
- for (int i = 0; i < TIME_ARRAY.length; i++) {
- Timestamp theTimestamp = new Timestamp(TIME_ARRAY[i]);
+ for (int i = 0; i < TIME_ARRAY.length; i++) {
+ Timestamp theTimestamp = new Timestamp(TIME_ARRAY[i]);
assertEquals(SECONDS_ARRAY[i], theTimestamp.getSeconds());
- } // end for
+ } // end for
+
+ } // end method testgetSeconds
- } // end method testgetSeconds
+ /*
+ * Method test for valueOf
+ */
+ static String theExceptionMessage = "Timestamp format must be yyyy-mm-dd hh:mm:ss.fffffffff";
- /*
- * Method test for valueOf
- */
- static String theExceptionMessage = "Timestamp format must be yyyy-mm-dd hh:mm:ss.fffffffff";
-
- public void testValueOfString() {
- for (int i = 0; i < TIME_ARRAY.length; i++) {
- Timestamp theTimestamp = new Timestamp(TIME_ARRAY[i]);
- Timestamp theTimestamp2 = Timestamp.valueOf(STRING_GMT_ARRAY[i]);
+ public void testValueOfString() {
+ for (int i = 0; i < TIME_ARRAY.length; i++) {
+ Timestamp theTimestamp = new Timestamp(TIME_ARRAY[i]);
+ Timestamp theTimestamp2 = Timestamp.valueOf(STRING_GMT_ARRAY[i]);
assertEquals(theTimestamp, theTimestamp2);
- } // end for
+ } // end for
- // Test for a string in correct format but with number values out of
- // range
- Timestamp theTimestamp = Timestamp.valueOf(STRING_OUTRANGE);
+ // Test for a string in correct format but with number values out of
+ // range
+ Timestamp theTimestamp = Timestamp.valueOf(STRING_OUTRANGE);
assertNotNull(theTimestamp);
- /*
- * System.out.println("testValueOfString: outrange timestamp: " +
- * theTimestamp.toString() );
- */
-
- for (String element : INVALID_STRINGS) {
- try {
- Timestamp.valueOf(element);
- fail("Should throw IllegalArgumentException.");
- } catch (IllegalArgumentException e) {
- //expected
- } // end try
-
- } // end for
-
- } // end method testvalueOfString
-
- /*
- * Method test for valueOf
- */
- public void testValueOfString1() {
-
- Timestamp theReturn;
- long[] theReturnTime = { 38720231, 38720231, 80279000, -38720691,
- 38720000};
- int[] theReturnNanos = { 231000000, 231987654, 0, 309000000, 0,};
-
- String[] valid = {
- "1970-01-01 10:45:20.231",
- "1970-01-01 10:45:20.231987654",
- "1970-01-01 22:17:59.0",
- "1969-12-31 13:14:39.309",
- "1970-01-01 10:45:20",
- };
- String[] invalid = {
- null,
- "ABCDEFGHI",
- "233104", "1970-01-01 22:17:59.",
+ /*
+ * System.out.println("testValueOfString: outrange timestamp: " +
+ * theTimestamp.toString() );
+ */
+
+ for (String element : INVALID_STRINGS) {
+ try {
+ Timestamp.valueOf(element);
+ fail("Should throw IllegalArgumentException.");
+ } catch (IllegalArgumentException e) {
+ // expected
+ } // end try
+
+ } // end for
+
+ } // end method testvalueOfString
+
+ /*
+ * Method test for valueOf
+ */
+ public void testValueOfString1() {
+
+ Timestamp theReturn;
+ long[] theReturnTime = { 38720231, 38720231, 80279000, -38720691,
+ 38720000 };
+ int[] theReturnNanos = { 231000000, 231987654, 0, 309000000, 0, };
+
+ String[] valid = { "1970-01-01 10:45:20.231",
+ "1970-01-01 10:45:20.231987654", "1970-01-01 22:17:59.0",
+ "1969-12-31 13:14:39.309", "1970-01-01 10:45:20", };
+ String[] invalid = { null, "ABCDEFGHI", "233104",
+ "1970-01-01 22:17:59.",
"1970-01-01 10:45:20.231987654690645322",
"1970-01-01 10:45:20&231987654",
"1970-01-01 10:45:20.-31987654",
- "1970-01-01 10:45:20.ABCD87654",
- "21-43-48",
- };
-
- for (int i = 0; i < valid.length; i++) {
- theReturn = Timestamp.valueOf(valid[i]);
- assertEquals(theReturnTime[i], theReturn.getTime());
- assertEquals(theReturnNanos[i], theReturn.getNanos());
- } // end for
+ "1970-01-01 10:45:20.ABCD87654", "21-43-48", };
+
+ for (int i = 0; i < valid.length; i++) {
+ theReturn = Timestamp.valueOf(valid[i]);
+ assertEquals(theReturnTime[i], theReturn.getTime());
+ assertEquals(theReturnNanos[i], theReturn.getNanos());
+ } // end for
for (String element : invalid) {
try {
theReturn = Timestamp.valueOf(element);
fail("Should throw IllegalArgumentException.");
} catch (IllegalArgumentException e) {
- //expected
+ // expected
}
}
- } // end method testValueOfString
+ } // end method testValueOfString
- /*
- * Method test for toString
- */
- public void testToString() {
- for (int i = 0; i < TIME_ARRAY.length; i++) {
- Timestamp theTimestamp = new Timestamp(TIME_ARRAY[i]);
+ /*
+ * Method test for toString
+ */
+ public void testToString() {
+ for (int i = 0; i < TIME_ARRAY.length; i++) {
+ Timestamp theTimestamp = new Timestamp(TIME_ARRAY[i]);
assertEquals(STRING_GMT_ARRAY[i], theTimestamp.toString());
- } // end for
+ } // end for
- } // end method testtoString
+ } // end method testtoString
- /*
- * Method test for getNanos
- */
- public void testGetNanos() {
- for (int i = 0; i < TIME_ARRAY.length; i++) {
- Timestamp theTimestamp = new Timestamp(TIME_ARRAY[i]);
+ /*
+ * Method test for getNanos
+ */
+ public void testGetNanos() {
+ for (int i = 0; i < TIME_ARRAY.length; i++) {
+ Timestamp theTimestamp = new Timestamp(TIME_ARRAY[i]);
assertEquals(NANOS_ARRAY[i], theTimestamp.getNanos());
- } // end for
+ } // end for
- } // end method testgetNanos
+ } // end method testgetNanos
- /*
- * Method test for setNanos
- */
- public void testSetNanosint() {
- int[] NANOS_INVALID = { -137891990, 1635665198, -1 };
- for (int i = 0; i < TIME_ARRAY.length; i++) {
- Timestamp theTimestamp = new Timestamp(TIME_ARRAY[i]);
+ /*
+ * Method test for setNanos
+ */
+ public void testSetNanosint() {
+ int[] NANOS_INVALID = { -137891990, 1635665198, -1 };
+ for (int i = 0; i < TIME_ARRAY.length; i++) {
+ Timestamp theTimestamp = new Timestamp(TIME_ARRAY[i]);
- theTimestamp.setNanos(NANOS_ARRAY2[i]);
+ theTimestamp.setNanos(NANOS_ARRAY2[i]);
assertEquals(NANOS_ARRAY2[i], theTimestamp.getNanos());
- // Also check that these Timestamps with detailed nanos values
- // convert to
- // strings correctly
+ // Also check that these Timestamps with detailed nanos values
+ // convert to
+ // strings correctly
assertEquals(STRING_NANOS_ARRAY[i], theTimestamp.toString());
- } // end for
+ } // end for
- for (int i = 0; i < NANOS_INVALID.length; i++) {
- Timestamp theTimestamp = new Timestamp(TIME_ARRAY[i]);
- int originalNanos = theTimestamp.getNanos();
- try {
- theTimestamp.setNanos(NANOS_INVALID[i]);
- fail("Should throw IllegalArgumentException");
- } catch (IllegalArgumentException e) {
- //expected
- } // end try
+ for (int i = 0; i < NANOS_INVALID.length; i++) {
+ Timestamp theTimestamp = new Timestamp(TIME_ARRAY[i]);
+ int originalNanos = theTimestamp.getNanos();
+ try {
+ theTimestamp.setNanos(NANOS_INVALID[i]);
+ fail("Should throw IllegalArgumentException");
+ } catch (IllegalArgumentException e) {
+ // expected
+ } // end try
assertEquals(originalNanos, theTimestamp.getNanos());
- } // end for
+ } // end for
+
+ } // end method testsetNanosint
+
+ /*
+ * Method test for equals
+ */
+ public void testEqualsTimestamp() {
+ for (long element : TIME_ARRAY) {
+ Timestamp theTimestamp = new Timestamp(element);
+ Timestamp theTimestamp2 = new Timestamp(element);
+
+ assertTrue(theTimestamp.equals(theTimestamp2));
+ } // end for
- } // end method testsetNanosint
+ Timestamp theTest = new Timestamp(TIME_COMPARE);
+
+ for (long element : TIME_ARRAY) {
+ Timestamp theTimestamp = new Timestamp(element);
+ assertFalse(theTimestamp.equals(theTest));
+ } // end for
- /*
- * Method test for equals
- */
- public void testEqualsTimestamp() {
- for (long element : TIME_ARRAY) {
- Timestamp theTimestamp = new Timestamp(element);
- Timestamp theTimestamp2 = new Timestamp(element);
-
- assertTrue(theTimestamp.equals(theTimestamp2));
- } // end for
-
- Timestamp theTest = new Timestamp(TIME_COMPARE);
-
- for (long element : TIME_ARRAY) {
- Timestamp theTimestamp = new Timestamp(element);
- assertFalse(theTimestamp.equals(theTest));
- } // end for
-
// Regression for HARMONY-526
assertFalse(new Timestamp(0).equals((Timestamp) null));
- } // end method testequalsTimestamp
+ } // end method testequalsTimestamp
- /*
- * Method test for equals
- */
- public void testEqualsObject() {
- for (long element : TIME_ARRAY) {
- Timestamp theTimestamp = new Timestamp(element);
+ /*
+ * Method test for equals
+ */
+ public void testEqualsObject() {
+ for (long element : TIME_ARRAY) {
+ Timestamp theTimestamp = new Timestamp(element);
- Object theTimestamp2 = new Timestamp(element);
+ Object theTimestamp2 = new Timestamp(element);
- assertTrue(theTimestamp.equals(theTimestamp2));
- } // end for
+ assertTrue(theTimestamp.equals(theTimestamp2));
+ } // end for
- Object theTest = new Timestamp(TIME_COMPARE);
+ Object theTest = new Timestamp(TIME_COMPARE);
- for (long element : TIME_ARRAY) {
- Timestamp theTimestamp = new Timestamp(element);
+ for (long element : TIME_ARRAY) {
+ Timestamp theTimestamp = new Timestamp(element);
- assertFalse(theTimestamp.equals(theTest));
- } // end for
+ assertFalse(theTimestamp.equals(theTest));
+ } // end for
- Object nastyTest = new String("Test ");
- Timestamp theTimestamp = new Timestamp(TIME_ARRAY[1]);
- assertFalse(theTimestamp.equals(nastyTest));
+ Object nastyTest = new String("Test ");
+ Timestamp theTimestamp = new Timestamp(TIME_ARRAY[1]);
+ assertFalse(theTimestamp.equals(nastyTest));
// Regression for HARMONY-526
assertFalse(new Timestamp(0).equals((Object) null));
- } // end method testequalsObject
+ } // end method testequalsObject
- /*
- * Method test for before
- */
- public void testBeforeTimestamp() {
- Timestamp theTest = new Timestamp(TIME_LATE);
-
- for (long element : TIME_ARRAY) {
- Timestamp theTimestamp = new Timestamp(element);
-
- assertTrue(theTimestamp.before(theTest));
- } // end for
+ /*
+ * Method test for before
+ */
+ public void testBeforeTimestamp() {
+ Timestamp theTest = new Timestamp(TIME_LATE);
- theTest = new Timestamp(TIME_EARLY);
+ for (long element : TIME_ARRAY) {
+ Timestamp theTimestamp = new Timestamp(element);
- for (long element : TIME_ARRAY) {
- Timestamp theTimestamp = new Timestamp(element);
+ assertTrue(theTimestamp.before(theTest));
+ } // end for
- assertFalse(theTimestamp.before(theTest));
- } // end for
+ theTest = new Timestamp(TIME_EARLY);
- for (long element : TIME_ARRAY) {
- theTest = new Timestamp(element);
- Timestamp theTimestamp = new Timestamp(element);
+ for (long element : TIME_ARRAY) {
+ Timestamp theTimestamp = new Timestamp(element);
- assertFalse(theTimestamp.before(theTest));
- theTest.setNanos(theTest.getNanos() + 1);
- assertTrue(theTimestamp.before(theTest));
- } // end for
+ assertFalse(theTimestamp.before(theTest));
+ } // end for
- } // end method testbeforeTimestamp
+ for (long element : TIME_ARRAY) {
+ theTest = new Timestamp(element);
+ Timestamp theTimestamp = new Timestamp(element);
+
+ assertFalse(theTimestamp.before(theTest));
+ theTest.setNanos(theTest.getNanos() + 1);
+ assertTrue(theTimestamp.before(theTest));
+ } // end for
- /*
- * Method test for after
- */
- public void testAfterTimestamp() {
- Timestamp theTest = new Timestamp(TIME_LATE);
+ } // end method testbeforeTimestamp
- for (long element : TIME_ARRAY) {
- Timestamp theTimestamp = new Timestamp(element);
+ /*
+ * Method test for after
+ */
+ public void testAfterTimestamp() {
+ Timestamp theTest = new Timestamp(TIME_LATE);
- assertFalse(theTimestamp.after(theTest));
- } // end for
+ for (long element : TIME_ARRAY) {
+ Timestamp theTimestamp = new Timestamp(element);
- theTest = new Timestamp(TIME_EARLY);
+ assertFalse(theTimestamp.after(theTest));
+ } // end for
- for (long element : TIME_ARRAY) {
- Timestamp theTimestamp = new Timestamp(element);
+ theTest = new Timestamp(TIME_EARLY);
- assertTrue(theTimestamp.after(theTest));
- } // end for
+ for (long element : TIME_ARRAY) {
+ Timestamp theTimestamp = new Timestamp(element);
- for (long element : TIME_ARRAY) {
- theTest = new Timestamp(element);
- Timestamp theTimestamp = new Timestamp(element);
+ assertTrue(theTimestamp.after(theTest));
+ } // end for
- assertFalse(theTimestamp.after(theTest));
- theTimestamp.setNanos(theTimestamp.getNanos() + 1);
- assertTrue(theTimestamp.after(theTest));
- } // end for
+ for (long element : TIME_ARRAY) {
+ theTest = new Timestamp(element);
+ Timestamp theTimestamp = new Timestamp(element);
+
+ assertFalse(theTimestamp.after(theTest));
+ theTimestamp.setNanos(theTimestamp.getNanos() + 1);
+ assertTrue(theTimestamp.after(theTest));
+ } // end for
- } // end method testafterTimestamp
+ } // end method testafterTimestamp
- /*
- * Method test for compareTo
- */
- @SuppressWarnings("deprecation")
+ /*
+ * Method test for compareTo
+ */
+ @SuppressWarnings("deprecation")
public void testCompareToTimestamp() {
- Timestamp theTest = new Timestamp(TIME_EARLY);
- Timestamp theTest2 = new Timestamp(TIME_LATE);
+ Timestamp theTest = new Timestamp(TIME_EARLY);
+ Timestamp theTest2 = new Timestamp(TIME_LATE);
+
+ for (long element : TIME_ARRAY) {
+ Timestamp theTimestamp = new Timestamp(element);
+ Timestamp theTimestamp2 = new Timestamp(element);
+
+ assertTrue(theTimestamp.compareTo(theTest) > 0);
+ assertTrue(theTimestamp.compareTo(theTest2) < 0);
+ assertEquals(0, theTimestamp.compareTo(theTimestamp2));
+ } // end for
- for (long element : TIME_ARRAY) {
- Timestamp theTimestamp = new Timestamp(element);
- Timestamp theTimestamp2 = new Timestamp(element);
-
- assertTrue(theTimestamp.compareTo(theTest) > 0);
- assertTrue(theTimestamp.compareTo(theTest2) < 0);
- assertEquals(0, theTimestamp.compareTo(theTimestamp2));
- } // end for
-
Timestamp t1 = new Timestamp(-1L);
Timestamp t2 = new Timestamp(-1L);
-
+
t1.setTime(Long.MIN_VALUE);
t2.setDate(Integer.MIN_VALUE);
assertEquals(1, t1.compareTo(t2));
@@ -551,42 +542,42 @@
assertEquals(0, t1.compareTo(t2));
assertEquals(0, t2.compareTo(t1));
- } // end method testcompareToTimestamp
+ } // end method testcompareToTimestamp
+
+ /**
+ * @tests java.sql.Timestamp#compareTo(java.util.Date)
+ */
+ public void testCompareToDate() {
+ Date theTest = new Timestamp(TIME_EARLY);
+ Date theTest2 = new Timestamp(TIME_LATE);
+
+ for (long element : TIME_ARRAY) {
+ Timestamp theTimestamp = new Timestamp(element);
+ Date theTimestamp2 = new Timestamp(element);
+
+ assertTrue(theTimestamp.compareTo(theTest) > 0);
+ assertTrue(theTimestamp.compareTo(theTest2) < 0);
+ assertEquals(0, theTimestamp.compareTo(theTimestamp2));
+ } // end for
- /**
- * @tests java.sql.Timestamp#compareTo(java.util.Date)
- */
- public void testCompareToDate() {
- Date theTest = new Timestamp(TIME_EARLY);
- Date theTest2 = new Timestamp(TIME_LATE);
-
- for (long element : TIME_ARRAY) {
- Timestamp theTimestamp = new Timestamp(element);
- Date theTimestamp2 = new Timestamp(element);
-
- assertTrue(theTimestamp.compareTo(theTest) > 0);
- assertTrue(theTimestamp.compareTo(theTest2) < 0);
- assertEquals(0, theTimestamp.compareTo(theTimestamp2));
- } // end for
-
- Date nastyTest = new Date();
- Timestamp theTimestamp = new Timestamp(TIME_ARRAY[1]);
- try {
- theTimestamp.compareTo(nastyTest);
+ Date nastyTest = new Date();
+ Timestamp theTimestamp = new Timestamp(TIME_ARRAY[1]);
+ try {
+ theTimestamp.compareTo(nastyTest);
// It throws ClassCastException in JDK 1.5.0_06 but in 1.5.0_07 it
// does not throw the expected exception.
fail("testCompareToObject: Did not get expected ClassCastException");
} catch (ClassCastException e) {
- // Should get here
- /*
- * System.out.println("testCompareToObject: ClassCastException as
- * expected"); System.out.println("Exception message: " +
- * e.getMessage());
- */
- } // end try
+ // Should get here
+ /*
+ * System.out.println("testCompareToObject: ClassCastException as
+ * expected"); System.out.println("Exception message: " +
+ * e.getMessage());
+ */
+ } // end try
+
+ } // end method testcompareToObject
- } // end method testcompareToObject
-
/**
* @tests serialization/deserialization compatibility.
*/
@@ -602,7 +593,7 @@
Timestamp object = new Timestamp(100L);
SerializationTest.verifyGolden(this, object);
}
-
+
/**
* @tests java.sql.Timestamp#toString()
*/
@@ -620,5 +611,5 @@
Timestamp t4 = new Timestamp(Long.MIN_VALUE + 808);
assertEquals("292269055-12-02 16:47:05.0", t4.toString()); //$NON-NLS-1$
}
-
+
} // end class TimestampTest
|