Search code examples
scalaclassoopjvm

scala : method not getting called without adding private modifier


i am new to scala and cant seem to notice any issue here. As mentioned in code comments, if(enableXMLMessageLog(method)) is evaluating to false without executing the method enableXMLMessageLog . Once i add private to this method, it starts to work as expected and returns true on evaluation.

The methods are member of an abstract class.

enter image description here

Any idea what is happening here and why is it only getting called after adding private ?


Solution

  • i think i got it . the method was being called from a unit test class and only the logBookingMessage method was set to when(messageLogger.logBookingMessage(any[LoggingMethod])).thenCallRealMethod() hence it was not able to call the method enableXMLMessageLog as it was being mocked and thus returning false.

    On adding private to the method, mocking framework does not mock and call the actual implementation of the method hence returning true.