/* Copyright (C) 2002 MySQL AB This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ package testsuite.simple; import testsuite.BaseTestCase; import java.sql.PreparedStatement; import java.sql.SQLException; /** * * @author Mark Matthews * @version $Id: NumbersTest.java,v 1.4.4.2 2003/02/17 15:42:50 mmatthew Exp $ */ public class NullNumbersTest extends BaseTestCase { //~ Static fields/initializers --------------------------------------------- private static final int TEST_INT_VALUE = 5; //~ Constructors ----------------------------------------------------------- /** * Creates a new NumbersTest object. * * @param name DOCUMENT ME! */ public NullNumbersTest(String name) { super(name); } //~ Methods ---------------------------------------------------------------- /** * DOCUMENT ME! * * @param args DOCUMENT ME! */ public static void main(String[] args) { new NullNumbersTest("testNumbers").run(); } /** * DOCUMENT ME! * * @throws Exception DOCUMENT ME! */ public void setUp() throws Exception { super.setUp(); createTestTable(); } /** * DOCUMENT ME! * * @throws SQLException DOCUMENT ME! */ public void testNumbers() throws SQLException { PreparedStatement pstmt = conn.prepareStatement("SELECT * from number_test"); rs = pstmt.executeQuery(); while (rs.next()) { int nullInt = rs.getInt(1); boolean nullWasNull = rs.wasNull(); long nonNullInt = rs.getInt(2); boolean nonNullWasNull = rs.wasNull(); assertTrue("Null int not retrieved correctly", (nullInt == 0)); assertTrue("Null int did not return wasNull", nullWasNull); assertTrue("Non Null int not retrieved correctly", (nonNullInt == TEST_INT_VALUE)); assertFalse("Non null int returned wasNull", nonNullWasNull); } pstmt.close(); } private void createTestTable() throws SQLException { try { stmt.executeUpdate("DROP TABLE number_test"); } catch (SQLException sqlEx) { ; } stmt.executeUpdate( "CREATE TABLE number_test (nullInt int, nonNullInt int)"); stmt.executeUpdate( "INSERT INTO number_test (nullInt, nonNullInt) values (" + "Null" + "," + TEST_INT_VALUE + ")"); } }