From 7fd502f6ddcc0c89ad44638391e038aed5488a03 Mon Sep 17 00:00:00 2001 From: Georgii Kovalev Date: Tue, 1 Oct 2024 19:59:32 +0500 Subject: [PATCH] readme about generic types --- README.md | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/README.md b/README.md index 34a6733..419eb6e 100644 --- a/README.md +++ b/README.md @@ -247,6 +247,29 @@ val overloaded = stub[Overloaded]: .method(_.overloaded: (Int, Boolean) => Int).returns((x, y) => x) ``` +### Generic types support + +Current implementation has restriction of 1 expectation per method. +It is same for generic types (Maybe it will change in the future if I find a solution). + +```scala 3 +import backstub.* + +trait TypeArgs: + def typeArgs[A](x: A): A + +val typeArgsStub = stub[TypeArgs]: + Expect[TypeArgs]: + .method(_.typeArgs[Int]).returns(x => x) + +typeArgsStub.typeArgs[Int](2) + +typeArgsStub.times(_.typeArgs) +typeArgsStub.calls(_.typeArgs) + +``` + + ## Example Model - [SessionCheckService.scala](modules/core/src/test/scala/backstub/SessionCheckService.scala)