Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Errors when trying to mock Java class that extends Comparable #259

Closed
jeff303 opened this issue May 20, 2019 · 2 comments
Closed

Errors when trying to mock Java class that extends Comparable #259

jeff303 opened this issue May 20, 2019 · 2 comments

Comments

@jeff303
Copy link

jeff303 commented May 20, 2019

ScalaMock Version

3.6.0

Scala Version

2.11

Runtime (JVM or JS)

Oracle JDK 1.8.0_181

Please describe the expected behavior of the issue

I expect to be able to mock such a class and do all the normal mock-related operations.

Please provide a description of what actually happens

I am trying to mock the FileStatus class (source code here) 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 = stub[MockFileStatus]
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 = stub[MockFileStatus]

The problem seems to be with the fact that this class extends Comparable without specifying any type parameters.

Any workarounds (however ugly) are welcomed. Thank you.

Reproducible Test Case

Note: you will need to add a dependency on hadoop-common 2.6.5.

test("my failing test") {
  // your imports
  import org.apache.hadoop.fs.FileStatus
  // code that fails
  val mockFile = mock[FileStatus]
}
@barkhorn
Copy link
Collaborator

Please use Stackoverflow for seeking help. This place is for reporting bugs only

@jeff303
Copy link
Author

jeff303 commented May 21, 2019

My apologies; I thought this was a similar case to #86, which had some discussion, but I guess it's not. Will post to SO instead.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants