1

I am trying to mock the awscala.dynamodbv2.DynamoDB.putConditionalMethod How would one define an expects for a method which is curried and includes a repeated parameter:

putConditional(tableName: String, attributes: (String, Any)*)(cond: Seq[(String, aws.model.ExpectedAttributeValue)]): Unit

Here's what I've got working:

(mockClient.putConditional(_: String, _: (String, Any))(_: Seq[(String, ExpectedAttributeValue)]))
    .expects("Data-Identity-Partitions", 
      *,
      Seq(
        "DatacenterId" -> exp.isNull,
        "InstanceId" -> exp.isNull,
        "TTL" -> exp.isNull
      ))

But this:

(mockClient.putConditional(_: String, _: (String, Any))(_: Seq[(String, ExpectedAttributeValue)]))
    .expects("Data-Identity-Partitions",
      Seq("DatacenterId" -> 1,
        "InstanceId" -> 0,
        "TTL" -> System.currentTimeMillis()),
      Seq(
        "DatacenterId" -> exp.isNull,
        "InstanceId" -> exp.isNull,
        "TTL" -> exp.isNull
      ))

results in the following compiler error:

[error] AwsPartitionActorSpec.scala:76: type mismatch;
[error]  found   : Seq[(String, Any)]
[error]  required: org.scalamock.matchers.MockParameter[(String, Any)]
[error]           Seq[(String, Any)]("DatacenterId" -> 1,
[error]                             ^
Mark J Miller
  • 4,751
  • 5
  • 44
  • 74

1 Answers1

0

better late than never i suppose, here's my suggestion:

  trait testtrait {
    def foo(t: String, a: (String, Any) *): Int
  }

  "foo" should "work" in {
    val m = mock[testtrait]

    m.foo _ expects where {
      case ("foo", Seq(("bar", 42L), ("baz", "mango"))) => true
      case _ => false
    } returns 5


    m.foo("foo", ("bar", 42L), ("baz", "mango")) should be (5)
  }
Philipp
  • 967
  • 6
  • 16