@SuppressWarnings("deprecation")
    public void stop() {
        try {
            if (gatewaySocket != null) {
                gatewaySocket.close();
            }
        } catch (IOException e) {
            LOGGER.warn("Can not close gatewaySocket properly", e);
        }
        try {
            if (feedbackSocket != null) {
                feedbackSocket.close();
            }
        } catch (IOException e) {
            LOGGER.warn("Can not close feedbackSocket properly", e);
        }

        if (gatewayThread != null) {
            gatewayThread.stop();
        }

        if (feedbackThread != null) {
            feedbackThread.stop();
        }

    }
Create an ApnsServerStub that uses any free port for gateway and feedback.

@return the server stub. Use getEffectiveGatewayPort() and getEffectiveFeedbackPort() to ask for ports.
src/test/java/com/notnoop/apns/utils/ApnsServerStub.java