Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cascading mock does not work for non-public classes #603

Closed
harish-prakash opened this issue Apr 12, 2019 · 0 comments
Closed

Cascading mock does not work for non-public classes #603

harish-prakash opened this issue Apr 12, 2019 · 0 comments
Assignees
Labels

Comments

@harish-prakash
Copy link

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

@rliesenfeld rliesenfeld self-assigned this Apr 13, 2019
@jmockit jmockit locked and limited conversation to collaborators Apr 18, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Development

No branches or pull requests

2 participants