jeudi 27 août 2015

How to test Post Rest Service using jMockit?

public int addservice() {

    HttpResponse response = PostJSON.post(url, json, HttpMethodsConstant.POST);
    return response.getStatusLine().getStatusCode();

}


@Test
public void test() {
    new NonStrictExpectations() {
        {
            PostJSON.post((String) any, (String) any, (HttpMethodsConstant) any);
            returns(200);
        }
    };
    int result = mainService.addService();
    assertTrue(result > 0);
}

I mocked PostJSON with @Mocked in the test class.

I am getting following error:

java.lang.ClassCastException: java.lang.String cannot be cast to org.apache.http.HttpResponse

Aucun commentaire:

Enregistrer un commentaire