• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

scoverage / sbt-scoverage-samples / #47

pending completion
#47

push

Roland Tritsch
Add sys.props to configure plugin versions (to support sbt-test ...

96 of 126 relevant lines covered (76.19%)

0.76 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

78.95
/src/main/scala/org/scoverage/samples/Futures.scala
1
package org.scoverage.samples
2

3
import scala.concurrent.{Promise, Future, ExecutionContext}
4
import scala.language.implicitConversions
5

6
class Futures {
7

8
  import EitherMappableFuture._
9

1✔
10
  def insert[T](
11
      doc: T
12
  )(implicit name: String, executor: ExecutionContext): Future[Result] = {
1✔
13
    val promise = Promise[Result]()
1✔
14
    Future {
15
      Thread.sleep(300)
1✔
16
    }.onComplete { case _ =>
1✔
17
      promise.success(Result(true, 421))
18
    }
1✔
19
    promise.future.mapEither(meaningful)
20
  }
21

1✔
22
  def check(result: Result): Either[Exception, Result] = Right(result)
23

1✔
24
  def meaningful(result: Result) = {
1✔
25
    check(result) match {
×
26
      case Left(e)  => Left(e)
1✔
27
      case Right(r) => Right(r)
28
    }
29
  }
30
}
31

32
case class Result(
×
33
    success: Boolean = true,
×
34
    status: Int = 200,
1✔
35
    timestamp: Long = System.currentTimeMillis
36
)
37

38
case class EitherMappableFuture[A](future: Future[A]) {
1✔
39
  def mapEither[E <: Throwable, B](
40
      f: A => Either[E, B]
41
  )(implicit ec: ExecutionContext): Future[B] = {
1✔
42
    future.flatMap(f(_) match {
×
43
      case Left(e)  => Future.failed(e)
1✔
44
      case Right(b) => Future.successful(b)
45
    })
46
  }
47
}
48
object EitherMappableFuture {
1✔
49
  implicit def futureToEitherMappable[A](
50
      future: Future[A]
51
  ): EitherMappableFuture[A] = EitherMappableFuture(future)
52
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc