org.mockito.internal.matchers.LocalizedMatcher cannot be cast to org.mockito.ArgumentMatcher with "any" matcher when running "activator test" - scala

I'm having an error in one of my specs2 tests. The project is implemented with Play!Framework (Scala).
This is my test:
class AmazonEmailSenderSpec extends Specification with Mockito {
"AmazonEmailSenderSpec#sendEmail" should {
"Send Email with correct data" in {
val client = mock[AmazonSimpleEmailServiceAsyncClient]
val emailSender = new AmazonEmailSender(client)
emailSender.sendEmail(Email(subject, content, from, to, cc))
val captor = ArgumentCaptor.forClass(classOf[SendEmailRequest])
there was one(client).sendEmail(captor.capture)
val sendEmailRequest: SendEmailRequest = captor.getValue
}
}
}
This test works fine if I run it on intellij, but somehow, it fails when I run it on the console using the play activator:
activator test
I get:
[info] AmazonEmailSenderSpec#sendEmail should
[error] ! Send Email with correct data
[error] org.mockito.internal.matchers.LocalizedMatcher cannot be cast to org.mockito.ArgumentMatcher (ArgumentsComparator.java:25)
[error] org.mockito.internal.invocation.ArgumentsComparator.argumentsMatch(ArgumentsComparator.java:25)
[error] org.mockito.internal.invocation.ArgumentsComparator.argumentsMatch(ArgumentsComparator.java:17)
[error] org.mockito.internal.invocation.InvocationMatcher.matches(InvocationMatcher.java:56)
[error] org.mockito.internal.invocation.InvocationsFinder$RemoveNotMatching.isOut(InvocationsFinder.java:145)
[error] org.mockito.internal.invocation.InvocationsFinder$RemoveNotMatching.isOut(InvocationsFinder.java:137)
[error] org.mockito.internal.util.collections.ListUtil.filter(ListUtil.java:16)
[error] org.mockito.internal.invocation.InvocationsFinder.findInvocations(InvocationsFinder.java:20)
[error] org.mockito.internal.verification.checkers.MissingInvocationChecker.check(MissingInvocationChecker.java:32)
[error] org.mockito.internal.verification.Times.verify(Times.java:36)
[error] org.mockito.internal.verification.MockAwareVerificationMode.verify(MockAwareVerificationMode.java:21)
[error] org.mockito.internal.handler.MockHandlerImpl.handle(MockHandlerImpl.java:76)
[error] org.mockito.internal.handler.NullResultGuardian.handle(NullResultGuardian.java:29)
[error] org.mockito.internal.handler.InvocationNotifierHandler.handle(InvocationNotifierHandler.java:37)
[error] org.mockito.internal.creation.bytebuddy.MockMethodInterceptor.doIntercept(MockMethodInterceptor.java:36)
[error] org.mockito.internal.creation.bytebuddy.MockMethodInterceptor.access$000(MockMethodInterceptor.java:17)
[error] org.mockito.internal.creation.bytebuddy.MockMethodInterceptor$DispatcherDefaultingToRealMethod.interceptSuperCallable(MockMethodInterceptor.java:96)
[error] com.amazonaws.services.simpleemail.AmazonSimpleEmailServiceAsyncClient$MockitoMock$1778874818.sendEmail(Unknown Source)
[error] integration.email.AmazonEmailSenderSpec$$anonfun$1$$anonfun$apply$11$$anonfun$apply$12.apply(AmazonEmailSenderSpec.scala:27)
[error] integration.email.AmazonEmailSenderSpec$$anonfun$1$$anonfun$apply$11$$anonfun$apply$12.apply(AmazonEmailSenderSpec.scala:27)
[error] integration.email.AmazonEmailSenderSpec$$anonfun$1$$anonfun$apply$11.apply(AmazonEmailSenderSpec.scala:27)
[error] integration.email.AmazonEmailSenderSpec$$anonfun$1$$anonfun$apply$11.apply(AmazonEmailSenderSpec.scala:19)
I can't understand why a LocalizedMatcher is being used by activator when an ArgumentMatcher should be used instead.
The signature to the method I'm trying to match is:
public SendEmailResult sendEmail(SendEmailRequest sendEmailRequest)
Couldn't really find any hints on google. Any ideas? Am I missing something really silly?

This is an old question, but I just happened to run into the same issue in 2017:
A solution that worked for me (JUnit/Specs2, in a mixed Java/Scala) project:
I forced mockito to use the latest version 2.7.11. But I also had a dependency on org.specs2:specs2-mock_2.12:3.8.6 which is still based on mockito 1.9.5. See maven central.
Somewhere here lies the problem. I removed the dependency on specs2-mock and Specs2's mockito syntax sugar and replaced it with plain mockito code. Voila! The error mentioned above was gone.

Related

sbt / native-packager, new jdeps error: java.lang.module.FindException: Module java.activation not found, required by java.xml.bind

I have not changed my setup as far as I can see. As of today, trying to run sbt native packager with jlink gives this error:
[info] Running: jdeps --multi-release 11 -R ...
[error] Exception in thread "main" java.lang.module.FindException: Module java.activation not found, required by java.xml.bind
[error] at java.base/java.lang.module.Resolver.findFail(Resolver.java:877)
[error] at java.base/java.lang.module.Resolver.resolve(Resolver.java:191)
[error] at java.base/java.lang.module.Resolver.resolve(Resolver.java:140)
[error] at java.base/java.lang.module.Configuration.resolve(Configuration.java:422)
[error] at java.base/java.lang.module.Configuration.resolve(Configuration.java:256)
[error] at jdk.jdeps/com.sun.tools.jdeps.JdepsConfiguration$Builder.build(JdepsConfiguration.java:564)
[error] at jdk.jdeps/com.sun.tools.jdeps.JdepsTask.buildConfig(JdepsTask.java:603)
[error] at jdk.jdeps/com.sun.tools.jdeps.JdepsTask.run(JdepsTask.java:557)
[error] at jdk.jdeps/com.sun.tools.jdeps.JdepsTask.run(JdepsTask.java:533)
[error] at jdk.jdeps/com.sun.tools.jdeps.Main.run(Main.java:64)
[error] at jdk.jdeps/com.sun.tools.jdeps.Main$JDepsToolProvider.run(Main.java:73)
[error] at java.base/java.util.spi.ToolProvider.run(ToolProvider.java:137)
[error] at ru.eldis.toollauncher.ToolLauncher.runTool(ToolLauncher.java:68)
[error] at ru.eldis.toollauncher.ToolLauncher.lambda$main$1(ToolLauncher.java:33)
[error] at ru.eldis.toollauncher.ToolLauncher.main(ToolLauncher.java:48)
How do I fix this? I tried adding javax.activation to libraryDependencies, that doesn't seem to have any effect or anything to do with this problem.
Edit: The root problem of seems to be my dependency on Pi4j 1.4, which depends on javax.xml.bind:jaxb-api which in turn depends on javax.activation:javax.activation-api. Now I don't understand much of this Java module stuff, but javax.activation-api does exist on Maven, so why does jdeps complain? If I exclude javax.xml.bind, it works, but now I'm worried I'm actually missing stuff on the class path.
javax.activation has been removed since java 11.
To fix it you can:
Download the javax.activation jar and run the command by adding this jar on module path:
jdeps --multi-release 11 -R --module-path path\to\javax.activation.jar ...
Running this command with java 8 jdeps

How can I resolve Scala package name conflicts?

package net.kolotyluk
package object leaderboard {
def randomLong: Long = {
val random = scala.util.Random
random.setSeed(System.nanoTime)
random.nextLong
}
}
Fails to compile with
[error] D:\Users\erick\repos\leaderboard\src\main\scala\net\kolotyluk\leaderboard\package.scala:7:24: object util is not a member of package net.kolotyluk.scala
[error] val random = scala.util.Random
[error] ^
[error] one error found
[error] (compile:compileIncremental) Compilation failed
I suspect the problem is I have package net.kolotyluk.scala.extras defined elsewhere. Why is it that Scala cannot find scala.util.Random? This seems like a defect in either the Scala compiler, or the Scala language itself.
Is there a way to import/specify an absolute package name instead of the relative package name which seems to be used here?
Using import __root__.scala.util.Random does not seem to work either as mentioned in https://docs.scala-lang.org/tour/packages-and-imports.html because
[error] D:\Users\erick\repos\leaderboard\src\main\scala\net\kolotyluk\leaderboard\package.scala:3:8: not found: object __root__
[error] import __root__.scala.util.Random
[error] ^
Doh! the documentation at https://docs.scala-lang.org/tour/packages-and-imports.html is wrong. It should be _root_ not __root__

Using Play 2.4 with a renamed `conf/routes` file

My simple Play 2.4 project does not compile when I rename the conf/routes file to something else, e.g. conf/hello.routes. The reason I'm doing this is to enable composition of APIs while allowing them to be developed in separate git repositories and sbt projects.
The idea of multiproject support is based on this project and blog post - but that's using Play 2.3.
The error I get is:
$ sbt test
...
[info] Hello should
[error] ! give {hello: true}
[error] Unable to provision, see the following errors:
[error]
[error] 1) Error in custom provider, java.lang.ClassCastException: interface play.api.routing.Router is not assignable from class hello.routes
[error] while locating play.api.test.FakeRouterProvider
[error] while locating play.api.routing.Router
[error]
[error] 1 error (InjectorImpl.java:1025)
[error] com.google.inject.internal.InjectorImpl$2.get(InjectorImpl.java:1025)
[error] com.google.inject.internal.InjectorImpl.getInstance(InjectorImpl.java:1051)
[error] play.api.inject.guice.GuiceInjector.instanceOf(GuiceInjectorBuilder.scala:321)
[error] play.api.inject.guice.GuiceInjector.instanceOf(GuiceInjectorBuilder.scala:316)
...
Got this resolved (code in the git repo now works).
The problems were likely connected to both of these:
the Controller implementation wants to be within a package controllers.hello instead of just hello
in the application.conf file one should omit the controllers namespace, i.e.
play.http.router = app.Routes
I learned this simply by comparing this code with samples that work.

Error message when trying to run a Mockito test in Play

I'm trying to run the following code in a test class in my play application to test Mockito:
trait DateWSClient {
def currentDate: String
}
class DateProvider (dateWS: DateWSClient) {
def currentYear = {
dateWS.currentDate.split("/")(0)
}
}
import org.specs2._
import org.specs2.mock.Mockito
class DateProviderSpec extends mutable.Specification with Mockito {
"currentYear" should {
"be the first part of the date returned by the WS" in {
val clientMock = mock[DateWSClient]
val formatter = new DateProvider(clientMock)
clientMock.currentDate returns "2013/08/07"
formatter.currentYear must beEqualTo("2013")
}
}
}
I got it from this article: http://workwithplay.com/blog/2013/08/07/mocking-with-mockito/
However when I run 'test' in the play terminal, I get the following error message:
[error] bad symbolic reference. A signature in MocksCreation.class refers to type MockSettings
[error] in package org.mockito which is not available.
[error] It may be completely missing from the current classpath, or the version on
[error] the classpath might be incompatible with the version used when compiling MocksCreation.class.
[error] bad symbolic reference. A signature in MockitoStubs.class refers to term stubbing
[error] in package org.mockito which is not available.
[error] It may be completely missing from the current classpath, or the version on
[error] the classpath might be incompatible with the version used when compiling MockitoStubs.class.
[error] two errors found
The same problem is described here: Error using Mockito and Specs2, however this sollution doesn't change anything for me.
What does this error message mean exactly? And how do I solve this problem?
The version of play I use is: 2.1.2
"org.mockito" % "mockito-core" % "1.9.5" needs to be added to the list of dependencies.
See the Play documentation on dependencies on how to do that.

GWT compilation problem The constructor StackTraceElement(String, String, String, int) is undefined

I am compiling my GWT module in Eclipse that inherits my other module (that compiles without problems) and I get this output:
Compiling module mymodule.GWT_TESTS
Validating newly compiled units
[ERROR] Errors in 'jar:file:/C:/apath/gwt-2.0.4/gwt-user.jar!/com/google/gwt/core/client/impl/StackTraceCreator.java'
[ERROR] Line 70: The constructor StackTraceElement(String, String, String, int) is undefined
[ERROR] Line 80: The constructor StackTraceElement(String, String, String, int) is undefined
[ERROR] Line 158: The constructor StackTraceElement(String, String, String, int) is undefined
[ERROR] Errors in 'file:/C:/apath/workspace/GWT_TESTS/src/mymodule/client/GWT_TESTS.java'
[ERROR] Line 7: The import mymodule.shared.FieldVerifier cannot be resolved
[ERROR] Line 122: FieldVerifier cannot be resolved
[ERROR] Errors in 'jar:file:/C:/apath/gwt-2.0.4/gwt-user.jar!/com/google/gwt/user/client/rpc/RpcRequestBuilder.java'
[ERROR] Line 167: The method getPermutationStrongName() is undefined for the type GWT
[ERROR] Errors in 'jar:file:/C:/apath/gwt-2.0.4/gwt-user.jar!/com/google/gwt/user/client/ui/TabLayoutPanel.java'
[ERROR] Line 21: The import com.google.gwt.dom.client.Style.Display cannot be resolved
[ERROR] Line 22: The import com.google.gwt.dom.client.Style.Unit cannot be resolved
[ERROR] Line 118: Style.Float cannot be resolved
[ERROR] Line 143: Unit cannot be resolved to a type
[ERROR] Line 153: Unit cannot be resolved to a type
[ERROR] Line 155: Unit cannot be resolved to a type
[ERROR] Line 161: Unit cannot be resolved
[ERROR] Line 161: Unit cannot be resolved
[ERROR] Line 162: Unit cannot be resolved
[ERROR] Line 167: Unit cannot be resolved
[ERROR] Line 390: Display cannot be resolved
[ERROR] Line 397: The method clearDisplay() is undefined for the type Style
[ERROR] Line 481: Unit cannot be resolved
[ERROR] Line 481: Unit cannot be resolved
[ERROR] Line 482: Unit cannot be resolved to a type
[ERROR] Line 482: Unit cannot be resolved
[ERROR] Line 484: Display cannot be resolved
[ERROR] Errors in 'jar:file:/C:/apath/gwt-2.0.4/gwt-user.jar!/com/google/gwt/user/client/ui/SubmitButton.java'
[ERROR] Line 49: The method getButtonElement() from the type Button is not visible
[ERROR] Line 62: The method createSubmitButtonElement() is undefined for the type Document
[ERROR] Unexpected
java.lang.NullPointerException
at com.google.gwt.dev.javac.CompiledClass.<init>(CompiledClass.java:81)
at com.google.gwt.dev.javac.JdtCompiler$FindTypesInCud.visit(JdtCompiler.java:204)
at org.eclipse.jdt.internal.compiler.ast.TypeDeclaration.traverse(TypeDeclaration.java:1198)
at org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration.traverse(CompilationUnitDeclaration.java:687)
at com.google.gwt.dev.javac.JdtCompiler$CompilerImpl.process(JdtCompiler.java:158)
at org.eclipse.jdt.internal.compiler.Compiler.compile(Compiler.java:444)
at com.google.gwt.dev.javac.JdtCompiler.doCompile(JdtCompiler.java:467)
at com.google.gwt.dev.javac.CompilationStateBuilder$CompileMoreLater.compile(CompilationStateBuilder.java:142)
at com.google.gwt.dev.javac.CompilationStateBuilder.doBuildFrom(CompilationStateBuilder.java:281)
at com.google.gwt.dev.javac.CompilationStateBuilder.buildFrom(CompilationStateBuilder.java:182)
at com.google.gwt.dev.cfg.ModuleDef.getCompilationState(ModuleDef.java:280)
at com.google.gwt.dev.Precompile.precompile(Precompile.java:502)
at com.google.gwt.dev.Precompile.precompile(Precompile.java:414)
at com.google.gwt.dev.Compiler.run(Compiler.java:201)
at com.google.gwt.dev.Compiler$1.run(Compiler.java:152)
at com.google.gwt.dev.CompileTaskRunner.doRun(CompileTaskRunner.java:87)
at com.google.gwt.dev.CompileTaskRunner.runWithAppropriateLogger(CompileTaskRunner.java:81)
at com.google.gwt.dev.Compiler.main(Compiler.java:159)
My module definition is:
<module>
<inherits name='com.google.gwt.user.User'/>
<inherits name="com.google.gwt.i18n.I18N"/>
<inherits name='othermodule.Main' />
<entry-point class='mymodule.client.GWT_TESTS'/>
</module>
How to resolve this kind of compilation problem? Am I forgetting inheriting from other modules (I tried to add the those where classes were not resolved even they should be inherited via User module and it did not help)? Is there anything in my Eclipse project setting that I am missing (mymodule is in a separate project, GWT configured, gwt 2.0.4, other modules and JARs are set in project dependencies)?
I deleted the project and recreated it again and it works now. I originally used GWT that came with Eclipse plugin (2.3.0) but then I had to change GWT version to 2.0.4. Either changing the GWT version for existing project or another of my change when I was resolving the problem caused the error.