@Test(timeout = 5000)
    public void handleReTransmissionError1Bad() throws InterruptedException {

        server = new ApnsServerStub(FixedCertificates.serverContext().getServerSocketFactory());
        final CountDownLatch sync = new CountDownLatch(1);
        final AtomicInteger numError = new AtomicInteger();
        final AtomicInteger numStartSend = new AtomicInteger();
        int EXPECTED_ERROR_COUNT = 1;
        server.getWaitForError().acquire();
        server.start();
        ApnsService service =
                APNS.newService().withSSLContext(clientContext())
                .withGatewayDestination(LOCALHOST, server.getEffectiveGatewayPort())
                .withDelegate(new StartSendingApnsDelegate() {

            public void startSending(final ApnsNotification message, final boolean resent) {
                if (!resent) {
                    numStartSend.incrementAndGet();
                }
            }

            public void messageSent(ApnsNotification message, boolean resent) {
            }

            public void messageSendFailed(ApnsNotification message, Throwable e) {
                numError.incrementAndGet();
                sync.countDown();
            }

            public void connectionClosed(DeliveryError e, int messageIdentifier) {
            }

            public void cacheLengthExceeded(int newCacheLength) {
            }

            public void notificationsResent(int resendCount) {
            }
        })
                .build();
        server.stopAt(eMsg1.length());
        service.push(eMsg1);

        server.sendError(8, eMsg1.getIdentifier());
        server.getWaitForError().release();
        server.getMessages().acquire();

        sync.await();

        Assert.assertEquals(EXPECTED_ERROR_COUNT, numError.get());
        Assert.assertEquals(EXPECTED_ERROR_COUNT, numStartSend.get());
    }
Test to make sure single rejected notifications are returned

@throws InterruptedException
src/test/java/com/notnoop/apns/integration/ApnsConnectionCacheTest.java