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

NullPointerException trying to use AsyncMockFactory in async scalatest #215

Closed
lj-ditrapani opened this issue Feb 4, 2018 · 6 comments
Closed
Labels
Milestone

Comments

@lj-ditrapani
Copy link
Contributor

lj-ditrapani commented Feb 4, 2018

ScalaMock Version

4.0.0

Scala Version

2.12.4

Runtime

JVM 1.8

Please describe the expected behavior of the issue

Using "scalatest" % "3.0.5" & sbt.version=1.1.0, I expect to execute simple async test using AsyncMockFactory.

Please provide a description of what actually happens

Examples compile, but throw NullPointerException at runtime.

Reproducible Test Case

package example

import org.scalamock.scalatest.AsyncMockFactory
import org.scalatest.AsyncFreeSpec

class ExampleTest extends AsyncFreeSpec {
  "runs fine" in {
    succeed
  }

  "this also runs fine" in {
    scala.concurrent.Future.successful { assert(true) }
  }
}

class AsyncExampleTest extends AsyncFreeSpec with AsyncMockFactory {
  "NPE!" in {
    succeed
  }

  "NPE again!" in {
    scala.concurrent.Future.successful { succeed }
  }

  "NPE a 3rd time!" in {
    trait Trait {
      def foo(): Int
    }
    val x = mock[Trait]
    (() => x.foo()).expects().returning(5)
    scala.concurrent.Future.successful { assert(x.foo() == 5) }
  }
}

Also, if I try to downgrade to scalamock 3.6.0, I get

[error] /home/blah/scalamock-example/src/test/scala/example.scala:3:12: object scalamock is not a member of package org
[error] import org.scalamock.scalatest.AsyncMockFactory
[error]            ^
@barkhorn
Copy link
Collaborator

barkhorn commented Feb 5, 2018

Hi I just recently merged PR #214 which sounds very similar. Could you please try the latest snapshot build and let me know if that works?

resolvers += "Sonatype OSS Snapshots" at "https://oss.sonatype.org/content/repositories/snapshots"

and scalamock version "4.1.0-SNAPSHOT"

@lj-ditrapani
Copy link
Contributor Author

4.1.0-SNAPSHOT works properly.

lj-ditrapani added a commit to lj-ditrapani/ScalaMock that referenced this issue Feb 5, 2018
@lj-ditrapani
Copy link
Contributor Author

BTW, thanks for the quick response!

@barkhorn barkhorn added this to the v4.1.0 milestone Feb 8, 2018
@barkhorn
Copy link
Collaborator

barkhorn commented Feb 8, 2018

Will add a comment here when 4.1.0 is published (aiming for Feb 17th)

@barkhorn barkhorn added the bug label Feb 8, 2018
@mucahitkantepe
Copy link

Getting same error in version 4.0.0

4.1.0-SNAPSHOT works.

barkhorn added a commit that referenced this issue Feb 17, 2018
@barkhorn
Copy link
Collaborator

4.1.0 is syncing with maven central right now

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

No branches or pull requests

3 participants