// Path: src/main/java/net/reini/rabbitmq/cdi/ConsumerHolder.java
// @FunctionalInterface
// interface AckAction {
//   void apply(RecoverableChannel channel) throws IOException;
// }


import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.ArgumentMatchers.isA;
import static org.mockito.Mockito.doThrow;
import static org.mockito.Mockito.inOrder;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import java.io.IOException;
import java.util.List;
import java.util.concurrent.TimeoutException;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.InOrder;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;
import com.rabbitmq.client.AMQP.BasicProperties;
import com.rabbitmq.client.ConsumerShutdownSignalCallback;
import com.rabbitmq.client.DeliverCallback;
import com.rabbitmq.client.Delivery;
import com.rabbitmq.client.Envelope;
import com.rabbitmq.client.MessageProperties;
import com.rabbitmq.client.RecoverableChannel;
import com.rabbitmq.client.ShutdownSignalException;
import net.reini.rabbitmq.cdi.ConsumerHolder.AckAction;
    BasicProperties properties = MessageProperties.BASIC;
    byte[] body = "some body".getBytes();
    Envelope envelope = new Envelope(123L, false, "exchange", "routingKey");
    Delivery message = new Delivery(envelope, properties, body);
    IOException ioe = new IOException("some error");

    when(consumerChannelFactoryMock.createChannel()).thenReturn(channelMock);
    when(eventConsumerMock.consume("consumerTag", envelope, properties, body)).thenReturn(false);
    doThrow(ioe).when(channelMock).basicNack(123L, false, false);

    sut.activate();
    assertThrows(IOException.class, () -> sut.deliverWithAck("consumerTag", message));
  }

  @Test
  void ensureCompleteShutdown() throws IOException, TimeoutException {
    sut = new ConsumerHolder(eventConsumerMock, "queue", true, PREFETCH_COUNT,
        consumerChannelFactoryMock, declarationsListMock, declarerRepositoryMock);
    when(consumerChannelFactoryMock.createChannel()).thenReturn(channelMock);

    sut.activate();
    sut.ensureCompleteShutdown();

    verify(channelMock).close();
  }

  @Test
  void invokePendingAckAction() throws IOException {
    sut = new ConsumerHolder(eventConsumerMock, "queue", true, PREFETCH_COUNT,
        consumerChannelFactoryMock, declarationsListMock, declarerRepositoryMock);
// Path: src/main/java/net/reini/rabbitmq/cdi/ConsumerHolder.java
// @FunctionalInterface
// interface AckAction {
//   void apply(RecoverableChannel channel) throws IOException;
// }


// Path: src/test/java/net/reini/rabbitmq/cdi/ConsumerHolderTest.java
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.ArgumentMatchers.isA;
import static org.mockito.Mockito.doThrow;
import static org.mockito.Mockito.inOrder;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import java.io.IOException;
import java.util.List;
import java.util.concurrent.TimeoutException;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.InOrder;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;
import com.rabbitmq.client.AMQP.BasicProperties;
import com.rabbitmq.client.ConsumerShutdownSignalCallback;
import com.rabbitmq.client.DeliverCallback;
import com.rabbitmq.client.Delivery;
import com.rabbitmq.client.Envelope;
import com.rabbitmq.client.MessageProperties;
import com.rabbitmq.client.RecoverableChannel;
import com.rabbitmq.client.ShutdownSignalException;
import net.reini.rabbitmq.cdi.ConsumerHolder.AckAction;

    BasicProperties properties = MessageProperties.BASIC;
    byte[] body = "some body".getBytes();
    Envelope envelope = new Envelope(123L, false, "exchange", "routingKey");
    Delivery message = new Delivery(envelope, properties, body);
    IOException ioe = new IOException("some error");

    when(consumerChannelFactoryMock.createChannel()).thenReturn(channelMock);
    when(eventConsumerMock.consume("consumerTag", envelope, properties, body)).thenReturn(false);
    doThrow(ioe).when(channelMock).basicNack(123L, false, false);

    sut.activate();
    assertThrows(IOException.class, () -> sut.deliverWithAck("consumerTag", message));
  }

  @Test
  void ensureCompleteShutdown() throws IOException, TimeoutException {
    sut = new ConsumerHolder(eventConsumerMock, "queue", true, PREFETCH_COUNT,
        consumerChannelFactoryMock, declarationsListMock, declarerRepositoryMock);
    when(consumerChannelFactoryMock.createChannel()).thenReturn(channelMock);

    sut.activate();
    sut.ensureCompleteShutdown();

    verify(channelMock).close();
  }

  @Test
  void invokePendingAckAction() throws IOException {
    sut = new ConsumerHolder(eventConsumerMock, "queue", true, PREFETCH_COUNT,
        consumerChannelFactoryMock, declarationsListMock, declarerRepositoryMock);
    AckAction action = mock(AckAction.class);