-
Notifications
You must be signed in to change notification settings - Fork 238
Cascading mock does not work for non-public classes #603
Copy link
Copy link
Closed
Labels
Description
Cascading mock does not work for non-public classes
In a test class, I mocked a static factory and expected its methods to return a non-null mocked object. However, the result of the method was....
.... you guessed it, null.
Test Class
public class TheTestClass {
@Tested
TheClassUnderTest test;
@Mocked
TheStaticFactory mockTheStaticFactory;
@Test
public void theTestedMethod_doesNotReturnNull() {
TheDependentService service = test.theTestedMethod();
assertNotNull(service);
}
}
Class Under Test
public class TheClassUnderTest {
public TheDependentService theTestedMethod() {
TheDependentService service = TheStaticFactory.getTheDependentService();
return service;
}
}
Static Factory
public class TheStaticFactory {
public static TheDependentService getTheDependentService() {
return new TheDependentService();
}
}
The Dependent Service
class TheDependentService {
}
Note TheDependentService is not public
Other Information
JMockit Version 1.43
JDK Version 11
Reactions are currently unavailable