private void testMethod_resultInErrorState(ServiceTestInvocation testMethod) throws Exception {
    try {
      expect(bodyParser.parse(testMethod.getBody())).andReturn(Collections.singleton(requestBody));
    } catch (BodyParseException e) {
      // needed for compiler
    }
    assertCreateRequest(testMethod);
    expect(request.process()).andReturn(result);
    expect(result.getStatus()).andReturn(status).atLeastOnce();
    expect(status.getStatusCode()).andReturn(400).atLeastOnce();
    expect(serializer.serialize(result)).andReturn(serializedResult);

    replayMocks();

    Response r = testMethod.invoke();

    assertEquals(serializedResult, r.getEntity());
    assertEquals(400, r.getStatus());
    verifyAndResetMocks();
  }
Base class for service unit tests.
ambari-server/src/test/java/org/apache/ambari/server/api/services/BaseServiceTest.java