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

Cats typeclass instances for ArgumentMatcher. #255

Conversation

dangerousben
Copy link
Contributor

No description provided.

@dangerousben dangerousben force-pushed the feature/argument-matcher-instances branch from 9db3379 to 84b93d3 Compare June 22, 2020 15:07
implicit def arbArgumentMatcher[A](implicit a: Arbitrary[A => Boolean]): Arbitrary[ArgumentMatcher[A]] =
Arbitrary(a.arbitrary.map(p => new ArgumentMatcher[A] { def matches(a: A) = p(a) }))

checkAll("ArgumentMatcher[MiniInt]", ContravariantMonoidalTests[ArgumentMatcher].contravariantMonoidal[MiniInt, MiniInt, MiniInt])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be nice to also have tests that show how to use these, and that will also prove that the macro is not messing up with them.
We can even fix the macro so we can add a specific call for these

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be just adding one or more strings to org.mockito.Utils.MockitoMatchers :)
in case they have symbolic syntax (ie *> or whatever) look at like 48 for an examples

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think stuff like this actually lessens the need for macro support, because the more convenient it is to combine and transform matchers, the less of a hassle it is to add in an argThat once done. I'll write up some example tests as suggested to test this theory though.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Of course, the less we rely on macros, the better :)

@dangerousben dangerousben force-pushed the feature/argument-matcher-instances branch from cc9df38 to 28c2b65 Compare June 22, 2020 18:18
@ultrasecreth
Copy link
Member

It looks like there is an issue with Scala 2.11

This is the output from CI, to test this locally you can run sbt clean +test (the + is what it makes it cross compile and run the tests in all the supported Scala versions)

[error]  found   : org.mockito.internal.matchers.Any
[error]  required: org.mockito.ArgumentMatcher[scala.Any]
[error] Note: Object <: Any (and org.mockito.internal.matchers.Any <: org.mockito.ArgumentMatcher[Object]), but Java-defined trait ArgumentMatcher is invariant in type T.
[error] You may wish to investigate a wildcard type such as `_ <: Any`. (SLS 3.2.10)
[error]       override def unit                                                          = narrow[scala.Any, Unit](Any.ANY)
[error]                                                                                                                ^
[error] /home/travis/build/mockito/mockito-scala/cats/src/main/scala/org/mockito/cats/instances/argumentMatcher.scala:19:109: type mismatch;
[error]  found   : org.mockito.internal.matchers.Any
[error]  required: org.mockito.ArgumentMatcher[scala.Any]
[error] Note: Object <: Any (and org.mockito.internal.matchers.Any <: org.mockito.ArgumentMatcher[Object]), but Java-defined trait ArgumentMatcher is invariant in type T.
[error] You may wish to investigate a wildcard type such as `_ <: Any`. (SLS 3.2.10)
[error]       override def empty[A]                                                      = narrow[scala.Any, A](Any.ANY)
[error]                                                                                                             ^
[error] two errors found

@ultrasecreth ultrasecreth merged commit 3769133 into mockito:release/1.x Jun 23, 2020
@dangerousben dangerousben deleted the feature/argument-matcher-instances branch June 23, 2020 09:36
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

Successfully merging this pull request may close these issues.

None yet

2 participants