@Test
public void testOfferProducerWithAddressDoesNotGrantNegativeCredit() throws Exception {

   // Mock returns to get at the runnable that grants credit.
   Mockito.when(manager.getServer()).thenReturn(server);
   Mockito.when(server.getPagingManager()).thenReturn(pagingManager);
   Mockito.when(pagingManager.getPageStore(any(SimpleString.class))).thenReturn(pagingStore);
   // Capture credit runnable and invoke to trigger credit top off
   ArgumentCaptor<Runnable> argument = ArgumentCaptor.forClass(Runnable.class);
   AMQPSessionCallback session = new AMQPSessionCallback(protonSPI, manager, connection, transportConnection, executor, operationContext);
   // Credit is at threshold
   Mockito.when(receiver.getCredit()).thenReturn(AMQP_LOW_CREDITS_DEFAULT);
   session.flow(new SimpleString("test"), ProtonServerReceiverContext.createCreditRunnable(1, AMQP_LOW_CREDITS_DEFAULT, receiver, connection));
   // Run the credit refill code.
   Mockito.verify(pagingStore).checkMemory(argument.capture());
   assertNotNull(argument.getValue());
   argument.getValue().run();
   // Ensure we aren't looking at remote credit as that gives us the wrong view of what credit is at the broker
   Mockito.verify(receiver, never()).getRemoteCredit();
   // Credit runnable should not grant what would be negative credit here
   Mockito.verify(receiver, never()).flow(anyInt());
}