View Javadoc
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    *      https://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 org.apache.commons.dbcp2.datasources;
19  
20  import static org.junit.jupiter.api.Assertions.assertArrayEquals;
21  
22  import java.sql.SQLException;
23  
24  import javax.sql.PooledConnection;
25  
26  import org.junit.jupiter.api.Test;
27  
28  /*
29   * Tests {@link PooledConnectionManager}.
30   */
31  class PooledConnectionManagerTest {
32  
33      static class Fixture implements PooledConnectionManager {
34  
35          private char[] password;
36  
37          @Override
38          public void closePool(final String userName) throws SQLException {
39              // empty
40          }
41  
42          char[] getPassword() {
43              return password;
44          }
45  
46          @Override
47          public void invalidate(final PooledConnection pc) throws SQLException {
48              // empty
49          }
50  
51          @Override
52          public void setPassword(final String password) {
53              this.password = password.toCharArray();
54          }
55      }
56  
57      @Test
58      void testSetPasswordCharArray() {
59          final Fixture fixture = new Fixture();
60          fixture.setPassword("p".toCharArray());
61          assertArrayEquals("p".toCharArray(), fixture.getPassword());
62      }
63  
64      @Test
65      void testSetPasswordString() {
66          final Fixture fixture = new Fixture();
67          fixture.setPassword("p");
68          assertArrayEquals("p".toCharArray(), fixture.getPassword());
69      }
70  }