I have the following code...
@RunWith(classOf[JUnitRunner])
class IdentitySuite extends AnyFunSuite with Matchers {
test("No Records returned") {
assert(true)
}
}
This works fine now I would like to add a mocked Object so I add...
testing {
suites {
// Configure the built-in test suite
test {
// Use JUnit4 test framework
useJUnit('4.13.2')
dependencies {
// Use Scalatest for testing our library
implementation 'org.scalatest:scalatest_3:3.2.12'
implementation 'org.scalatestplus:junit-4-13_3:3.2.12.0'
implementation 'org.easymock:easymock:4.3'
implementation 'org.scalatestplus:easymock-4-3_3:3.2.12.0'
runtimeOnly 'org.scala-lang.modules:scala-xml_3:2.1.0'
}
}
}
}
But when I try to add the mock
@RunWith(classOf[JUnitRunner])
class IdentitySuite extends AnyFunSuite with Matchers {
test("No Records returned") {
val cds = EasyMock.createMock(classOf[CoreDataSource])
assert(true)
}
}
I get
Caused by: java.lang.reflect.InaccessibleObjectException: Unable to make protected final java.lang.Class java.lang.ClassLoader.defineClass(java.lang.String,byte[],int,int,java.security.ProtectionDomain) throws java.lang.ClassFormatError accessible: module java.base does not "opens java.lang" to unnamed module @40f9161a
I see some old questions that point at downgrading to 15 but that isn't an option in my case.
How do I Mock a Scala class when using Java 18?