I have the following class:
import name.package.OtherClass;
import name.package.Context;
import name.package.Configuration.keys;
public class MyClass{
public static void configure(Context context){
Configuration config = new OtherClass().getConfiguration(keys);
context.configure(config);
}
}
I want to mock the method OtherClass.getConfiguration()
. Could I do the following?
import org.mockito.Mock;
import org.mockito.Mockito;
public class MyClassTest{
@Mock
private Context context = Mockito.mock(Context.class);
@Mock
private OtherClass otherClass = Mockito.mock(OtherClass.class);
@Mock
private Context configurationMock = Mockito.mock(Configuration.class);
@Test
public void testConfigure(){
Mockito.when(otherClass.getConfiguration(keys)).thenReturn(configurationMock);
MyClass.configure(context);
verify(context.configure(configurationMock), times(1))
}
}
Remember that OtherClass
is not an argument of MyClass
, and I want to know if a mock of it inside the class of tests takes effect in MyClass
instance when I run the test.
I have tried executing this but didn't get clear results.