### Question:
ClientRequest extends OutboundMessageContext implements ClientRequestContext, HttpHeaders, InjectionManagerSupplier { void doWriteEntity(final MessageBodyWorkers writeWorkers, final GenericType<?> entityType) throws IOException { OutputStream entityStream = null; boolean connectionFailed = false; boolean runtimeException = false; try { try { entityStream = writeWorkers.writeTo( getEntity(), entityType.getRawType(), entityType.getType(), getEntityAnnotations(), getMediaType(), getHeaders(), getPropertiesDelegate(), getEntityStream(), writerInterceptors); setEntityStream(entityStream); } catch (final IOException e) { connectionFailed = true; throw e; } catch (final RuntimeException e) { runtimeException = true; throw e; } } finally { if (!connectionFailed) { if (entityStream != null) { try { entityStream.close(); } catch (final IOException e) { ExceptionUtils.conditionallyReThrow(e, !runtimeException, LOGGER, LocalizationMessages.ERROR_CLOSING_OUTPUT_STREAM(), Level.FINE); } catch (final RuntimeException e) { ExceptionUtils.conditionallyReThrow(e, !runtimeException, LOGGER, LocalizationMessages.ERROR_CLOSING_OUTPUT_STREAM(), Level.FINE); } } try { commitStream(); } catch (final IOException e) { ExceptionUtils.conditionallyReThrow(e, !runtimeException, LOGGER, LocalizationMessages.ERROR_COMMITTING_OUTPUT_STREAM(), Level.FINE); } catch (final RuntimeException e) { ExceptionUtils.conditionallyReThrow(e, !runtimeException, LOGGER, LocalizationMessages.ERROR_COMMITTING_OUTPUT_STREAM(), Level.FINE); } } } } protected  ClientRequest(
            final URI requestUri, final ClientConfig clientConfig, final PropertiesDelegate propertiesDelegate);  ClientRequest(final ClientRequest original); T resolveProperty(final String name, final Class<T> type); @SuppressWarnings("unchecked") T resolveProperty(final String name, final T defaultValue); @Override Object getProperty(final String name); @Override Collection<String> getPropertyNames(); @Override void setProperty(final String name, final Object object); @Override void removeProperty(final String name); @Override URI getUri(); @Override void setUri(final URI uri); @Override String getMethod(); @Override void setMethod(final String method); @Override JerseyClient getClient(); @Override void abortWith(final Response response); Response getAbortResponse(); @Override Configuration getConfiguration(); @Override List<String> getRequestHeader(String name); @Override MultivaluedMap<String, String> getRequestHeaders(); @Override Map<String, Cookie> getCookies(); MessageBodyWorkers getWorkers(); void setWorkers(final MessageBodyWorkers workers); void accept(final MediaType... types); void accept(final String... types); void acceptLanguage(final Locale... locales); void acceptLanguage(final String... locales); void cookie(final Cookie cookie); void cacheControl(final CacheControl cacheControl); void encoding(final String encoding); void language(final String language); void language(final Locale language); void type(final MediaType type); void type(final String type); void variant(final Variant variant); boolean isAsynchronous(); void enableBuffering(); void writeEntity(); Iterable<WriterInterceptor> getWriterInterceptors(); Iterable<ReaderInterceptor> getReaderInterceptors(); @Override InjectionManager getInjectionManager(); boolean ignoreUserAgent(); void ignoreUserAgent(final boolean ignore);  }### Answer:
@Test public void testSSLExceptionHandling() throws Exception { final IOException ioException = new IOException("Test"); final ClientRequest request = mockThrowing(ioException); try { request.doWriteEntity(workers, entityType); fail("An IOException exception should be thrown."); } catch (IOException e) { Assert.assertThat("Detected a un-expected exception! \n" + ExceptionUtils.exceptionStackTraceAsString(e), e, Is.is(ioException)); } }
@Test public void testRuntimeExceptionBeingReThrown() throws Exception { final RuntimeException runtimeException = new RuntimeException("Test"); ClientRequest request = mockThrowing(runtimeException); try { request.doWriteEntity(workers, entityType); Assert.fail("A RuntimeException exception should be thrown."); } catch (RuntimeException e) { Assert.assertThat("Detected a un-expected exception! \n" + ExceptionUtils.exceptionStackTraceAsString(e), e, Is.is(runtimeException)); } }