ScalaMock
ScalaMock copied to clipboard
Mocking interface that defines public clone method fails on Scala 2.13.6
ScalaMock Version
5.1.0
Scala Version
2.13.6
Runtime
JVM
Please describe the expected behavior of the issue
Creation of mock successfully compiles
Please provide a description of what actually happens
[error] ....weaker access privileges in overriding
[error] def clone(): Object (defined in trait MyInterface)
[error] override should be public;
[error] (note that def clone(): Object (defined in trait MyInterface) is abstract,
[error] and is therefore overridden by concrete protected[package lang] def clone(): Object (defined in class Object))
[error] mock[MyInterface]
Reproducible Test Case
public interface MyInterface {
public Object clone() throws CloneNotSupportedException;
}
import org.scalamock.scalatest.MockFactory
import org.scalatest.funsuite.AnyFunSuite
class Test extends AnyFunSuite with MockFactory {
test("should be able to mock") {
mock[MyInterface] // fails to compile on 2.13.6
}
}
As discussed in https://github.com/scala/bug/issues/12466 this behavior on Scala 2.13.6 is valid, so it seems ScalaMock needs to implement MyInterface
by defining a public override of clone
instead of leaving the protected
abstract from Object
.