vendredi 26 mai 2017

Null object after using @Inject

I am trying to use Java Dependency Injection in my functional test. While trying to run the test I keep getting the dependency as null. The constructor of this dependency will just start a wiremock server. Can someone please help me find what is wrong?

MockService - that gets injected

public class MockService {

    public MockService() {
        this(8080, 9443);
    }

    public MockService(int port, int httpsport){

        wireMockServer = new WireMockServer(config);
        wireMockServer.start();    
    }
}

Functional test where I am injecting:

public class SampleResourceFunctionalTest {

    @Inject
    MockService mockService;

    @BeforeClass 
    public void init() {

        mockService.calls();

     }....


}

I keep getting a null for mockService in the init() method. Why is the mockService not getting injected?

Thanks for your help here

Aucun commentaire:

Enregistrer un commentaire