I have a method in a class as follows:
class Foo{
public void foo(){
Bar bar = new Bar();
String barResult = bar.something();
//code to test
}
}
Note that bar
is not an attribute of Foo
class. I need to write a test case for foo()
and I need a way to mock bar.something()
.
E.g: when(bar.something()).thenReturn('myresult');
But it is not possible since bar
is not accessible from the test class. How can I achieve this?