### Question:
TyrusClientEngine implements ClientEngine { @Override public UpgradeRequest createUpgradeRequest(TimeoutHandler timeoutHandler) { switch (clientEngineState) { case INIT: { ClientEndpointConfig config = (ClientEndpointConfig) endpointWrapper.getEndpointConfig(); this.timeoutHandler = timeoutHandler; clientHandShake = Handshake.createClientHandshake( RequestContext.Builder.create().requestURI(connectToServerUriParam) .secure("wss".equals(connectToServerUriParam.getScheme())).build()); clientHandShake.setExtensions(config.getExtensions()); clientHandShake.setSubProtocols(config.getPreferredSubprotocols()); clientHandShake.prepareRequest(); UpgradeRequest upgradeRequest = clientHandShake.getRequest(); config.getConfigurator().beforeRequest(upgradeRequest.getHeaders()); clientEngineState = TyrusClientEngineState.UPGRADE_REQUEST_CREATED; logUpgradeRequest(upgradeRequest); return upgradeRequest; } case REDIRECT_REQUIRED: { this.timeoutHandler = timeoutHandler; final URI requestUri = redirectLocation; RequestContext requestContext = RequestContext.Builder.create(clientHandShake.getRequest()) .requestURI(requestUri) .secure("wss".equalsIgnoreCase(requestUri.getScheme())).build(); Handshake.updateHostAndOrigin(requestContext); clientEngineState = TyrusClientEngineState.UPGRADE_REQUEST_CREATED; logUpgradeRequest(requestContext); return requestContext; } case AUTH_REQUIRED: { UpgradeRequest upgradeRequest = clientHandShake.getRequest(); if (clientEngineState.getAuthenticator() != null) { if (LOGGER.isLoggable(Level.CONFIG)) { debugContext.appendLogMessage(LOGGER, Level.CONFIG, DebugContext.Type.MESSAGE_OUT, "Using " + "authenticator: ", clientEngineState.getAuthenticator().getClass().getName()); } String authorizationHeader; try { final Credentials credentials = (Credentials) properties.get(ClientProperties.CREDENTIALS); debugContext.appendLogMessage(LOGGER, Level.CONFIG, DebugContext.Type.MESSAGE_OUT, "Using " + "credentials: ", credentials); authorizationHeader = clientEngineState.getAuthenticator() .generateAuthorizationHeader( upgradeRequest.getRequestURI(), clientEngineState.getWwwAuthenticateHeader(), credentials); } catch (AuthenticationException e) { listener.onError(e); return null; } upgradeRequest.getHeaders().put(UpgradeRequest.AUTHORIZATION, Collections.singletonList(authorizationHeader)); } clientEngineState = TyrusClientEngineState.AUTH_UPGRADE_REQUEST_CREATED; logUpgradeRequest(upgradeRequest); return upgradeRequest; } default: redirectUriHistory.clear(); throw new IllegalStateException(); } } TyrusClientEngine(TyrusEndpointWrapper endpointWrapper, ClientHandshakeListener listener,
                                    Map<String, Object> properties, URI connectToServerUriParam,
                                    DebugContext debugContext); @Override UpgradeRequest createUpgradeRequest(TimeoutHandler timeoutHandler); @Override ClientUpgradeInfo processResponse(final UpgradeResponse upgradeResponse,
                                             final Writer writer, final Connection.CloseListener closeListener); @Override void processError(Throwable t); TimeoutHandler getTimeoutHandler(); static final int DEFAULT_INCOMING_BUFFER_SIZE; }### Answer:
@Test public void testCallCreateRequestTwice() throws DeploymentException { ClientEngine engine = getClientEngine(Collections.<String, Object>emptyMap()); UpgradeRequest upgradeRequest = engine.createUpgradeRequest(null); assertNotNull("First call must return instance of UpgradeRequest", upgradeRequest); try { engine.createUpgradeRequest(null); fail("Second call of createUpgradeRequest must fail"); } catch (IllegalStateException e) { } }