diff --git a/shared/src/main/scala-3/org/scalamock/clazz/Utils.scala b/shared/src/main/scala-3/org/scalamock/clazz/Utils.scala index a966a499..52a5cf21 100644 --- a/shared/src/main/scala-3/org/scalamock/clazz/Utils.scala +++ b/shared/src/main/scala-3/org/scalamock/clazz/Utils.scala @@ -128,10 +128,11 @@ private[clazz] class Utils(using val quotes: Quotes): def apply(tpe: TypeRepr): List[MockableDefinition] = val methods = (tpe.typeSymbol.methodMembers.toSet -- TypeRepr.of[Object].typeSymbol.methodMembers).toList - .filter(sym => !sym.flags.is(Flags.Private) && !sym.flags.is(Flags.Final) && !sym.flags.is(Flags.Mutable)) - .filterNot(sym => tpe.memberType(sym) match - case defaultParam @ ByNameType(AnnotatedType(_, Apply(Select(New(Inferred()), ""), Nil))) => true - case _ => false + .filter(sym => + !sym.flags.is(Flags.Private) && + !sym.flags.is(Flags.Final) && + !sym.flags.is(Flags.Mutable) && + !sym.name.contains("$default$") ) .zipWithIndex .map((sym, idx) => MockableDefinition(idx, sym, tpe)) diff --git a/shared/src/test/scala/com/paulbutcher/test/mock/MethodsWithDefaultParamsTest.scala b/shared/src/test/scala/com/paulbutcher/test/mock/MethodsWithDefaultParamsTest.scala index 67d6e479..b9693513 100644 --- a/shared/src/test/scala/com/paulbutcher/test/mock/MethodsWithDefaultParamsTest.scala +++ b/shared/src/test/scala/com/paulbutcher/test/mock/MethodsWithDefaultParamsTest.scala @@ -34,6 +34,8 @@ class MethodsWithDefaultParamsTest extends IsolatedSpec { trait TraitHavingMethodsWithDefaultParams { def withAllDefaultParams(a: String = "default", b: CaseClass = CaseClass(42)): String + + def withDefaultParamAndTypeParam[T](a: String = "default", b: Int = 5): T } behavior of "Mocks" @@ -84,5 +86,13 @@ class MethodsWithDefaultParamsTest extends IsolatedSpec { m.withAllDefaultParams("other", CaseClass(99)) } + they should "mock trait methods with type param and default parameters" in { + val m = mock[TraitHavingMethodsWithDefaultParams] + + (m.withDefaultParamAndTypeParam[Int] _).expects("default", 5).returns(5) + + m.withDefaultParamAndTypeParam[Int]("default", 5) shouldBe 5 + } + override def newInstance = new MethodsWithDefaultParamsTest } diff --git a/shared/src/test/scala/org/scalamock/test/scalatest/AsyncSyncMixinTest.scala b/shared/src/test/scala/org/scalamock/test/scalatest/AsyncSyncMixinTest.scala index 87d8030a..d9c3ae02 100644 --- a/shared/src/test/scala/org/scalamock/test/scalatest/AsyncSyncMixinTest.scala +++ b/shared/src/test/scala/org/scalamock/test/scalatest/AsyncSyncMixinTest.scala @@ -20,13 +20,12 @@ package org.scalamock.test.scalatest -import org.scalatest.flatspec.AnyFlatSpec -import org.scalatest._ +import org.scalatest.flatspec.{AnyFlatSpec, AsyncFlatSpec} +import org.scalamock.scalatest.{MockFactory, AsyncMockFactory} /** * Tests for issue #371 */ -@Ignore class AsyncSyncMixinTest extends AnyFlatSpec { "MockFactory" should "be mixed only with Any*Spec and not Async*Spec traits" in {