Home | History | Annotate | Download | only in sql
      1 /*
      2  * Licensed to the Apache Software Foundation (ASF) under one or more
      3  * contributor license agreements.  See the NOTICE file distributed with
      4  * this work for additional information regarding copyright ownership.
      5  * The ASF licenses this file to You under the Apache License, Version 2.0
      6  * (the "License"); you may not use this file except in compliance with
      7  * the License.  You may obtain a copy of the License at
      8  *
      9  *     http://www.apache.org/licenses/LICENSE-2.0
     10  *
     11  * Unless required by applicable law or agreed to in writing, software
     12  * distributed under the License is distributed on an "AS IS" BASIS,
     13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     14  * See the License for the specific language governing permissions and
     15  * limitations under the License.
     16  */
     17 
     18 package libcore.javax.sql;
     19 
     20 import java.sql.Connection;
     21 import java.sql.SQLException;
     22 import javax.sql.ConnectionEvent;
     23 import javax.sql.ConnectionEventListener;
     24 import javax.sql.PooledConnection;
     25 import javax.sql.StatementEventListener;
     26 import junit.framework.TestCase;
     27 
     28 public class OldConnectionEventTest extends TestCase {
     29 
     30     public void testConstructorConnection() {
     31         Impl_PooledConnection ipc = new Impl_PooledConnection();
     32         ConnectionEvent ce = new ConnectionEvent(ipc);
     33         ConnectionEvent ce2 = new ConnectionEvent(ipc,null);
     34         assertSame(ce2.getSource(),ce.getSource());
     35     }
     36 
     37     public void testGetSQLException() {
     38         Impl_PooledConnection ipc = new Impl_PooledConnection();
     39         ConnectionEvent ce = new ConnectionEvent(ipc);
     40 
     41         ConnectionEvent ce2 = new ConnectionEvent(ipc, null);
     42         assertNull(ce.getSQLException());
     43         assertEquals(ce2.getSQLException(), ce.getSQLException());
     44 
     45         SQLException e = new SQLException();
     46         ConnectionEvent ce3 = new ConnectionEvent(ipc, e);
     47         assertNotNull(ce3.getSQLException());
     48         assertNotSame(ce3.getSQLException(), ce2.getSQLException());
     49     }
     50 
     51     static class Impl_PooledConnection implements PooledConnection {
     52         public void addConnectionEventListener(ConnectionEventListener theListener) {}
     53         public void close() throws SQLException {}
     54         public Connection getConnection() throws SQLException {
     55             return null;
     56         }
     57         public void removeConnectionEventListener(ConnectionEventListener listener) {}
     58         public void addStatementEventListener(StatementEventListener listener) {}
     59         public void removeStatementEventListener(StatementEventListener listener) {}
     60     }
     61 }
     62