Skip to content

Instantly share code, notes, and snippets.

@choplin
Last active February 17, 2020 14:59
Show Gist options
  • Save choplin/a52a1c67582371d21a9837db253eefae to your computer and use it in GitHub Desktop.
Save choplin/a52a1c67582371d21a9837db253eefae to your computer and use it in GitHub Desktop.
import wvlet.airframe._
import wvlet.airspec._
case class Wrap[A](a: A)
trait Algebra[M[_]] {
def f: M[Int]
}
trait Service[A[_]] {
private val alg = bind[Algebra[A]]
}
trait ConcreteService {
private val alg = bind[Algebra[Wrap]]
}
trait Impl extends Algebra[Wrap] {
override def f: Wrap[Int] = Wrap(0)
}
class HigherKindedInjectionTest extends AirSpec {
override def design: Design =
Design.newDesign
.bind[App].toSingleton
.bind[Algebra[Wrap]].to[Impl]
.bind[Service[Wrap]].toSingleton
.bind[ConcreteService].toSingleton
test("Algebra[Wrap] should be built") { _: Algebra[Wrap] =>
}
test("ConcreteService") { _: ConcreteService =>
}
test("Service[Wrap] should be built") { _: Service[Wrap] =>
}
}
HigherKindedInjectionTest:
- design 6.61ms
- Algebra[Wrap] should be built 16.41ms
- ConcreteService 3.99ms
2020-02-17 23:57:13.421+0900 warn [AirframeSession] [session:26148878 -> session:5dde9211] No binding nor the default constructor for Algebra[A] at HigherKindedInjectionTest.scala:11 is found. Add bind[Algebra[A]].toXXX to your design or dependencies. The dependency order is: [Algebra[A]] - (AirframeSession.scala:452)
- Service[Wrap] should be built 27.49ms << error: Failed to call HigherKindedInjectionTest.`Service[Wrap] should be built`. Missing dependency for Service[Wrap[_]]:
[MISSING_DEPENDENCY] Binding for Algebra[A] at HigherKindedInjectionTest.scala:11 is not found: Algebra[A]
wvlet.airspec.spi.MissingTestDependency: Failed to call HigherKindedInjectionTest.`Service[Wrap] should be built`. Missing dependency for Service[Wrap[_]]:
[MISSING_DEPENDENCY] Binding for Algebra[A] at HigherKindedInjectionTest.scala:11 is not found: Algebra[A]
at wvlet.airspec.AirSpecDef.resolveArg(AirSpecDef.scala:31)
at wvlet.airspec.AirSpecDef.resolveArg$(AirSpecDef.scala:14)
at wvlet.airspec.AirSpecDefF1.resolveArg(AirSpecDef.scala:58)
at wvlet.airspec.AirSpecDefF1.run(AirSpecDef.scala:67)
at wvlet.airspec.runner.AirSpecTaskRunner.$anonfun$runSingle$7(AirSpecTaskRunner.scala:197)
at scala.util.Try$.apply(Try.scala:210)
at wvlet.airspec.runner.AirSpecTaskRunner.$anonfun$runSingle$6(AirSpecTaskRunner.scala:196)
at wvlet.airframe.Session.withChildSession(Session.scala:117)
at wvlet.airframe.Session.withChildSession$(Session.scala:113)
at wvlet.airframe.AirframeSession.withChildSession(AirframeSession.scala:32)
at wvlet.airspec.runner.AirSpecTaskRunner.runSingle(AirSpecTaskRunner.scala:184)
at wvlet.airspec.runner.AirSpecTaskRunner.$anonfun$runSpec$6(AirSpecTaskRunner.scala:140)
at wvlet.airspec.runner.AirSpecTaskRunner.$anonfun$runSpec$6$adapted(AirSpecTaskRunner.scala:139)
at scala.collection.IterableOnceOps.foreach(IterableOnce.scala:553)
at scala.collection.IterableOnceOps.foreach$(IterableOnce.scala:551)
at scala.collection.AbstractIterable.foreach(Iterable.scala:921)
at wvlet.airspec.runner.AirSpecTaskRunner.$anonfun$runSpec$5(AirSpecTaskRunner.scala:139)
at scala.runtime.java8.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.scala:18)
at wvlet.airframe.Session.start(Session.scala:133)
at wvlet.airframe.Session.start$(Session.scala:130)
at wvlet.airframe.AirframeSession.start(AirframeSession.scala:32)
at wvlet.airspec.runner.AirSpecTaskRunner.runSpec(AirSpecTaskRunner.scala:139)
at wvlet.airspec.runner.AirSpecTaskRunner.run(AirSpecTaskRunner.scala:106)
at wvlet.airspec.runner.AirSpecTaskRunner.$anonfun$runTask$1(AirSpecTaskRunner.scala:62)
at scala.runtime.java8.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.scala:18)
at wvlet.airspec.Compat$.withLogScanner(Compat.scala:77)
at wvlet.airspec.runner.AirSpecTaskRunner.runTask(AirSpecTaskRunner.scala:49)
at wvlet.airspec.runner.AirSpecTask.execute(AirSpecTask.scala:64)
at wvlet.airspec.runner.AirSpecTask.execute(AirSpecTask.scala:42)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
Execution took 52ms
4 tests, 3 passed, 1 errors
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment