public void addLastHandler(AbstractChainHandler handler) {
        if (tail == null) {
            tail = handler;
            setNext(handler);
            return;
        }
        tail.setNext(handler);
        tail = handler;
    }
@Test
    public void testChain() {
        final HandlerChain handlerChain = new HandlerChain();
        final BulkheadRequestHandler bulkheadRequestHandler = Mockito.spy(BulkheadRequestHandler.class);
        final CircuitBreakerRequestHandler circuitBreakerClientReqHandler =
                Mockito.spy(CircuitBreakerRequestHandler.class);
        final FaultRequestHandler faultRequestHandler = Mockito.spy(FaultRequestHandler.class);
        handlerChain.addLastHandler(bulkheadRequestHandler);
        handlerChain.addLastHandler(circuitBreakerClientReqHandler);
        handlerChain.addLastHandler(faultRequestHandler);
        int num = 3;
        AbstractChainHandler handler = handlerChain;
        while (handler.getNext() != null) {
            num--;
            handler = handler.getNext();
        }
        assertEquals(0, num);

        // test call
        final RequestContext requestContext = ChainContext.getThreadLocalContext("test");
        final HttpRequestEntity build = new Builder().setRequestType(RequestType.CLIENT).setApiPath("/api").build();
        requestContext.setRequestEntity(build);
        final Set<String> businessNames = Collections.singleton("test");
        final Exception exception = new IllegalArgumentException("error");
        final Object result = new Object();
        handlerChain.onBefore(requestContext, businessNames);
        handlerChain.onThrow(requestContext, businessNames, exception);
        handlerChain.onResult(requestContext, businessNames, result);
        Mockito.verify(bulkheadRequestHandler, Mockito.times(1))
                .onBefore(requestContext, businessNames);
        Mockito.verify(bulkheadRequestHandler, Mockito.times(1))
                .onThrow(requestContext, businessNames, exception);
        Mockito.verify(bulkheadRequestHandler, Mockito.times(1))
                .onResult(requestContext, businessNames, result);

        Mockito.verify(circuitBreakerClientReqHandler, Mockito.times(1))
                .onBefore(requestContext, businessNames);
        Mockito.verify(circuitBreakerClientReqHandler, Mockito.times(1))
                .onThrow(requestContext, businessNames, exception);
        Mockito.verify(circuitBreakerClientReqHandler, Mockito.times(1))
                .onResult(requestContext, businessNames, result);

        Mockito.verify(faultRequestHandler, Mockito.times(1))
                .onBefore(requestContext, businessNames);
        Mockito.verify(faultRequestHandler, Mockito.times(1))
                .onThrow(requestContext, businessNames, exception);
        Mockito.verify(faultRequestHandler, Mockito.times(1))
                .onResult(requestContext, businessNames, result);

    }