You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
The text was updated successfully, but these errors were encountered:
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
Class Under Test
Static Factory
The Dependent Service
Note TheDependentService is not public
Other Information
JMockit Version 1.43
JDK Version 11
The text was updated successfully, but these errors were encountered: