blob: b5fb45321e0ccb97f6da4c885f681eef399a9bab [file] [log] [blame]
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.commons.dbcp2.datasources;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertTrue;
import java.util.Arrays;
import org.apache.commons.dbcp2.Utils;
import org.junit.Before;
import org.junit.Test;
/**
* Tests for UserPassKey.
* @since 2.5.0
*/
public class TestUserPassKey {
private UserPassKey userPassKey;
private UserPassKey anotherUserPassKey;
@Before
public void setUp() {
userPassKey = new UserPassKey("user", "pass");
anotherUserPassKey = new UserPassKey((String) null, "");
}
@Test
public void testGettersAndSetters() {
assertEquals("user", userPassKey.getUsername());
assertEquals("pass", userPassKey.getPassword());
assertTrue(Arrays.equals(Utils.toCharArray("pass"), userPassKey.getPasswordCharArray()));
}
@Test
public void testEquals() {
assertEquals(new UserPassKey("user"), new UserPassKey("user", (char[]) null));
assertEquals(userPassKey, userPassKey);
assertNotEquals(userPassKey, null);
assertNotEquals(userPassKey, new Object());
assertNotEquals(new UserPassKey(null), userPassKey);
assertEquals(new UserPassKey(null), new UserPassKey(null));
assertNotEquals(new UserPassKey("user", "pass"), new UserPassKey("foo", "pass"));
}
@Test
public void testHashcode() {
assertEquals(userPassKey.hashCode(), new UserPassKey("user", "pass").hashCode());
assertNotEquals(userPassKey.hashCode(), anotherUserPassKey.hashCode());
}
@Test
public void testToString() {
assertEquals(userPassKey.toString(), new UserPassKey("user", "pass").toString());
assertNotEquals(userPassKey.toString(), anotherUserPassKey.toString());
}
}