001 /* 002 * Licensed to the Apache Software Foundation (ASF) under one or more 003 * contributor license agreements. See the NOTICE file distributed with 004 * this work for additional information regarding copyright ownership. 005 * The ASF licenses this file to You under the Apache License, Version 2.0 006 * (the "License"); you may not use this file except in compliance with 007 * the License. You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017 package org.apache.commons.dbutils.wrappers; 018 019 import java.sql.ResultSet; 020 import java.sql.SQLException; 021 022 import org.apache.commons.dbutils.BaseTestCase; 023 import org.apache.commons.dbutils.MockResultSet; 024 import org.apache.commons.dbutils.ProxyFactory; 025 026 /** 027 * StringTrimmedResultSetTest 028 */ 029 public class StringTrimmedResultSetTest extends BaseTestCase { 030 031 public void setUp() throws Exception { 032 super.setUp(); 033 this.rs = StringTrimmedResultSet.wrap(this.rs); 034 } 035 036 public void testGetString() throws SQLException { 037 this.rs.next(); 038 assertEquals("notInBean", rs.getString(4)); 039 } 040 041 public void testGetObject() throws SQLException { 042 this.rs.next(); 043 assertEquals("notInBean", rs.getObject(4)); 044 } 045 046 /** 047 * Make sure 2 wrappers work together. 048 * @throws SQLException if a database access error occurs 049 */ 050 public void testMultipleWrappers() throws Exception { 051 // Create a ResultSet with data 052 Object[][] rows = new Object[][] { { null } 053 }; 054 ResultSet rs = MockResultSet.create(metaData, rows); 055 056 // Wrap the ResultSet with a null checked version 057 SqlNullCheckedResultSet ncrs = new SqlNullCheckedResultSet(rs); 058 ncrs.setNullString(" trim this "); 059 rs = ProxyFactory.instance().createResultSet(ncrs); 060 061 // Wrap the wrapper with a string trimmed version 062 rs = StringTrimmedResultSet.wrap(rs); 063 064 rs.next(); 065 assertEquals("trim this", rs.getString(1)); 066 } 067 068 }