Packages

t

org.scalamock.ziotest

SimplerZIOMockMigration

trait SimplerZIOMockMigration extends AnyRef

Can simplify migration from zio-mock to scalamock. Not needed when writing tests on scalamock from scratch.

Linear Supertypes
AnyRef, Any
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. SimplerZIOMockMigration
  2. AnyRef
  3. Any
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. All

Value Members

  1. final def !=(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  2. final def ##(): Int
    Definition Classes
    AnyRef → Any
  3. final def ==(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  4. final def asInstanceOf[T0]: T0
    Definition Classes
    Any
  5. def clone(): AnyRef
    Attributes
    protected[lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( ... ) @native() @HotSpotIntrinsicCandidate()
  6. macro def createMockedLayer[A](expectations: URIO[A, Any])(implicit tag: Tag[A]): ULayer[A]

    Creates a layer that creates a new mock.

    Creates a layer that creates a new mock.

    WARN: use with caution, provide only one Layer of each type!

    In zio-mock there's an implicit conversion from Expectation[A] to ULayer[A]. In scalamock, instead of Expectation, URIO[A, Any] can be used. To avoid rewriting the passing of expectations to layers, an analogous conversion is defined.

    It's not declared as implicit to avoid unnecessary bugs, it has to be called manually.

    WARN: when passing effects to layers carelessly, unexpected behavior can occur: creation of mocks that we didn't want to create.

    Example:

    test("creation of two mocks") {
      val layer1 = createMockedLayer(
        ZIO.serviceWith[Service] { mock =>
          (mock.f _).expects(42).returnsZIO("-42")
        }
      )
      val layer2 = createMockedLayer(
        ZIO.serviceWith[Service] { mock =>
          (mock.f _).expects(43).returnsZIO("-43")
        }
      )
      val effect = for {
        _ <- ZIO.serviceWith[Service] { mock =>
          (mock.f _).expects(42).returnsZIO("-42")
        }
        value <- ZIO.serviceWithZIO[Service](_.f(42))
      } yield assertTrue(value == "-42")
      effect.provideLayer(layer1 ++ layer2)
    }

    In this test, two mocks are created — one expects to be called with an argument 42, and the second — with an argument 43 (and probably creating TWO mocks is not what the developer wanted).

    So when writing tests on scalamock from scratch, it's not recommended to use this conversion (and the trait SimplerZIOMockMigration, in general). Only for simplifying the migration from zio-mock to scalamock.

    Moreover, in some cases, when there's no complex logic on layers in the test, it's possible to migrate without this trait, if you get rid of passing expectations to layers.

  7. final def eq(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  8. def equals(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  9. final def getClass(): Class[_]
    Definition Classes
    AnyRef → Any
    Annotations
    @native() @HotSpotIntrinsicCandidate()
  10. def hashCode(): Int
    Definition Classes
    AnyRef → Any
    Annotations
    @native() @HotSpotIntrinsicCandidate()
  11. final def isInstanceOf[T0]: Boolean
    Definition Classes
    Any
  12. final def ne(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  13. final def notify(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native() @HotSpotIntrinsicCandidate()
  14. final def notifyAll(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native() @HotSpotIntrinsicCandidate()
  15. final def synchronized[T0](arg0: ⇒ T0): T0
    Definition Classes
    AnyRef
  16. def toString(): String
    Definition Classes
    AnyRef → Any
  17. final def wait(arg0: Long, arg1: Int): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  18. final def wait(arg0: Long): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws( ... ) @native()
  19. final def wait(): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )

Deprecated Value Members

  1. def finalize(): Unit
    Attributes
    protected[lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( classOf[java.lang.Throwable] ) @Deprecated
    Deprecated

Inherited from AnyRef

Inherited from Any

Ungrouped