title: ScalaTest Matcher For a Java Lambda Call that's Run in a Different Thread
body: <p>In the following ScalaTest example, <code>obtainLock</code> is a Java function which takes in a <code>String</code> and two functional interfaces for success/failure calls. This occurs in an asynchronous manner, meaning the lambdas are called from a different thread.</p>
  
  <p>With the existing code, this test returns true because it exits the test block before either lambda are called. I've taken a look at the <a href="http://www.scalatest.org/user_guide/async_testing" rel="nofollow noreferrer">Async Testing Documentation for ScalaTest</a>, but I'm not sure how I'd go about writing the tests since the Java functions I'm calling don't return a <code>Future</code>. </p>
  
  <p>Is there a way to test this asynchronous code in ScalaTest? I'm using Scala 2.12, ScalaTest 0.9.6 and Java 9.</p>
  
  <pre><code>  "Acquiring locks" - {
      "Return a lock for a key with valid lease limit" in {
        locker.obtainLock(lockKeyA, suc =&gt; {
          suc.key shouldEqual "AAA"
          suc.validUntilInMs should be &gt; System.currentTimeMillis()
        }, (fmsg, lockInfo) =&gt; {
          fmsg shouldBe ""
        })
      }
  </code></pre>