@Test public void shouldReturnConnectionToPoolWhenNonOkResponse() throws Exception { when(mMessagePusher.pushAndReadResponse(mConnection, mMessage)) .thenReturn(new PushResponse(AppleResponseCode.InvalidPayloadSize, BigDecimal.ONE)); mService.pushMessage(mMessage); verify(mPool).returnObject(mConnection); }
@Test public void shouldCloseConnectionExplicitlyIfResponseFromAppleIsNotOk() throws Exception { when(mMessagePusher.pushAndReadResponse(mConnection, mMessage)) .thenReturn(new PushResponse(AppleResponseCode.InvalidPayloadSize, BigDecimal.ONE)); mService.pushMessage(mMessage); verify(mConnection).close(); }
@Test public void shouldReturnConnectionToPoolWhenExceptionThrownByMessagePusher() throws Exception { when(mMessagePusher.pushAndReadResponse(mConnection, mMessage)) .thenThrow(new MessageTransformationException("FOO")); try { mService.pushMessage(mMessage); } catch (MessageTransformationException e) { // expected } verify(mPool).returnObject(mConnection); }
@Test public void shouldReturnConnectionToPoolWhenOkResponse() throws Exception { when(mMessagePusher.pushAndReadResponse(mConnection, mMessage)).thenReturn(PushResponse.OK); mService.pushMessage(mMessage); verify(mPool).returnObject(mConnection); }