Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

scalamock and method with multiple argument

Tags:

scalamock

i am trying to mock an object that has a function with multiple argument.

I would just try to set the expectation for it. That is, somehting of the form:

(item.addMetadata(,,,,,)).expects("","","","","","","")

I just don't know how to write it. The example, usually deal with one argument function: (item.addMetadata _).expects("")

How to deal with multiple argument ?

EDIT1

I change to Just for the sake of compiling:

(item.addMetadata _) expects (where {
      (schema: String, element: String, qualifier: String, lang: String, value: String) => true
    })

Now The problem apparently is that the method is overloaded ?

I get the following error:

Error:(21, 15) ambiguous reference to overloaded definition,
both method addMetadata in class Item of type (x$1: String, x$2: String, x$3: String, x$4: String, x$5: String, x$6: String, x$7: Int)Unit
and  method addMetadata in class Item of type (x$1: String, x$2: String, x$3: String, x$4: String, x$5: String)Unit
match expected type ?
        (item.addMetadata _) expects (where {
              ^

as a side not i should also added the fact that i am mocking a class and not an interface. This is class which is not under my control, has a private constructor and only a static create method. So i also get the following error:

Error:(18, 24) constructor Item in class Item cannot be accessed in <$anon: org.dspace.content.Item>
    val item = mock[Item]
                   ^
like image 237
MaatDeamon Avatar asked Sep 11 '25 20:09

MaatDeamon


1 Answers

What i needed was to deal with an overloaded method of an object. I did not figure that out initially.

So the solution is to write:

(item.addMetadata(_: String, _:String, _:String, _:String, _:String)) expects ("hi", "he", "hey", "test", "holla")

Not sure however what would have been necessary if it was not an overloaded method, which was part of my original question.

like image 174
MaatDeamon Avatar answered Sep 13 '25 13:09

MaatDeamon