Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8146907
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T14:09:58+00:00 2026-06-06T14:09:58+00:00

For unit testing a Scala project, I am writing my own simple javax.sql.DataSource class

  • 0

For unit testing a Scala project, I am writing my own simple javax.sql.DataSource class which basically just wraps a java.sql.DriverManager instance under the covers.

I simply extended javax.sql.DataSource, and for the most part let Eclipse auto-generate stubs for the required methods/functions.

class H2DataSource extends javax.sql.DataSource {

  import java.io.PrintWriter
  import java.sql.DriverManager

  var printWriter : PrintWriter

  Class.forName("org.h2.Driver")

  @throws(classOf[SQLException])
  override def getLogWriter() : PrintWriter = {
    printWriter
  }

  @throws(classOf[SQLException])
  override def getLoginTimeout() : Int = {
    // TODO Auto-generated method stub
    0
  }

  @throws(classOf[SQLException])
  override def setLogWriter(printWriter: PrintWriter) = {
    this.printWriter = printWriter 
  }

  @throws(classOf[SQLException])
  override def setLoginTimeout(seconds: Int) = {
    // TODO Auto-generated method stub
  }

  @throws(classOf[SQLException])
  override def isWrapperFor(iface: Class[_]) : Boolean = {
    // TODO Auto-generated method stub
    false
  }

  @throws(classOf[SQLException])
  override def unwrap[T](iface: java.lang.Class[_]) : T = {
    // TODO Auto-generated method stub
    null.asInstanceOf[T]
  }

  @throws(classOf[SQLException])
  override def getConnection() : Connection = {
    DriverManager.getConnection("jdbc:h2:myH2")
  }

  @throws(classOf[SQLException])
  override def getConnection(user: String, password: String) : Connection = {
    DriverManager.getConnection("jdbc:h2:myH2", user, password)
  }

}

However, I’m running into a compilation problem with the unwrap function… with the compiler telling me that it doesn’t override anything.

Here is a side-by-side comparison of unwrap… the first auto-generated in Java, and the second translated into Scala by myself. Can anyone spot what I’m doing wrong, such that the compiler wouldn’t recognize them as equivalent?

@Overrride
public <T> T unwrap(Class<T> iface) throws SQLException {
   return null;
}

...

@throws(classOf[SQLException])
override def unwrap[T](iface: java.lang.Class[_]) : T = {
  null.asInstanceOf[T]
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T14:09:59+00:00Added an answer on June 6, 2026 at 2:09 pm

    Try:

    @throws(classOf[SQLException])
    override def unwrap[T](iface: Class[T]) : T = {
      null.asInstanceOf[T]
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I just found some scala code which has a strange class name: class `This
I'm looking to unit testing as a means of regression testing on a project.
I'm new to unit testing and NUit in particular. I'm just typing some examples
I just bought The Art of Unit Testing from Amazon. I'm pretty serious about
I know unit testing but haven't done unit testing for silverlight project yet. Can
How to write a unit testing case for custom spring validator implementation class .
For unit testing purposes I'm trying to write a mock object of a class
I'm writing a unit testing platform and I want to be able to dynamically
I am using .net unit testing in my project. I would like to know
I am using .net unit testing in my project. I can unit test, get

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.