### Question:
UndertowEndpoint extends AbstractReceiveListener implements XEndpoint { WebSocketCallback<Void> wrapCallback(XSendCallback callback) { return new WebSocketCallback<Void>() { private final AtomicBoolean onceOnly = new AtomicBoolean(); @Override public void complete(WebSocketChannel channel, Void context) { if (onceOnly.compareAndSet(false, true)) { backlog.decrementAndGet(); if (callback != null) callback.onComplete(UndertowEndpoint.this); } } @Override public void onError(WebSocketChannel channel, Void context, Throwable cause) { if (onceOnly.compareAndSet(false, true)) { backlog.decrementAndGet(); if (callback != null) callback.onError(UndertowEndpoint.this, cause); } } }; } UndertowEndpoint(UndertowEndpointManager manager, WebSocketChannel channel); @Override @SuppressWarnings("unchecked") T getContext(); @Override void setContext(Object context); @Override void send(String payload, XSendCallback callback); @Override void send(ByteBuffer payload, XSendCallback callback); WebSocketChannel getChannel(); @Override void flush(); @Override void sendPing(); @Override void close(); @Override void terminate(); @Override InetSocketAddress getRemoteAddress(); @Override long getBacklog(); @Override boolean isOpen(); @Override long getLastActivityTime(); @Override String toString();  }### Answer:
@Test public void testCallbackOnceOnlyComplete() { createEndpointManager(); final XSendCallback callback = mock(XSendCallback.class); final WebSocketCallback<Void> wsCallback = endpoint.wrapCallback(callback); wsCallback.complete(channel, null); verify(callback, times(1)).onComplete(eq(endpoint)); wsCallback.complete(channel, null); verify(callback, times(1)).onComplete(eq(endpoint)); }