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

Problematic argThat implicit conversion in Mockito #260

Closed
emrecelikten opened this issue May 2, 2014 · 3 comments
Closed

Problematic argThat implicit conversion in Mockito #260

emrecelikten opened this issue May 2, 2014 · 3 comments

Comments

@emrecelikten
Copy link

Consider the following snippet:

import org.specs2.matcher.Matcher
import org.specs2.mock.Mockito
import org.specs2.mutable.Specification

class ArgThatProblemSpec extends Specification with Mockito {
  def beTrueCustom: Matcher[Boolean] = beTrue ^^ {(t: Boolean) => t}

  def someFun(x: Int): Boolean = true
  def someFun2(x: Int): (Option[String], Boolean) = (Some("Test"), true)

  "ArgThat" should {
    "not apply here" in {
      someFun(42) must beTrueCustom
      someFun2(42) must beTrueCustom
    }
  }
}

There should be a compile error for the second case as a matcher of Matcher[Boolean] should not match an (Option[String], Boolean). Instead, I get this:

[info] ArgThatProblemSpec
[info]
[info] ArgThat should
[info] ! not apply here
[error]    ClassCastException: : java.lang.Boolean cannot be cast to org.specs2.matcher.Matcher  (ArgThatProblemSpec.scala:33)
[error] ArgThatProblemSpec$$anonfun$1$$anonfun$apply$2.apply(ArgThatProblemSpec.scala:33)
[error] ArgThatProblemSpec$$anonfun$1$$anonfun$apply$2.apply(ArgThatProblemSpec.scala:31)
[info]
[info]
[info] Total for specification ArgThatProblemSpec
[info] Finished in 45 ms
[info] 1 example, 0 failure, 1 error

Indeed, that is the case when I remove the Mockito mixin:

ArgThatProblemSpec.scala:14: type mismatch;
[error]  found   : org.specs2.matcher.Matcher[Boolean]
[error]  required: org.specs2.matcher.Matcher[(Option[String], Boolean)]
[error]       someFun2(42) must beTrueCustom

Apparently the implicit conversion in ArgThat causes this.

One more thing: ArgThat mixin in Mockito seems to be redundant as MockitoMatchers already includes that.

Using Scala 2.10.4 and specs2 2.3.11.

Thanks,

Emre

@emrecelikten
Copy link
Author

Even this one compiles, although I am not sure how:

"ArgThat" should {
  "not apply here" in {
    val something: Either[String, Exception] = beTrueCustom

    println(something)

    1===1
  }
}

It prints null.

@etorreborre
Copy link
Owner

This is related to this issue. I'm still trying to find a good way out, both flexible and safe.

@emrecelikten
Copy link
Author

Thanks again, Eric.

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