Source:
<code>private void doOnMessageWithDeliveryException(List<Symbol> sourceSymbols, Outcome defaultOutcome, Exception deliveryException, Class<? extends DeliveryState> expectedDeliveryState) throws Exception { AMQPConnectionContext mockConnContext = mock(AMQPConnectionContext.class); doAnswer((Answer<Void>) invocation -> { Runnable runnable = invocation.getArgument(0); runnable.run(); return null; }).when(mockConnContext).runLater(any(Runnable.class)); doAnswer((Answer<Void>) invocation -> { Runnable runnable = invocation.getArgument(0); runnable.run(); return null; }).when(mockConnContext).runNow(any(Runnable.class)); ProtonProtocolManager mockProtocolManager = mock(ProtonProtocolManager.class); when(mockProtocolManager.isUseModifiedForTransientDeliveryErrors()).thenReturn(true); when(mockConnContext.getProtocolManager()).thenReturn(mockProtocolManager); AMQPSessionCallback mockSession = mock(AMQPSessionCallback.class); Receiver mockReceiver = mock(Receiver.class); ProtonServerReceiverContext rc = new ProtonServerReceiverContext(mockSession, mockConnContext, null, mockReceiver); Delivery mockDelivery = mock(Delivery.class); when(mockDelivery.getLink()).thenReturn(mockReceiver); when(mockReceiver.current()).thenReturn(mockDelivery); Source source = new Source(); source.setOutcomes(sourceSymbols.toArray(new Symbol[]{})); source.setDefaultOutcome(defaultOutcome); when(mockReceiver.getSource()).thenReturn(source); doThrow(deliveryException).when(mockSession).serverSend(eq(rc), nullable(Transaction.class), eq(mockReceiver), eq(mockDelivery), nullable(SimpleString.class), any(RoutingContext.class), nullable(AMQPMessage.class)); rc.onMessage(mockDelivery); <START> Thread.sleep(1000); <END> verify(mockDelivery, times(1)).settle(); verify(mockDelivery, times(1)).disposition(any(expectedDeliveryState)); }</code><technical_language>safe in env</technical_language>

Target:
private void doOnMessageWithDeliveryException(List<Symbol> sourceSymbols, Outcome defaultOutcome, Exception deliveryException, Class<? extends DeliveryState> expectedDeliveryState) throws Exception { AMQPConnectionContext mockConnContext = mock(AMQPConnectionContext.class); doAnswer((Answer<Void>) invocation -> { Runnable runnable = invocation.getArgument(0); runnable.run(); return null; }).when(mockConnContext).runLater(any(Runnable.class)); doAnswer((Answer<Void>) invocation -> { Runnable runnable = invocation.getArgument(0); runnable.run(); return null; }).when(mockConnContext).runNow(any(Runnable.class)); ProtonProtocolManager mockProtocolManager = mock(ProtonProtocolManager.class); when(mockProtocolManager.isUseModifiedForTransientDeliveryErrors()).thenReturn(true); when(mockConnContext.getProtocolManager()).thenReturn(mockProtocolManager); AMQPSessionCallback mockSession = mock(AMQPSessionCallback.class); Receiver mockReceiver = mock(Receiver.class); ProtonServerReceiverContext rc = new ProtonServerReceiverContext(mockSession, mockConnContext, null, mockReceiver); Delivery mockDelivery = mock(Delivery.class); when(mockDelivery.getLink()).thenReturn(mockReceiver); when(mockReceiver.current()).thenReturn(mockDelivery); Source source = new Source(); source.setOutcomes(sourceSymbols.toArray(new Symbol[]{})); source.setDefaultOutcome(defaultOutcome); when(mockReceiver.getSource()).thenReturn(source); doThrow(deliveryException).when(mockSession).serverSend(eq(rc), nullable(Transaction.class), eq(mockReceiver), eq(mockDelivery), nullable(SimpleString.class), any(RoutingContext.class), nullable(AMQPMessage.class)); rc.onMessage(mockDelivery); verify(mockDelivery, times(1)).settle(); verify(mockDelivery, times(1)).disposition(any(expectedDeliveryState)); }