I am trying to mock the FileStatus class from the Hadoop common API Java library. The following compiler errors result:
Error:(34, 24) double definition:
override def compareTo(o: Any): Int at line 34 and
override def compareTo(x$1: T): Int at line 34
have same type after erasure: (o: Object)Int
val mockFile = mock[FileStatus]
Error:(34, 24) name clash between defined and inherited member:
def compareTo(x$1: T): Int in trait Comparable and
override def compareTo(o: Any): Int at line 34
have same type after erasure: (x$1: Object)Int
val mockFile = mock[FileStatus]
The problem may be with the fact that this class extends Comparable
without specifying any type parameters. The relevant Java snippet from its source code can be seen here:
public class FileStatus implements Writable, Comparable {
// <snipped>
@Override
public int compareTo(Object o) {
FileStatus other = (FileStatus)o;
return this.getPath().compareTo(other.getPath());
}
// <snipped>
}
To reproduce the compiler error, simply add a dependency on org.apache.hadoop:hadoop-common:2.6.5, and create the following Scalatest method:
test("my failing test") {
// your imports
import org.apache.hadoop.fs.FileStatus
// code that fails
val mockFile = mock[FileStatus]
}
Is there any way to work around this in order to allow this class to be mocked via Scalamock? For reference, this is with Scalamock 3.6.0, Scala 2.11, and Oracle JDK 1.8.0_181.