'Is it possible to call a method that is both final and protected from a unit test?

I have this example class

class Foo extends Parent {
  final override protected def test(): String = "hello world"
}

As it is now, I am unable to call this method directly within my unit test. I am using Mockito and from what I've read so far, I either need to

  • remove the final so I can extend and override the access modifier (turn protected to private[package]) with another child class (Bar extends Foo)
  • update the Foo class to be private[package].

Neither options are desirable. Is there a way to keep the signature while still exposing the method to be unit testable?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source