commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From stevencasw...@apache.org
Subject cvs commit: jakarta-commons-sandbox/dbutils/src/test/org/apache/commons/dbutils/driver SqlNullCheckedResultSetTestCase.java StringTrimmedResultSetTestCase.java
Date Sun, 02 Feb 2003 17:09:43 GMT
stevencaswell    2003/02/02 09:09:43

  Added:       dbutils/src/test/org/apache/commons/dbutils/driver
                        SqlNullCheckedResultSetTestCase.java
                        StringTrimmedResultSetTestCase.java
  Log:
  initial import
  
  Revision  Changes    Path
  1.1                  jakarta-commons-sandbox/dbutils/src/test/org/apache/commons/dbutils/driver/SqlNullCheckedResultSetTestCase.java
  
  Index: SqlNullCheckedResultSetTestCase.java
  ===================================================================
  
  package org.apache.commons.dbutils.driver;
  
  import java.io.ByteArrayInputStream;
  import java.io.CharArrayReader;
  import java.io.InputStream;
  import java.io.Reader;
  import java.math.BigDecimal;
  import java.sql.Array;
  import java.sql.Blob;
  import java.sql.Clob;
  import java.sql.Ref;
  import java.sql.SQLException;
  import java.sql.Statement;
  import java.sql.Time;
  import java.sql.Timestamp;
  import java.util.Calendar;
  import java.util.Map;
  import junit.framework.Test;
  import junit.framework.TestSuite;
  import junit.textui.TestRunner;
  import org.apache.commons.dbutils.driver.SqlNullCheckedResultSet;
  import org.apache.commons.dbutils.mockdriver.MockConnection;
  import org.apache.commons.dbutils.mockdriver.MockResultSet;
  import org.apache.commons.dbutils.mockdriver.MockStatement;
  
  /**
   * Test cases for
   * <code>SqlNullCheckedResultSetTestCase</code>
   * class.
   *
   * @author  <a href="stevencaswell@apache.org">Steven Caswell</a>
   * @version $Id: SqlNullCheckedResultSetTestCase.java,v 1.1 2003/02/02 17:09:42 stevencaswell Exp $
   */
  public class SqlNullCheckedResultSetTestCase extends junit.framework.TestCase
  {
      protected SqlNullCheckedResultSet rs = null;
      
      /**
       * Constructs a new instance of
       * <code>SqlNullCheckedResultSetTestCase</code>
       * with the specified name.
       *
       * @param name the test case name
       */
      public SqlNullCheckedResultSetTestCase(String name) {
          super(name);
      }
      
      /**
       * Sets up instance variables required by this test case.
       */
      public void setUp() {
          MockConnection connection = new MockConnection();
          MockStatement statement = new MockStatement(connection);
          rs = new SqlNullCheckedResultSet(new SqlNullUncheckedMockResultSet(statement));
      }
      
      /**
       * Builds the test suite.
       *
       * @return the test suite
       */
      public static Test suite() {
          return new TestSuite(SqlNullCheckedResultSetTestCase.class);
      }
      
      /**
       * Tears down instance variables required by this test case.
       */
      public void tearDown() {
      }
      
      /**
       * Tests the getAsciiStream implementation.
       */
      public void testGetAsciiStream() {
          try {
              assertNull("get ascii stream index is null", rs.getAsciiStream(1));
              assertTrue("get ascii stream was SQL NULL", rs.wasNull());
              assertNull("get ascii stream column is null", rs.getAsciiStream("column"));
              assertTrue("get ascii stream was SQL NULL", rs.wasNull());
              // Set what gets returned to something other than the default
              InputStream stream = new ByteArrayInputStream(new byte[0]);
              rs.setNullAsciiStream(stream);
              assertNotNull("get ascii stream index not null", rs.getAsciiStream(1));
              assertEquals("get ascii stream when SQL NULL", stream, rs.getAsciiStream(1));
              assertNotNull("get ascii stream column not null", rs.getAsciiStream("column"));
              assertEquals("get ascii stream when SQL NULL", stream, rs.getAsciiStream("column"));
          }
          catch(Exception e) {
              fail("Could not test: " + e.getMessage());
          }
      }
      
      /**
       * Tests the getBigDecimal implementation.
       */
      public void testGetBigDecimal() {
          try {
              assertNull("get big decimal index is null", rs.getBigDecimal(1));
              assertTrue("get big decimal was SQL NULL", rs.wasNull());
              assertNull("get big decimal column is null", rs.getBigDecimal("column"));
              assertTrue("get big decimal was SQL NULL", rs.wasNull());
              // Set what gets returned to something other than the default
              BigDecimal bd = new BigDecimal(5.0);
              rs.setNullBigDecimal(bd);
              assertNotNull("get big decimal index not null", rs.getBigDecimal(1));
              assertEquals("get big decimal when SQL NULL", bd, rs.getBigDecimal(1));
              assertNotNull("get big decimal column not null", rs.getBigDecimal("column"));
              assertEquals("get big decimal when SQL NULL", bd, rs.getBigDecimal("column"));
          }
          catch(Exception e) {
              fail("Could not test: " + e.getMessage());
          }
      }
      
      /**
       * Tests the getBinaryStream implementation.
       */
      public void testGetBinaryStream() {
          try {
              assertNull("get binary stream index is null", rs.getBinaryStream(1));
              assertTrue("get binary stream was SQL NULL", rs.wasNull());
              assertNull("get binary stream column is null", rs.getBinaryStream("column"));
              assertTrue("get binary stream was SQL NULL", rs.wasNull());
              // Set what gets returned to something other than the default
              InputStream stream = new ByteArrayInputStream(new byte[0]);
              rs.setNullBinaryStream(stream);
              assertNotNull("get binary stream index not null", rs.getBinaryStream(1));
              assertEquals("get binary stream when SQL NULL", stream, rs.getBinaryStream(1));
              assertNotNull("get binary stream column not null", rs.getBinaryStream("column"));
              assertEquals("get binary stream when SQL NULL", stream, rs.getBinaryStream("column"));
          }
          catch(Exception e) {
              fail("Could not test: " + e.getMessage());
          }
      }
      
      /**
       * Tests the getBlob implementation.
       */
      public void testGetBlob() {
          try {
              assertNull("get blob index is null", rs.getBlob(1));
              assertTrue("get blob was SQL NULL", rs.wasNull());
              assertNull("get blob column is null", rs.getBlob("column"));
              assertTrue("get blob was SQL NULL", rs.wasNull());
              // Set what gets returned to something other than the default
              Blob blob = new SqlNullCheckedResultSetMockBlob();
              rs.setNullBlob(blob);
              assertNotNull("get blob index not null", rs.getBlob(1));
              assertEquals("get blob when SQL NULL", blob, rs.getBlob(1));
              assertNotNull("get blob column not null", rs.getBlob("column"));
              assertEquals("get blob when SQL NULL", blob, rs.getBlob("column"));
          }
          catch(Exception e) {
              fail("Could not test: " + e.getMessage());
          }
      }
      
      /**
       * Tests the getBoolean implementation.
       */
      public void testGetBoolean() {
          try {
              assertEquals("get boolean index", false, rs.getBoolean(1));
              assertTrue("get boolean was SQL NULL", rs.wasNull());
              assertEquals("get boolean column", false, rs.getBoolean("column"));
              assertTrue("get boolean was SQL NULL", rs.wasNull());
              // Set what gets returned to something other than the default
              rs.setNullBoolean(true);
              assertEquals("get boolean when SQL NULL", true, rs.getBoolean(1));
              assertEquals("get boolean when SQL NULL", true, rs.getBoolean("column"));
          }
          catch(Exception e) {
              fail("Could not test: " + e.getMessage());
          }
      }
      
      /**
       * Tests the getByte implementation.
       */
      public void testGetByte() {
          try {
              assertEquals("get byte index", (byte) 0, rs.getByte(1));
              assertTrue("get byte was SQL NULL", rs.wasNull());
              assertEquals("get byte column", (byte) 0, rs.getByte("column"));
              assertTrue("get byte was SQL NULL", rs.wasNull());
              // Set what gets returned to something other than the default
              byte b = (byte) 10;
              rs.setNullByte(b);
              assertEquals("get byte when SQL NULL", b, rs.getByte(1));
              assertEquals("get byte when SQL NULL", b, rs.getByte("column"));
          }
          catch(Exception e) {
              fail("Could not test: " + e.getMessage());
          }
      }
      
      /**
       * Tests the getByte implementation.
       */
      public void testGetBytes() {
          try {
              assertNull("get bytes index is null", rs.getBytes(1));
              assertTrue("get bytes was SQL NULL", rs.wasNull());
              assertNull("get bytes column is null", rs.getBytes("column"));
              assertTrue("get bytes was SQL NULL", rs.wasNull());
              // Set what gets returned to something other than the default
              byte[] b = new byte[5];
              for(int i = 0; i < 5; i++) {
                  b[0] = (byte) i;
              }
              rs.setNullBytes(b);
              assertNotNull("get bytes index not null", rs.getBytes(1));
              assertEquals("get bytes when SQL NULL", b, rs.getBytes(1));
              assertNotNull("get bytes column not null", rs.getBytes("column"));
              assertEquals("get bytes when SQL NULL", b, rs.getBytes("column"));
          }
          catch(Exception e) {
              fail("Could not test: " + e.getMessage());
          }
      }
      
      /**
       * Tests the getCharacterStream implementation.
       */
      public void testGetCharacterStream() {
          try {
              assertNull("get character stream index is null", rs.getCharacterStream(1));
              assertTrue("get character stream was SQL NULL", rs.wasNull());
              assertNull("get character stream column is null", rs.getCharacterStream("column"));
              assertTrue("get character stream was SQL NULL", rs.wasNull());
              // Set what gets returned to something other than the default
              Reader reader = new CharArrayReader("this is a string".toCharArray());
              rs.setNullCharacterStream(reader);
              assertNotNull("get character stream index not null", rs.getCharacterStream(1));
              assertEquals("get character stream when SQL NULL", reader, rs.getCharacterStream(1));
              assertNotNull("get character stream column not null", rs.getCharacterStream("column"));
              assertEquals("get character stream when SQL NULL", reader, rs.getCharacterStream("column"));
          }
          catch(Exception e) {
              fail("Could not test: " + e.getMessage());
          }
      }
      
      /**
       * Tests the getClob implementation.
       */
      public void testGetClob() {
          try {
              assertNull("get clob index is null", rs.getClob(1));
              assertTrue("get clob was SQL NULL", rs.wasNull());
              assertNull("get clob column is null", rs.getClob("column"));
              assertTrue("get clob was SQL NULL", rs.wasNull());
              // Set what gets returned to something other than the default
              Clob clob = new SqlNullCheckedResultSetMockClob();
              rs.setNullClob(clob);
              assertNotNull("get clob index not null", rs.getClob(1));
              assertEquals("get clob when SQL NULL", clob, rs.getClob(1));
              assertNotNull("get clob column not null", rs.getClob("column"));
              assertEquals("get clob when SQL NULL", clob, rs.getClob("column"));
          }
          catch(Exception e) {
              fail("Could not test: " + e.getMessage());
          }
      }
      
      /**
       * Tests the getDate implementation.
       */
      public void testGetDate() {
          try {
              assertNull("get date index is null", rs.getDate(1));
              assertTrue("get date was SQL NULL", rs.wasNull());
              assertNull("get date column is null", rs.getDate("column"));
              assertTrue("get date was SQL NULL", rs.wasNull());
              assertNull("get date index,calendar is null", rs.getDate(1, Calendar.getInstance()));
              assertTrue("get date was SQL NULL", rs.wasNull());
              assertNull("get date column,calendar is null", rs.getDate("column", Calendar.getInstance()));
              assertTrue("get date was SQL NULL", rs.wasNull());
              // Set what gets returned to something other than the default
              java.sql.Date date = new java.sql.Date(new java.util.Date().getTime());
              rs.setNullDate(date);
              assertNotNull("get date index not null", rs.getDate(1));
              assertEquals("get date when SQL NULL", date, rs.getDate(1));
              assertNotNull("get date column not null", rs.getDate("column"));
              assertEquals("get date when SQL NULL", date, rs.getDate("column"));
              assertNotNull("get date index,calendar not null", rs.getDate(1, Calendar.getInstance()));
              assertEquals("get date when SQL NULL", date, rs.getDate(1, Calendar.getInstance()));
              assertNotNull("get date column,calendar not null", rs.getDate("column", Calendar.getInstance()));
              assertEquals("get date when SQL NULL", date, rs.getDate("column", Calendar.getInstance()));
          }
          catch(Exception e) {
              fail("Could not test: " + e.getMessage());
          }
      }
      
      /**
       * Tests the getDouble implementation.
       */
      public void testGetDouble() {
          try {
              assertEquals("get double index", (double) 0.0, rs.getDouble(1), 0.0);
              assertTrue("get double was SQL NULL", rs.wasNull());
              assertEquals("get double column", (double) 0.0, rs.getDouble("column"), 0.0);
              assertTrue("get double was SQL NULL", rs.wasNull());
              // Set what gets returned to something other than the default
              double d = (double) 10.0;
              rs.setNullDouble(d);
              assertEquals("get double when SQL NULL", d, rs.getDouble(1), 0.0);
              assertEquals("get double when SQL NULL", d, rs.getDouble("column"), 0.0);
          }
          catch(Exception e) {
              fail("Could not test: " + e.getMessage());
          }
      }
      
      /**
       * Tests the getFloat implementation.
       */
      public void testGetFloat() {
          try {
              assertEquals("get float index", (float) 0, rs.getFloat(1), 0.0);
              assertTrue("get float was SQL NULL", rs.wasNull());
              assertEquals("get float column", (float) 0, rs.getFloat("column"), 0.0);
              assertTrue("get float was SQL NULL", rs.wasNull());
              // Set what gets returned to something other than the default
              float f = (float) 10.0;
              rs.setNullFloat(f);
              assertEquals("get float when SQL NULL", f, rs.getFloat(1), 0.0);
              assertEquals("get float when SQL NULL", f, rs.getFloat("column"), 0.0);
          }
          catch(Exception e) {
              fail("Could not test: " + e.getMessage());
          }
      }
      
      /**
       * Tests the getInt implementation.
       */
      public void testGetInt() {
          try {
              assertEquals("get int index", (int) 0, rs.getInt(1));
              assertTrue("get int was SQL NULL", rs.wasNull());
              assertEquals("get int column", (int) 0, rs.getInt("column"));
              assertTrue("get int was SQL NULL", rs.wasNull());
              // Set what gets returned to something other than the default
              int i = (int) 10;
              rs.setNullInt(i);
              assertEquals("get int when SQL NULL", i, rs.getInt(1));
              assertEquals("get int when SQL NULL", i, rs.getInt("column"));
          }
          catch(Exception e) {
              fail("Could not test: " + e.getMessage());
          }
      }
      
      /**
       * Tests the getLong implementation.
       */
      public void testGetLong() {
          try {
              assertEquals("get long index", (long) 0, rs.getLong(1));
              assertTrue("get long was SQL NULL", rs.wasNull());
              assertEquals("get long column", (long) 0, rs.getLong("column"));
              assertTrue("get long was SQL NULL", rs.wasNull());
              // Set what gets returned to something other than the default
              long l = (long) 10;
              rs.setNullLong(l);
              assertEquals("get long when SQL NULL", l, rs.getLong(1));
              assertEquals("get long when SQL NULL", l, rs.getLong("column"));
          }
          catch(Exception e) {
              fail("Could not test: " + e.getMessage());
          }
      }
      
      /**
       * Tests the getObject implementation.
       */
      public void testGetObject() {
          try {
              assertNull("get object index is null", rs.getObject(1));
              assertTrue("get object was SQL NULL", rs.wasNull());
              assertNull("get object column is null", rs.getObject("column"));
              assertTrue("get object was SQL NULL", rs.wasNull());
              assertNull("get object index,map is null", rs.getObject(1, (Map) null));
              assertTrue("get object was SQL NULL", rs.wasNull());
              assertNull("get object column,map is null", rs.getObject("column", (Map) null));
              assertTrue("get object was SQL NULL", rs.wasNull());
              // Set what gets returned to something other than the default
              Object o = new Object();
              rs.setNullObject(o);
              assertNotNull("get object index not null", rs.getObject(1));
              assertEquals("get object when SQL NULL", o, rs.getObject(1));
              assertNotNull("get object column not null", rs.getObject("column"));
              assertEquals("get object when SQL NULL", o, rs.getObject("column"));
              assertNotNull("get object index,map not null", rs.getObject(1, (Map) null));
              assertEquals("get object when SQL NULL", o, rs.getObject(1, (Map) null));
              assertNotNull("get object column,map not null", rs.getObject("column", (Map) null));
              assertEquals("get object when SQL NULL", o, rs.getObject("column", (Map) null));
          }
          catch(Exception e) {
              fail("Could not test: " + e.getMessage());
          }
      }
      
      /**
       * Tests the getRef implementation.
       */
      public void testGetRef() {
          try {
              assertNull("get ref index is null", rs.getRef(1));
              assertTrue("get ref was SQL NULL", rs.wasNull());
              assertNull("get ref column is null", rs.getRef("column"));
              assertTrue("get ref was SQL NULL", rs.wasNull());
              // Set what gets returned to something other than the default
              Ref ref = new SqlNullCheckedResultSetMockRef();
              rs.setNullRef(ref);
              assertNotNull("get ref index not null", rs.getRef(1));
              assertEquals("get ref when SQL NULL", ref, rs.getRef(1));
              assertNotNull("get ref column not null", rs.getRef("column"));
              assertEquals("get ref when SQL NULL", ref, rs.getRef("column"));
          }
          catch(Exception e) {
              fail("Could not test: " + e.getMessage());
          }
      }
      
      /**
       * Tests the getShort implementation.
       */
      public void testGetShort() {
          try {
              assertEquals("get short index", (short) 0, rs.getShort(1));
              assertTrue("get short was SQL NULL", rs.wasNull());
              assertEquals("get short column", (short) 0, rs.getShort("column"));
              assertTrue("get short was SQL NULL", rs.wasNull());
              // Set what gets returned to something other than the default
              short s = (short) 10;
              rs.setNullShort(s);
              assertEquals("get short when SQL NULL", s, rs.getShort(1));
              assertEquals("get short when SQL NULL", s, rs.getShort("column"));
          }
          catch(Exception e) {
              fail("Could not test: " + e.getMessage());
          }
      }
      
      /**
       * Tests the getString implementation.
       */
      public void testGetString() {
          try {
              assertEquals("get string index", null, rs.getString(1));
              assertTrue("get string was SQL NULL", rs.wasNull());
              assertEquals("get string column", null, rs.getString("column"));
              assertTrue("get string was SQL NULL", rs.wasNull());
              // Set what gets returned to something other than the default
              String s = "hello, world";
              rs.setNullString(s);
              assertEquals("get string when SQL NULL", s, rs.getString(1));
              assertEquals("get string when SQL NULL", s, rs.getString("column"));
          }
          catch(Exception e) {
              fail("Could not test: " + e.getMessage());
          }
      }
      
      /**
       * Tests the getTime implementation.
       */
      public void testGetTime() {
          try {
              assertNull("get time index is null", rs.getTime(1));
              assertTrue("get time was SQL NULL", rs.wasNull());
              assertNull("get time column is null", rs.getTime("column"));
              assertTrue("get time was SQL NULL", rs.wasNull());
              assertNull("get time index,calendar is null", rs.getTime(1, Calendar.getInstance()));
              assertTrue("get time was SQL NULL", rs.wasNull());
              assertNull("get time column,calendar is null", rs.getTime("column", Calendar.getInstance()));
              assertTrue("get time was SQL NULL", rs.wasNull());
              // Set what gets returned to something other than the default
              Time time = new Time(new java.util.Date().getTime());
              rs.setNullTime(time);
              assertNotNull("get time index not null", rs.getTime(1));
              assertEquals("get time when SQL NULL", time, rs.getTime(1));
              assertNotNull("get time column not null", rs.getTime("column"));
              assertEquals("get time when SQL NULL", time, rs.getTime("column"));
              assertNotNull("get time index,calendar not null", rs.getTime(1, Calendar.getInstance()));
              assertEquals("get time when SQL NULL", time, rs.getTime(1, Calendar.getInstance()));
              assertNotNull("get time column,calendar not null", rs.getTime("column", Calendar.getInstance()));
              assertEquals("get time when SQL NULL", time, rs.getTime("column", Calendar.getInstance()));
          }
          catch(Exception e) {
              fail("Could not test: " + e.getMessage());
          }
      }
      
      /**
       * Tests the getTimestamp implementation.
       */
      public void testGetTimestamp() {
          try {
              assertNull("get timestamp index is null", rs.getTimestamp(1));
              assertTrue("get timestamp was SQL NULL", rs.wasNull());
              assertNull("get timestamp column is null", rs.getTimestamp("column"));
              assertTrue("get timestamp was SQL NULL", rs.wasNull());
              assertNull("get timestamp index,calendar is null", rs.getTimestamp(1, Calendar.getInstance()));
              assertTrue("get timestamp was SQL NULL", rs.wasNull());
              assertNull("get timestamp column,calendar is null", rs.getTimestamp("column", Calendar.getInstance()));
              assertTrue("get timestamp was SQL NULL", rs.wasNull());
              // Set what gets returned to something other than the default
              Timestamp ts = new Timestamp(new java.util.Date().getTime());
              rs.setNullTimestamp(ts);
              assertNotNull("get timestamp index not null", rs.getTimestamp(1));
              assertEquals("get timestamp when SQL NULL", ts, rs.getTimestamp(1));
              assertNotNull("get timestamp column not null", rs.getTimestamp("column"));
              assertEquals("get timestamp when SQL NULL", ts, rs.getTimestamp("column"));
              assertNotNull("get timestamp index,calendar not null", rs.getTimestamp(1, Calendar.getInstance()));
              assertEquals("get timestamp when SQL NULL", ts, rs.getTimestamp(1, Calendar.getInstance()));
              assertNotNull("get timestamp column,calendar not null", rs.getTimestamp("column", Calendar.getInstance()));
              assertEquals("get timestamp when SQL NULL", ts, rs.getTimestamp("column", Calendar.getInstance()));
          }
          catch(Exception e) {
              fail("Could not test: " + e.getMessage());
          }
      }
      
      /**
       * Tests the getUnicodeStream implementation.
       */
      public void testGetUnicodeStream() {
          try {
              assertNull("get unicode stream index is null", rs.getUnicodeStream(1));
              assertTrue("get unicode stream was SQL NULL", rs.wasNull());
              assertNull("get unicode stream column is null", rs.getUnicodeStream("column"));
              assertTrue("get unicode stream was SQL NULL", rs.wasNull());
              // Set what gets returned to something other than the default
              InputStream stream = new ByteArrayInputStream(new byte[0]);
              rs.setNullUnicodeStream(stream);
              assertNotNull("get unicode stream index not null", rs.getUnicodeStream(1));
              assertEquals("get unicode stream when SQL NULL", stream, rs.getUnicodeStream(1));
              assertNotNull("get unicode stream column not null", rs.getUnicodeStream("column"));
              assertEquals("get unicode stream when SQL NULL", stream, rs.getUnicodeStream("column"));
          }
          catch(Exception e) {
              fail("Could not test: " + e.getMessage());
          }
      }
  
      /**
       * Tests the setNullAsciiStream implementation.
       */
      public void testSetNullAsciiStream() {
          try {
              assertNull("null ascii stream", rs.getNullAsciiStream());
              // Set what gets returned to something other than the default
              InputStream stream = new ByteArrayInputStream(new byte[0]);
              rs.setNullAsciiStream(stream);
              assertNotNull("get ascii stream index not null", rs.getAsciiStream(1));
              assertEquals("get ascii stream when SQL NULL", stream, rs.getAsciiStream(1));
              assertNotNull("get ascii stream column not null", rs.getAsciiStream("column"));
              assertEquals("get ascii stream when SQL NULL", stream, rs.getAsciiStream("column"));
          }
          catch(Exception e) {
              fail("Could not test: " + e.getMessage());
          }
      }
      
      /**
       * Tests the setNullBigDecimal implementation.
       */
      public void testSetNullBigDecimal() {
          try {
              assertNull("null big decimal", rs.getNullBigDecimal());
              // Set what gets returned to something other than the default
              BigDecimal bd = new BigDecimal(5.0);
              rs.setNullBigDecimal(bd);
              assertNotNull("get big decimal index not null", rs.getBigDecimal(1));
              assertEquals("get big decimal when SQL NULL", bd, rs.getBigDecimal(1));
              assertNotNull("get big decimal column not null", rs.getBigDecimal("column"));
              assertEquals("get big decimal when SQL NULL", bd, rs.getBigDecimal("column"));
          }
          catch(Exception e) {
              fail("Could not test: " + e.getMessage());
          }
      }
      
      /**
       * Tests the setNullBinaryStream implementation.
       */
      public void testSetNullBinaryStream() {
          try {
              assertNull("null binary stream", rs.getNullBinaryStream());
              // Set what gets returned to something other than the default
              InputStream stream = new ByteArrayInputStream(new byte[0]);
              rs.setNullBinaryStream(stream);
              assertNotNull("get binary stream index not null", rs.getBinaryStream(1));
              assertEquals("get binary stream when SQL NULL", stream, rs.getBinaryStream(1));
              assertNotNull("get binary stream column not null", rs.getBinaryStream("column"));
              assertEquals("get binary stream when SQL NULL", stream, rs.getBinaryStream("column"));
          }
          catch(Exception e) {
              fail("Could not test: " + e.getMessage());
          }
      }
      
      /**
       * Tests the setNullBlob implementation.
       */
      public void testSetNullBlob() {
          try {
              assertNull("null blob", rs.getNullBlob());
              // Set what gets returned to something other than the default
              Blob blob = new SqlNullCheckedResultSetMockBlob();
              rs.setNullBlob(blob);
              assertNotNull("get blob index not null", rs.getBlob(1));
              assertEquals("get blob when SQL NULL", blob, rs.getBlob(1));
              assertNotNull("get blob column not null", rs.getBlob("column"));
              assertEquals("get blob when SQL NULL", blob, rs.getBlob("column"));
          }
          catch(Exception e) {
              fail("Could not test: " + e.getMessage());
          }
      }
      
      /**
       * Tests the setNullBoolean implementation.
       */
      public void testSetNullBoolean() {
          try {
              assertFalse("null boolean", rs.getNullBoolean());
              // Set what gets returned to something other than the default
              rs.setNullBoolean(true);
              assertEquals("get boolean when SQL NULL", true, rs.getBoolean(1));
              assertEquals("get boolean when SQL NULL", true, rs.getBoolean("column"));
          }
          catch(Exception e) {
              fail("Could not test: " + e.getMessage());
          }
      }
      
      /**
       * Tests the setNullByte implementation.
       */
      public void testSetNullByte() {
          try {
              assertEquals("null byte", (byte) 0, rs.getNullByte());
              // Set what gets returned to something other than the default
              byte b = (byte) 10;
              rs.setNullByte(b);
              assertEquals("get byte when SQL NULL", b, rs.getByte(1));
              assertEquals("get byte when SQL NULL", b, rs.getByte("column"));
          }
          catch(Exception e) {
              fail("Could not test: " + e.getMessage());
          }
      }
      
      /**
       * Tests the setNullByte implementation.
       */
      public void testSetNullBytes() {
          try {
              assertNull("null bytes", rs.getNullBytes());
              // Set what gets returned to something other than the default
              byte[] b = new byte[5];
              for(int i = 0; i < 5; i++) {
                  b[0] = (byte) i;
              }
              rs.setNullBytes(b);
              assertNotNull("get bytes index not null", rs.getBytes(1));
              assertEquals("get bytes when SQL NULL", b, rs.getBytes(1));
              assertNotNull("get bytes column not null", rs.getBytes("column"));
              assertEquals("get bytes when SQL NULL", b, rs.getBytes("column"));
          }
          catch(Exception e) {
              fail("Could not test: " + e.getMessage());
          }
      }
      
      /**
       * Tests the setNullCharacterStream implementation.
       */
      public void testSetNullCharacterStream() {
          try {
              assertNull("null character tream", rs.getNullCharacterStream());
              // Set what gets returned to something other than the default
              Reader reader = new CharArrayReader("this is a string".toCharArray());
              rs.setNullCharacterStream(reader);
              assertNotNull("get character stream index not null", rs.getCharacterStream(1));
              assertEquals("get character stream when SQL NULL", reader, rs.getCharacterStream(1));
              assertNotNull("get character stream column not null", rs.getCharacterStream("column"));
              assertEquals("get character stream when SQL NULL", reader, rs.getCharacterStream("column"));
          }
          catch(Exception e) {
              fail("Could not test: " + e.getMessage());
          }
      }
      
      /**
       * Tests the setNullClob implementation.
       */
      public void testSetNullClob() {
          try {
              assertNull("null clob", rs.getNullClob());
              // Set what gets returned to something other than the default
              Clob clob = new SqlNullCheckedResultSetMockClob();
              rs.setNullClob(clob);
              assertNotNull("get clob index not null", rs.getClob(1));
              assertEquals("get clob when SQL NULL", clob, rs.getClob(1));
              assertNotNull("get clob column not null", rs.getClob("column"));
              assertEquals("get clob when SQL NULL", clob, rs.getClob("column"));
          }
          catch(Exception e) {
              fail("Could not test: " + e.getMessage());
          }
      }
      
      /**
       * Tests the setNullDate implementation.
       */
      public void testSetNullDate() {
          try {
              assertNull("null date", rs.getNullDate());
              // Set what gets returned to something other than the default
              java.sql.Date date = new java.sql.Date(new java.util.Date().getTime());
              rs.setNullDate(date);
              assertNotNull("get date index not null", rs.getDate(1));
              assertEquals("get date when SQL NULL", date, rs.getDate(1));
              assertNotNull("get date column not null", rs.getDate("column"));
              assertEquals("get date when SQL NULL", date, rs.getDate("column"));
              assertNotNull("get date index,calendar not null", rs.getDate(1, Calendar.getInstance()));
              assertEquals("get date when SQL NULL", date, rs.getDate(1, Calendar.getInstance()));
              assertNotNull("get date column,calendar not null", rs.getDate("column", Calendar.getInstance()));
              assertEquals("get date when SQL NULL", date, rs.getDate("column", Calendar.getInstance()));
          }
          catch(Exception e) {
              fail("Could not test: " + e.getMessage());
          }
      }
      
      /**
       * Tests the setNullDouble implementation.
       */
      public void testSetNullDouble() {
          try {
              assertEquals("null double", (double) 0.0, rs.getNullDouble(), 0.0);
              // Set what gets returned to something other than the default
              double d = (double) 10.0;
              rs.setNullDouble(d);
              assertEquals("get double when SQL NULL", d, rs.getDouble(1), 0.0);
              assertEquals("get double when SQL NULL", d, rs.getDouble("column"), 0.0);
          }
          catch(Exception e) {
              fail("Could not test: " + e.getMessage());
          }
      }
      
      /**
       * Tests the setNullFloat implementation.
       */
      public void testSetNullFloat() {
          try {
              assertEquals("null float", (float) 0.0, rs.getNullFloat(), 0.0);
              // Set what gets returned to something other than the default
              float f = (float) 10.0;
              rs.setNullFloat(f);
              assertEquals("get float when SQL NULL", f, rs.getFloat(1), 0.0);
              assertEquals("get float when SQL NULL", f, rs.getFloat("column"), 0.0);
          }
          catch(Exception e) {
              fail("Could not test: " + e.getMessage());
          }
      }
      
      /**
       * Tests the setNullInt implementation.
       */
      public void testSetNullInt() {
          try {
              assertEquals("null int", 0, rs.getNullInt());
              assertEquals("get int index", (int) 0, rs.getInt(1));
              assertTrue("get int was SQL NULL", rs.wasNull());
              assertEquals("get int column", (int) 0, rs.getInt("column"));
              assertTrue("get int was SQL NULL", rs.wasNull());
              // Set what gets returned to something other than the default
              int i = (int) 10;
              rs.setNullInt(i);
              assertEquals("get int when SQL NULL", i, rs.getInt(1));
              assertEquals("get int when SQL NULL", i, rs.getInt("column"));
          }
          catch(Exception e) {
              fail("Could not test: " + e.getMessage());
          }
      }
      
      /**
       * Tests the setNullLong implementation.
       */
      public void testSetNullLong() {
          try {
              assertEquals("null long", (long) 0, rs.getNullLong());
              // Set what gets returned to something other than the default
              long l = (long) 10;
              rs.setNullLong(l);
              assertEquals("get long when SQL NULL", l, rs.getLong(1));
              assertEquals("get long when SQL NULL", l, rs.getLong("column"));
          }
          catch(Exception e) {
              fail("Could not test: " + e.getMessage());
          }
      }
      
      /**
       * Tests the setNullObject implementation.
       */
      public void testSetNullObject() {
          try {
              assertNull("null object", rs.getNullObject());
              // Set what gets returned to something other than the default
              Object o = new Object();
              rs.setNullObject(o);
              assertNotNull("get object index not null", rs.getObject(1));
              assertEquals("get object when SQL NULL", o, rs.getObject(1));
              assertNotNull("get object column not null", rs.getObject("column"));
              assertEquals("get object when SQL NULL", o, rs.getObject("column"));
              assertNotNull("get object index,map not null", rs.getObject(1, (Map) null));
              assertEquals("get object when SQL NULL", o, rs.getObject(1, (Map) null));
              assertNotNull("get object column,map not null", rs.getObject("column", (Map) null));
              assertEquals("get object when SQL NULL", o, rs.getObject("column", (Map) null));
          }
          catch(Exception e) {
              fail("Could not test: " + e.getMessage());
          }
      }
      
      /**
       * Tests the setNullRef implementation.
       */
      public void testSetNullRef() {
          try {
              assertNull("null ref", rs.getNullRef());
              // Set what gets returned to something other than the default
              Ref ref = new SqlNullCheckedResultSetMockRef();
              rs.setNullRef(ref);
              assertNotNull("get ref index not null", rs.getRef(1));
              assertEquals("get ref when SQL NULL", ref, rs.getRef(1));
              assertNotNull("get ref column not null", rs.getRef("column"));
              assertEquals("get ref when SQL NULL", ref, rs.getRef("column"));
          }
          catch(Exception e) {
              fail("Could not test: " + e.getMessage());
          }
      }
      
      /**
       * Tests the setNullShort implementation.
       */
      public void testSetNullShort() {
          try {
              assertEquals("null short", (short) 0, rs.getNullShort());
              // Set what gets returned to something other than the default
              short s = (short) 10;
              rs.setNullShort(s);
              assertEquals("get short when SQL NULL", s, rs.getShort(1));
              assertEquals("get short when SQL NULL", s, rs.getShort("column"));
          }
          catch(Exception e) {
              fail("Could not test: " + e.getMessage());
          }
      }
      
      /**
       * Tests the setNullString implementation.
       */
      public void testSetNullString() {
          try {
              assertEquals("null string", null, rs.getNullString());
              // Set what gets returned to something other than the default
              String s = "hello, world";
              rs.setNullString(s);
              assertEquals("get string when SQL NULL", s, rs.getString(1));
              assertEquals("get string when SQL NULL", s, rs.getString("column"));
          }
          catch(Exception e) {
              fail("Could not test: " + e.getMessage());
          }
      }
      
      /**
       * Tests the setNullTime implementation.
       */
      public void testSetNullTime() {
          try {
              assertEquals("null time", null, rs.getNullTime());
              // Set what gets returned to something other than the default
              Time time = new Time(new java.util.Date().getTime());
              rs.setNullTime(time);
              assertNotNull("get time index not null", rs.getTime(1));
              assertEquals("get time when SQL NULL", time, rs.getTime(1));
              assertNotNull("get time column not null", rs.getTime("column"));
              assertEquals("get time when SQL NULL", time, rs.getTime("column"));
              assertNotNull("get time index,calendar not null", rs.getTime(1, Calendar.getInstance()));
              assertEquals("get time when SQL NULL", time, rs.getTime(1, Calendar.getInstance()));
              assertNotNull("get time column,calendar not null", rs.getTime("column", Calendar.getInstance()));
              assertEquals("get time when SQL NULL", time, rs.getTime("column", Calendar.getInstance()));
          }
          catch(Exception e) {
              fail("Could not test: " + e.getMessage());
          }
      }
      
      /**
       * Tests the setNullTimestamp implementation.
       */
      public void testSetNullTimestamp() {
          try {
              assertEquals("null timestamp", null, rs.getNullTimestamp());
              // Set what gets returned to something other than the default
              Timestamp ts = new Timestamp(new java.util.Date().getTime());
              rs.setNullTimestamp(ts);
              assertNotNull("get timestamp index not null", rs.getTimestamp(1));
              assertEquals("get timestamp when SQL NULL", ts, rs.getTimestamp(1));
              assertNotNull("get timestamp column not null", rs.getTimestamp("column"));
              assertEquals("get timestamp when SQL NULL", ts, rs.getTimestamp("column"));
              assertNotNull("get timestamp index,calendar not null", rs.getTimestamp(1, Calendar.getInstance()));
              assertEquals("get timestamp when SQL NULL", ts, rs.getTimestamp(1, Calendar.getInstance()));
              assertNotNull("get timestamp column,calendar not null", rs.getTimestamp("column", Calendar.getInstance()));
              assertEquals("get timestamp when SQL NULL", ts, rs.getTimestamp("column", Calendar.getInstance()));
          }
          catch(Exception e) {
              fail("Could not test: " + e.getMessage());
          }
      }
      
      /**
       * Tests the setNullUnicodeStream implementation.
       */
      public void testSetNullUnicodeStream() {
          try {
              assertEquals("null unicode stream", null, rs.getNullUnicodeStream());
              // Set what gets returned to something other than the default
              InputStream stream = new ByteArrayInputStream(new byte[0]);
              rs.setNullUnicodeStream(stream);
              assertNotNull("get unicode stream index not null", rs.getUnicodeStream(1));
              assertEquals("get unicode stream when SQL NULL", stream, rs.getUnicodeStream(1));
              assertNotNull("get unicode stream column not null", rs.getUnicodeStream("column"));
              assertEquals("get unicode stream when SQL NULL", stream, rs.getUnicodeStream("column"));
          }
          catch(Exception e) {
              fail("Could not test: " + e.getMessage());
          }
      }
      
      /**
       * Runs the test suite.
       *
       * @param args command line arguments
       */
      public static void main(String args[])
      {
          TestRunner.run(suite());
      }
  }
  
  class SqlNullUncheckedMockResultSet extends MockResultSet  {
      SqlNullUncheckedMockResultSet(Statement statement) {
          super(statement);
      }
      
      public InputStream getUnicodeStream(String str) throws SQLException {
          return null;
      }
      
      public InputStream getUnicodeStream(int param) throws SQLException {
          return null;
      }
      
      public Timestamp getTimestamp(String str, Calendar calendar) throws SQLException {
          return null;
      }
      
      public Timestamp getTimestamp(int param, Calendar calendar) throws SQLException {
          return null;
      }
      
      public Timestamp getTimestamp(int param) throws SQLException {
          return null;
      }
      
      public Timestamp getTimestamp(String str) throws SQLException {
          return null;
      }
      
      public Time getTime(int param, Calendar calendar) throws SQLException {
          return null;
      }
      
      public Time getTime(String str, Calendar calendar) throws SQLException {
          return null;
      }
      
      public Time getTime(String str) throws SQLException {
          return null;
      }
      
      public Time getTime(int param) throws SQLException {
          return null;
      }
      
      public String getString(int param) throws SQLException {
          return null;
      }
      
      public String getString(String str) throws SQLException {
          return null;
      }
      
      public short getShort(String str) throws SQLException {
          return 0;
      }
      
      public short getShort(int param) throws SQLException {
          return 0;
      }
      
      public Ref getRef(int param) throws SQLException {
          return null;
      }
      
      public java.sql.Ref getRef(String str) throws SQLException {
          return null;
      }
      
      public Object getObject(int param, Map map) throws SQLException {
          return null;
      }
      
      public Object getObject(String str, Map map) throws SQLException {
          return null;
      }
      
      public Object getObject(int param) throws SQLException {
          return null;
      }
      
      public Object getObject(String str) throws SQLException {
          return null;
      }
      
      public long getLong(String str) throws SQLException {
          return 0;
      }
      
      public long getLong(int param) throws SQLException {
          return 0;
      }
      
      public int getInt(String str) throws SQLException {
          return 0;
      }
      
      public int getInt(int param) throws SQLException {
          return 0;
      }
      
      public float getFloat(String str) throws SQLException {
          return (float) 0.0;
      }
      
      public float getFloat(int param) throws SQLException {
          return (float) 0.0;
      }
      
      public double getDouble(int param) throws SQLException {
          return 0.0;
      }
      
      public double getDouble(String str) throws SQLException {
          return 0.0;
      }
      
      public java.sql.Date getDate(int param, Calendar calendar) throws SQLException {
          return null;
      }
      
      public java.sql.Date getDate(String str, Calendar calendar) throws SQLException {
          return null;
      }
      
      public java.sql.Date getDate(String str) throws SQLException {
          return null;
      }
      
      public java.sql.Date getDate(int param) throws SQLException {
          return null;
      }
      
      public Clob getClob(int param) throws SQLException {
          return null;
      }
      
      public Clob getClob(String str) throws SQLException {
          return null;
      }
      
      public Reader getCharacterStream(String str) throws SQLException {
          return null;
      }
      
      public Reader getCharacterStream(int param) throws SQLException {
          return null;
      }
      
      public byte[] getBytes(String str) throws SQLException {
          return null;
      }
      
      public byte[] getBytes(int param) throws SQLException {
          return null;
      }
      
      public byte getByte(String str) throws SQLException {
          return (byte) 0;
      }
      
      public byte getByte(int param) throws SQLException {
          return (byte) 0;
      }
      
      public boolean getBoolean(int param) throws SQLException {
          return false;
      }
      
      public boolean getBoolean(String str) throws SQLException {
          return false;
      }
      
      public Blob getBlob(int param) throws SQLException {
          return null;
      }
      
      public Blob getBlob(String str) throws SQLException {
          return null;
      }
      
      public InputStream getBinaryStream(String str) throws SQLException {
          return null;
      }
      
      public InputStream getBinaryStream(int param) throws SQLException {
          return null;
      }
      
      public BigDecimal getBigDecimal(String str, int param) throws SQLException {
          return null;
      }
      
      public BigDecimal getBigDecimal(int param, int param1) throws SQLException {
          return null;
      }
      
      public BigDecimal getBigDecimal(int param) throws SQLException {
          return null;
      }
      
      public BigDecimal getBigDecimal(String str) throws SQLException {
          return null;
      }
      
      public InputStream getAsciiStream(String str) throws SQLException {
          return null;
      }
      
      public InputStream getAsciiStream(int param) throws SQLException {
          return null;
      }
      
      public Array getArray(String str) throws SQLException {
          return null;
      }
      
      public Array getArray(int param) throws SQLException {
          return null;
      }
  
      public boolean wasNull() throws SQLException {
          return true;
      }
  }
  
  class SqlNullCheckedResultSetMockBlob implements Blob {
      
      public InputStream getBinaryStream() throws SQLException {
          return new ByteArrayInputStream(new byte[0]);
      }
      
      public byte[] getBytes(long param, int param1) throws SQLException {
          return new byte[0];
      }
      
      public long length() throws SQLException {
          return 0;
      }
      
      public long position(byte[] values, long param) throws SQLException {
          return 0;
      }
      
      public long position(java.sql.Blob blob, long param) throws SQLException {
          return 0;
      }
      
  }
  
  class SqlNullCheckedResultSetMockClob implements Clob {
      
      public InputStream getAsciiStream() throws SQLException {
          return null;
      }
      
      public Reader getCharacterStream() throws SQLException {
          return null;
      }
      
      public String getSubString(long param, int param1) throws SQLException {
          return "";
      }
      
      public long length() throws SQLException {
          return 0;
      }
      
      public long position(Clob clob, long param) throws SQLException {
          return 0;
      }
      
      public long position(String str, long param) throws SQLException {
          return 0;
      }
      
  }
  
  class SqlNullCheckedResultSetMockRef implements Ref {
      
      public String getBaseTypeName() throws SQLException {
          return "";
      }
      
  }    
  
  
  
  1.1                  jakarta-commons-sandbox/dbutils/src/test/org/apache/commons/dbutils/driver/StringTrimmedResultSetTestCase.java
  
  Index: StringTrimmedResultSetTestCase.java
  ===================================================================
  /*
   * StringTrimmedResultSetTestCase.java
   */
  
  package org.apache.commons.dbutils.driver;
  
  import java.sql.ResultSet;
  import java.sql.SQLException;
  import java.sql.Statement;
  import junit.framework.Test;
  import junit.framework.TestSuite;
  import junit.textui.TestRunner;
  import org.apache.commons.dbutils.mockdriver.MockConnection;
  import org.apache.commons.dbutils.mockdriver.MockResultSet;
  import org.apache.commons.dbutils.mockdriver.MockStatement;
  
  /**
   * Test cases for
   * <code>StringTrimmedResultSetTestCase</code>
   * class.
   *
   * @author  <a href="stevencaswell@apache.org">Steven Caswell</a>
   * @version $Id: StringTrimmedResultSetTestCase.java,v 1.1 2003/02/02 17:09:43 stevencaswell Exp $
   */
  public class StringTrimmedResultSetTestCase extends junit.framework.TestCase {
      
      /**
       * Constructs a new instance of
       * <code>StringTrimmedResultSetTestCase</code>
       * with the specified name.
       *
       * @param name the test case name
       */
      public StringTrimmedResultSetTestCase(String name) {
          super(name);
      }
      
      /**
       * Sets up instance variables required by this test case.
       */
      public void setUp() {
      }
      
      /**
       * Builds the test suite.
       *
       * @return the test suite
       */
      public static Test suite() {
          return new TestSuite(StringTrimmedResultSetTestCase.class);
      }
      
      /**
       * Tears down instance variables required by this test case.
       */
      public void tearDown() {
      }
      
      /**
       * Tests the someMethod implementation.
       */
      public void testGetString() {
          try {
              MockConnection connection = new MockConnection();
              MockStatement statement = new MockStatement(connection);
              ResultSet rs = new StringUntrimmedMockResultSet(statement);
              assertEquals("untrimmed string from index", "  untrimmed string 1 ", rs.getString(1));
              rs = new StringTrimmedResultSet(new StringUntrimmedMockResultSet(statement));
              assertEquals("untrimmed string from index", "untrimmed string 1", rs.getString(1));
              
              rs = new StringUntrimmedMockResultSet(statement);
              assertEquals("untrimmed string from index", "  untrimmed string column ", rs.getString("column"));
              rs = new StringTrimmedResultSet(new StringUntrimmedMockResultSet(statement));
              assertEquals("untrimmed string from index", "untrimmed string column", rs.getString("column"));
          }
          catch(Exception e) {
              fail("Could not test: " + e.getMessage());
          }
      }
      
      /**
       * Runs the test suite.
       *
       * @param args command line arguments
       */
      public static void main(String args[]) {
          TestRunner.run(suite());
      }
      
  }
  
  class StringUntrimmedMockResultSet extends MockResultSet {
      StringUntrimmedMockResultSet(Statement statement) {
          super(statement);
      }
      
      public String getString(int index) throws SQLException {
          return "  untrimmed string " + index + " ";
      }
      
      public String getString(String column) throws SQLException {
          return "  untrimmed string " + column + " ";
      }
  }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Mime
View raw message