Search in sources :

Example 1 with StrictExpectations

use of mockit.StrictExpectations in project swagger-parser by swagger-api.

the class ExternalRefProcessorTest method testProcessRefToExternalDefinition_NoNameConflict.

@Test
public void testProcessRefToExternalDefinition_NoNameConflict(@Injectable final Model mockedModel) throws Exception {
    final String ref = "http://my.company.com/path/to/file.json#/foo/bar";
    final RefFormat refFormat = RefFormat.URL;
    new StrictExpectations() {

        {
            cache.getRenamedRef(ref);
            times = 1;
            result = null;
            cache.loadRef(ref, refFormat, Model.class);
            times = 1;
            result = mockedModel;
            swagger.getDefinitions();
            times = 1;
            result = null;
            cache.putRenamedRef(ref, "bar");
            swagger.addDefinition("bar", mockedModel);
            times = 1;
            cache.addReferencedKey("bar");
            times = 1;
            result = null;
        }
    };
    String newRef = new ExternalRefProcessor(cache, swagger).processRefToExternalDefinition(ref, refFormat);
    assertEquals(newRef, "bar");
}
Also used : StrictExpectations(mockit.StrictExpectations) RefFormat(io.swagger.models.refs.RefFormat) Test(org.testng.annotations.Test)

Example 2 with StrictExpectations

use of mockit.StrictExpectations in project docker-maven-plugin by fabric8io.

the class DockerAccessWithHcClientTest method givenTheGetWillFail.

private void givenTheGetWillFail() throws IOException {
    new StrictExpectations() {

        {
            mockDelegate.get(anyString, (ResponseHandler) any, 200);
            result = new HttpResponseException(HTTP_INTERNAL_ERROR, "error");
        }
    };
}
Also used : StrictExpectations(mockit.StrictExpectations) HttpResponseException(org.apache.http.client.HttpResponseException)

Example 3 with StrictExpectations

use of mockit.StrictExpectations in project docker-maven-plugin by fabric8io.

the class DockerAccessWithHcClientTest method givenThePushWillFail.

@SuppressWarnings({ "rawtypes", "unchecked" })
private void givenThePushWillFail(final int retries, final boolean suceedAtEnd) throws IOException {
    new StrictExpectations() {

        {
            int fail = retries + (suceedAtEnd ? 0 : 1);
            mockDelegate.post(anyString, null, (Map<String, String>) any, (ResponseHandler) any, 200);
            minTimes = fail;
            maxTimes = fail;
            result = new HttpResponseException(HTTP_INTERNAL_ERROR, "error");
            mockDelegate.post(anyString, null, (Map<String, String>) any, (ResponseHandler) any, 200);
            minTimes = suceedAtEnd ? 1 : 0;
            maxTimes = suceedAtEnd ? 1 : 0;
        }
    };
}
Also used : StrictExpectations(mockit.StrictExpectations) HttpResponseException(org.apache.http.client.HttpResponseException)

Example 4 with StrictExpectations

use of mockit.StrictExpectations in project docker-maven-plugin by fabric8io.

the class DockerAccessWithHcClientTest method givenThePostWillFail.

private void givenThePostWillFail() throws IOException {
    new StrictExpectations() {

        {
            mockDelegate.post(anyString, any, (ResponseHandler) any, 200);
            result = new HttpResponseException(HTTP_INTERNAL_ERROR, "error");
        }
    };
}
Also used : StrictExpectations(mockit.StrictExpectations) HttpResponseException(org.apache.http.client.HttpResponseException)

Example 5 with StrictExpectations

use of mockit.StrictExpectations in project swagger-parser by swagger-api.

the class ResponseProcessorTest method testProcessResponse.

@Test
public void testProcessResponse(@Injectable final Model responseSchema, @Injectable final Property responseHeader) throws Exception {
    new StrictExpectations() {

        {
            new ModelProcessor(cache, swagger);
            times = 1;
            result = modelProcessor;
            modelProcessor.processModel(responseSchema);
            times = 1;
        }
    };
    Response response = new Response();
    response.setResponseSchema(responseSchema);
    response.addHeader("foo", responseHeader);
    new ResponseProcessor(cache, swagger).processResponse(response);
    new FullVerifications() {

        {
        }
    };
}
Also used : Response(io.swagger.models.Response) StrictExpectations(mockit.StrictExpectations) FullVerifications(mockit.FullVerifications) Test(org.testng.annotations.Test)

Aggregations

StrictExpectations (mockit.StrictExpectations)5 HttpResponseException (org.apache.http.client.HttpResponseException)3 Test (org.testng.annotations.Test)2 Response (io.swagger.models.Response)1 RefFormat (io.swagger.models.refs.RefFormat)1 FullVerifications (mockit.FullVerifications)1