1

So I am writing some Scala tests for some Java code (I am very new at both of them). What I am trying to do is instead of calling .create on the Configuration class, I want to call create on the conf mock object. How can I go about doing this?

When I try to call .create on a mock of the Configuration class, I get an error since (I think) .create is a static method from a custom abstract Configuration java class

Scala test code:

var conf: Configuration = mock[Configuration]

when(Configuration.create("var1","var2", "var3")).thenReturn(testConfiguration)

Thanks!

  • 1
    static methods are not ment to be called on an object in java, however you could create an non-initialzied variable and do: MyClass class; class.staticMethod(); or create a inner class that has a static method like here: https://stackoverflow.com/questions/7884004/is-calling-static-methods-via-an-object-bad-form-why In Scala, there are no static methods, however you could create some "pseudo-static" with implementing a singleton – ItFreak Aug 08 '19 at 14:43
  • 1
    Possible duplicate of [How do I make my scala method static?](https://stackoverflow.com/questions/48178192/how-do-i-make-my-scala-method-static) – Elias Aug 08 '19 at 14:44
  • 2
    The posted snippet doesn't make a lot of sense. And having a static method that needs to be mocked seems very wrong. Add a [mcve] please. – Nathan Hughes Aug 08 '19 at 14:50

0 Answers0