ユニットテストでこのメッセージが表示されますexpected:<interface java.sql.Connection> but was:<class com.mysql.jdbc.JDBC4Connection>
私のコードから:
@Test
public void connectionTest() throws SQLException{
Connection conn = ConnectionManager.createConnection();
assertEquals(Connection.class, conn.getClass());
conn.close();
}
接続を取得するための私の模擬クラス:
public class ConnectionManager {
@SuppressWarnings("unused")
public static Connection createConnection() throws SQLException {
String url = "jdbc:mysql://localhost:3306/library";
String name = "root";
String password = "root";
Connection connection = null;
try {
Class.forName("com.mysql.jdbc.Driver");
connection = DriverManager.getConnection(url, name, password);
} catch (ClassNotFoundException e) {
if (connection != null){
connection.close();
}
throw new SQLException(e);
}
return connection;
}
}
私のコードの何が問題になっていますか?