Skip to content

Commit

Permalink
Use a fake execution context to avoid timing issues on CI (#343)
Browse files Browse the repository at this point in the history
  • Loading branch information
ultrasecreth authored Jan 10, 2021
1 parent b751841 commit 56cc1db
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 8 deletions.
2 changes: 1 addition & 1 deletion .bsp/sbt.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"name":"sbt","version":"1.4.5","bspVersion":"2.0.0-M5","languages":["scala"],"argv":["/Library/Java/JavaVirtualMachines/adoptopenjdk-11.jdk/Contents/Home/bin/java","-Xms100m","-Xmx100m","-classpath","/Users/brunobonanno/Library/Application Support/JetBrains/IntelliJIdea2020.3/plugins/Scala/launcher/sbt-launch.jar","xsbt.boot.Boot","-bsp"]}
{"name":"sbt","version":"1.4.6","bspVersion":"2.0.0-M5","languages":["scala"],"argv":["/Library/Java/JavaVirtualMachines/adoptopenjdk-11.jdk/Contents/Home/bin/java","-Xms100m","-Xmx100m","-classpath","/Users/bbonanno/Library/Application Support/JetBrains/IntelliJIdea2020.3/plugins/Scala/launcher/sbt-launch.jar","xsbt.boot.Boot","-bsp"]}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import org.scalatest.matchers.should.Matchers
import org.scalatest.wordspec.AnyWordSpec
import user.org.mockito.matchers.{ ValueCaseClassInt, ValueClass }

import scala.concurrent.ExecutionContext.Implicits.global
import user.org.mockito.SameThreadExecutionContext.Instance
import scala.concurrent.Future

class IdiomaticMockitoTest_212 extends AnyWordSpec with Matchers with IdiomaticMockito with ArgumentMatchersSugar with ScalaFutures {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import org.scalatest.prop.TableDrivenPropertyChecks
import org.scalatest.matchers.should.Matchers
import org.scalatest.wordspec.AnyWordSpec

import scala.concurrent.ExecutionContext.Implicits.global
import user.org.mockito.SameThreadExecutionContext.Instance
import scala.concurrent.Future

//noinspection RedundantDefaultArgument
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class AsyncIdiomaticMockitoTest_212 extends AsyncWordSpec with Matchers with Asy
val mockFunction = mock[() => Int]
mockFunction() returns 42

Future(mockFunction.apply())
Future(mockFunction.apply())(user.org.mockito.SameThreadExecutionContext.Instance)
.map { v =>
v shouldBe 42
mockFunction() was called
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ package user.org.mockito

import org.mockito.{ ArgumentMatchersSugar, IdiomaticMockito }
import org.scalatest.concurrent.ScalaFutures
import org.scalatest.matchers.should.Matchers
import org.scalatest.wordspec.AnyWordSpec
import user.org.mockito.SameThreadExecutionContext.Instance
import user.org.mockito.matchers.{ ValueCaseClassInt, ValueClass }

import scala.concurrent.ExecutionContext.Implicits.global
import scala.concurrent.Future
import org.scalatest.matchers.should.Matchers
import org.scalatest.wordspec.AnyWordSpec

class IdiomaticMockitoTest_213 extends AnyWordSpec with Matchers with IdiomaticMockito with ArgumentMatchersSugar with ScalaFutures {
class Foo {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import org.mockito.{ ArgumentMatchersSugar, MockitoSugar }
import org.scalatest.concurrent.ScalaFutures
import org.scalatest.prop.TableDrivenPropertyChecks

import scala.concurrent.ExecutionContext.Implicits.global
import user.org.mockito.SameThreadExecutionContext.Instance
import scala.concurrent.Future
import org.scalatest.matchers.should.Matchers
import org.scalatest.wordspec.AnyWordSpec
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package user.org.mockito

import scala.concurrent.ExecutionContext

class SameThreadExecutionContext extends ExecutionContext {
override def execute(runnable: Runnable): Unit = runnable.run()

override def reportFailure(cause: Throwable): Unit = throw cause
}

object SameThreadExecutionContext {
implicit val Instance: ExecutionContext = new SameThreadExecutionContext
}

0 comments on commit 56cc1db

Please sign in to comment.