"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "httpclient/src/test/java/org/apache/http/impl/execchain/TestResponseEntityWrapper.java" between
httpcomponents-client-4.5.6-src.tar.gz and httpcomponents-client-4.5.7-src.tar.gz

About: HttpComponents is an Apache project responsible for creating and maintaining a toolset of low level Java components focused on HTTP and associated protocols. Java sources.

TestResponseEntityWrapper.java  (httpcomponents-client-4.5.6-src):TestResponseEntityWrapper.java  (httpcomponents-client-4.5.7-src)
skipping to change at line 44 skipping to change at line 44
import org.apache.http.HttpEntity; import org.apache.http.HttpEntity;
import org.apache.http.util.EntityUtils; import org.apache.http.util.EntityUtils;
import org.junit.Assert; import org.junit.Assert;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import org.mockito.Mockito; import org.mockito.Mockito;
@SuppressWarnings("boxing") // test code @SuppressWarnings("boxing") // test code
public class TestResponseEntityWrapper { public class TestResponseEntityWrapper {
private InputStream instream; private InputStream inStream;
private HttpEntity entity; private HttpEntity entity;
private ConnectionHolder connHolder; private ConnectionHolder connHolder;
private ResponseEntityProxy wrapper; private ResponseEntityProxy wrapper;
@Before @Before
public void setup() throws Exception { public void setup() throws Exception {
instream = Mockito.mock(InputStream.class); inStream = Mockito.mock(InputStream.class);
entity = Mockito.mock(HttpEntity.class); entity = Mockito.mock(HttpEntity.class);
Mockito.when(entity.getContent()).thenReturn(instream); Mockito.when(entity.getContent()).thenReturn(inStream);
connHolder = Mockito.mock(ConnectionHolder.class); connHolder = Mockito.mock(ConnectionHolder.class);
wrapper = new ResponseEntityProxy(entity, connHolder); wrapper = new ResponseEntityProxy(entity, connHolder);
} }
@Test @Test
public void testReusableEntityStreamClosed() throws Exception { public void testReusableEntityStreamClosed() throws Exception {
Mockito.when(entity.isStreaming()).thenReturn(true); Mockito.when(entity.isStreaming()).thenReturn(true);
Mockito.when(connHolder.isReusable()).thenReturn(true); Mockito.when(connHolder.isReusable()).thenReturn(true);
EntityUtils.consume(wrapper); EntityUtils.consume(wrapper);
Mockito.verify(instream, Mockito.times(1)).close(); Mockito.verify(inStream, Mockito.times(1)).close();
Mockito.verify(connHolder).releaseConnection(); Mockito.verify(connHolder).releaseConnection();
} }
@Test @Test
public void testReusableEntityStreamClosedIOError() throws Exception { public void testReusableEntityStreamClosedIOError() throws Exception {
Mockito.when(entity.isStreaming()).thenReturn(true); Mockito.when(entity.isStreaming()).thenReturn(true);
Mockito.when(connHolder.isReusable()).thenReturn(true); Mockito.when(connHolder.isReusable()).thenReturn(true);
Mockito.doThrow(new IOException()).when(instream).close(); Mockito.doThrow(new IOException()).when(inStream).close();
try { try {
EntityUtils.consume(wrapper); EntityUtils.consume(wrapper);
Assert.fail("IOException expected"); Assert.fail("IOException expected");
} catch (final IOException ex) { } catch (final IOException ex) {
} }
Mockito.verify(connHolder).abortConnection(); Mockito.verify(connHolder).abortConnection();
} }
@Test @Test
public void testEntityStreamClosedIOErrorAlreadyReleased() throws Exception { public void testEntityStreamClosedIOErrorAlreadyReleased() throws Exception {
Mockito.when(entity.isStreaming()).thenReturn(true); Mockito.when(entity.isStreaming()).thenReturn(true);
Mockito.when(connHolder.isReusable()).thenReturn(true); Mockito.when(connHolder.isReusable()).thenReturn(true);
Mockito.when(connHolder.isReleased()).thenReturn(true); Mockito.when(connHolder.isReleased()).thenReturn(true);
Mockito.doThrow(new SocketException()).when(instream).close(); Mockito.doThrow(new SocketException()).when(inStream).close();
EntityUtils.consume(wrapper); EntityUtils.consume(wrapper);
Mockito.verify(connHolder).close(); Mockito.verify(connHolder).close();
} }
@Test @Test
public void testReusableEntityWriteTo() throws Exception { public void testReusableEntityWriteTo() throws Exception {
final OutputStream outstream = Mockito.mock(OutputStream.class); final OutputStream outStream = Mockito.mock(OutputStream.class);
Mockito.when(entity.isStreaming()).thenReturn(true); Mockito.when(entity.isStreaming()).thenReturn(true);
Mockito.when(connHolder.isReusable()).thenReturn(true); Mockito.when(connHolder.isReusable()).thenReturn(true);
wrapper.writeTo(outstream); wrapper.writeTo(outStream);
Mockito.verify(connHolder).releaseConnection(); Mockito.verify(connHolder).releaseConnection();
} }
@Test @Test
public void testReusableEntityWriteToIOError() throws Exception { public void testReusableEntityWriteToIOError() throws Exception {
final OutputStream outstream = Mockito.mock(OutputStream.class); final OutputStream outStream = Mockito.mock(OutputStream.class);
Mockito.when(entity.isStreaming()).thenReturn(true); Mockito.when(entity.isStreaming()).thenReturn(true);
Mockito.when(connHolder.isReusable()).thenReturn(true); Mockito.when(connHolder.isReusable()).thenReturn(true);
Mockito.doThrow(new IOException()).when(entity).writeTo(outstream); Mockito.doThrow(new IOException()).when(entity).writeTo(outStream);
try { try {
wrapper.writeTo(outstream); wrapper.writeTo(outStream);
Assert.fail("IOException expected"); Assert.fail("IOException expected");
} catch (final IOException ex) { } catch (final IOException ex) {
} }
Mockito.verify(connHolder, Mockito.never()).releaseConnection(); Mockito.verify(connHolder, Mockito.never()).releaseConnection();
Mockito.verify(connHolder).abortConnection(); Mockito.verify(connHolder).abortConnection();
} }
@Test @Test
public void testReusableEntityEndOfStream() throws Exception { public void testReusableEntityEndOfStream() throws Exception {
Mockito.when(instream.read()).thenReturn(-1); Mockito.when(inStream.read()).thenReturn(-1);
Mockito.when(entity.isStreaming()).thenReturn(true); Mockito.when(entity.isStreaming()).thenReturn(true);
Mockito.when(connHolder.isReusable()).thenReturn(true); Mockito.when(connHolder.isReusable()).thenReturn(true);
final InputStream content = wrapper.getContent(); final InputStream content = wrapper.getContent();
Assert.assertEquals(-1, content.read()); Assert.assertEquals(-1, content.read());
Mockito.verify(instream).close(); Mockito.verify(inStream).close();
Mockito.verify(connHolder).releaseConnection(); Mockito.verify(connHolder).releaseConnection();
} }
@Test @Test
public void testReusableEntityEndOfStreamIOError() throws Exception { public void testReusableEntityEndOfStreamIOError() throws Exception {
Mockito.when(instream.read()).thenReturn(-1); Mockito.when(inStream.read()).thenReturn(-1);
Mockito.when(entity.isStreaming()).thenReturn(true); Mockito.when(entity.isStreaming()).thenReturn(true);
Mockito.when(connHolder.isReusable()).thenReturn(true); Mockito.when(connHolder.isReusable()).thenReturn(true);
Mockito.doThrow(new IOException()).when(instream).close(); Mockito.doThrow(new IOException()).when(inStream).close();
final InputStream content = wrapper.getContent(); final InputStream content = wrapper.getContent();
try { try {
content.read(); content.read();
Assert.fail("IOException expected"); Assert.fail("IOException expected");
} catch (final IOException ex) { } catch (final IOException ex) {
} }
Mockito.verify(connHolder).abortConnection(); Mockito.verify(connHolder).abortConnection();
} }
} }
 End of changes. 15 change blocks. 
15 lines changed or deleted 15 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)