"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "httpclient/src/test/java/org/apache/http/conn/TestEofSensorInputStream.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.

TestEofSensorInputStream.java  (httpcomponents-client-4.5.6-src):TestEofSensorInputStream.java  (httpcomponents-client-4.5.7-src)
skipping to change at line 40 skipping to change at line 40
import java.io.InputStream; import java.io.InputStream;
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","static-access"}) // test code @SuppressWarnings({"boxing","static-access"}) // test code
public class TestEofSensorInputStream { public class TestEofSensorInputStream {
private InputStream instream; private InputStream inStream;
private EofSensorWatcher eofwatcher; private EofSensorWatcher eofwatcher;
private EofSensorInputStream eofstream; private EofSensorInputStream eofstream;
@Before @Before
public void setup() throws Exception { public void setup() throws Exception {
instream = Mockito.mock(InputStream.class); inStream = Mockito.mock(InputStream.class);
eofwatcher = Mockito.mock(EofSensorWatcher.class); eofwatcher = Mockito.mock(EofSensorWatcher.class);
eofstream = new EofSensorInputStream(instream, eofwatcher); eofstream = new EofSensorInputStream(inStream, eofwatcher);
} }
@Test @Test
public void testClose() throws Exception { public void testClose() throws Exception {
Mockito.when(eofwatcher.streamClosed(Mockito.<InputStream>any())).thenRe turn(Boolean.TRUE); Mockito.when(eofwatcher.streamClosed(Mockito.<InputStream>any())).thenRe turn(Boolean.TRUE);
eofstream.close(); eofstream.close();
Assert.assertTrue(eofstream.isSelfClosed()); Assert.assertTrue(eofstream.isSelfClosed());
Assert.assertNull(eofstream.getWrappedStream()); Assert.assertNull(eofstream.getWrappedStream());
Mockito.verify(instream, Mockito.times(1)).close(); Mockito.verify(inStream, Mockito.times(1)).close();
Mockito.verify(eofwatcher).streamClosed(instream); Mockito.verify(eofwatcher).streamClosed(inStream);
eofstream.close(); eofstream.close();
} }
@Test @Test
public void testCloseIOError() throws Exception { public void testCloseIOError() throws Exception {
Mockito.when(eofwatcher.streamClosed(Mockito.<InputStream>any())).thenTh row(new IOException()); Mockito.when(eofwatcher.streamClosed(Mockito.<InputStream>any())).thenTh row(new IOException());
try { try {
eofstream.close(); eofstream.close();
Assert.fail("IOException expected"); Assert.fail("IOException expected");
} catch (final IOException ex) { } catch (final IOException ex) {
} }
Assert.assertTrue(eofstream.isSelfClosed()); Assert.assertTrue(eofstream.isSelfClosed());
Assert.assertNull(eofstream.getWrappedStream()); Assert.assertNull(eofstream.getWrappedStream());
Mockito.verify(eofwatcher).streamClosed(instream); Mockito.verify(eofwatcher).streamClosed(inStream);
} }
@Test @Test
public void testReleaseConnection() throws Exception { public void testReleaseConnection() throws Exception {
Mockito.when(eofwatcher.streamClosed(Mockito.<InputStream>any())).thenRe turn(Boolean.TRUE); Mockito.when(eofwatcher.streamClosed(Mockito.<InputStream>any())).thenRe turn(Boolean.TRUE);
eofstream.releaseConnection(); eofstream.releaseConnection();
Assert.assertTrue(eofstream.isSelfClosed()); Assert.assertTrue(eofstream.isSelfClosed());
Assert.assertNull(eofstream.getWrappedStream()); Assert.assertNull(eofstream.getWrappedStream());
Mockito.verify(instream, Mockito.times(1)).close(); Mockito.verify(inStream, Mockito.times(1)).close();
Mockito.verify(eofwatcher).streamClosed(instream); Mockito.verify(eofwatcher).streamClosed(inStream);
eofstream.releaseConnection(); eofstream.releaseConnection();
} }
@Test @Test
public void testAbortConnection() throws Exception { public void testAbortConnection() throws Exception {
Mockito.when(eofwatcher.streamAbort(Mockito.<InputStream>any())).thenRet urn(Boolean.TRUE); Mockito.when(eofwatcher.streamAbort(Mockito.<InputStream>any())).thenRet urn(Boolean.TRUE);
eofstream.abortConnection(); eofstream.abortConnection();
Assert.assertTrue(eofstream.isSelfClosed()); Assert.assertTrue(eofstream.isSelfClosed());
Assert.assertNull(eofstream.getWrappedStream()); Assert.assertNull(eofstream.getWrappedStream());
Mockito.verify(instream, Mockito.times(1)).close(); Mockito.verify(inStream, Mockito.times(1)).close();
Mockito.verify(eofwatcher).streamAbort(instream); Mockito.verify(eofwatcher).streamAbort(inStream);
eofstream.abortConnection(); eofstream.abortConnection();
} }
@Test @Test
public void testAbortConnectionIOError() throws Exception { public void testAbortConnectionIOError() throws Exception {
Mockito.when(eofwatcher.streamAbort(Mockito.<InputStream>any())).thenThr ow(new IOException()); Mockito.when(eofwatcher.streamAbort(Mockito.<InputStream>any())).thenThr ow(new IOException());
try { try {
eofstream.abortConnection(); eofstream.abortConnection();
Assert.fail("IOException expected"); Assert.fail("IOException expected");
} catch (final IOException ex) { } catch (final IOException ex) {
} }
Assert.assertTrue(eofstream.isSelfClosed()); Assert.assertTrue(eofstream.isSelfClosed());
Assert.assertNull(eofstream.getWrappedStream()); Assert.assertNull(eofstream.getWrappedStream());
Mockito.verify(eofwatcher).streamAbort(instream); Mockito.verify(eofwatcher).streamAbort(inStream);
} }
@Test @Test
public void testRead() throws Exception { public void testRead() throws Exception {
Mockito.when(eofwatcher.eofDetected(Mockito.<InputStream>any())).thenRet urn(Boolean.TRUE); Mockito.when(eofwatcher.eofDetected(Mockito.<InputStream>any())).thenRet urn(Boolean.TRUE);
Mockito.when(instream.read()).thenReturn(0, -1); Mockito.when(inStream.read()).thenReturn(0, -1);
Assert.assertEquals(0, eofstream.read()); Assert.assertEquals(0, eofstream.read());
Assert.assertFalse(eofstream.isSelfClosed()); Assert.assertFalse(eofstream.isSelfClosed());
Assert.assertNotNull(eofstream.getWrappedStream()); Assert.assertNotNull(eofstream.getWrappedStream());
Mockito.verify(eofwatcher, Mockito.never()).eofDetected(instream); Mockito.verify(eofwatcher, Mockito.never()).eofDetected(inStream);
Assert.assertEquals(-1, eofstream.read()); Assert.assertEquals(-1, eofstream.read());
Assert.assertFalse(eofstream.isSelfClosed()); Assert.assertFalse(eofstream.isSelfClosed());
Assert.assertNull(eofstream.getWrappedStream()); Assert.assertNull(eofstream.getWrappedStream());
Mockito.verify(instream, Mockito.times(1)).close(); Mockito.verify(inStream, Mockito.times(1)).close();
Mockito.verify(eofwatcher).eofDetected(instream); Mockito.verify(eofwatcher).eofDetected(inStream);
Assert.assertEquals(-1, eofstream.read()); Assert.assertEquals(-1, eofstream.read());
} }
@Test @Test
public void testReadIOError() throws Exception { public void testReadIOError() throws Exception {
Mockito.when(eofwatcher.eofDetected(Mockito.<InputStream>any())).thenRet urn(Boolean.TRUE); Mockito.when(eofwatcher.eofDetected(Mockito.<InputStream>any())).thenRet urn(Boolean.TRUE);
Mockito.when(instream.read()).thenThrow(new IOException()); Mockito.when(inStream.read()).thenThrow(new IOException());
try { try {
eofstream.read(); eofstream.read();
Assert.fail("IOException expected"); Assert.fail("IOException expected");
} catch (final IOException ex) { } catch (final IOException ex) {
} }
Assert.assertFalse(eofstream.isSelfClosed()); Assert.assertFalse(eofstream.isSelfClosed());
Assert.assertNull(eofstream.getWrappedStream()); Assert.assertNull(eofstream.getWrappedStream());
Mockito.verify(eofwatcher).streamAbort(instream); Mockito.verify(eofwatcher).streamAbort(inStream);
} }
@Test @Test
public void testReadByteArray() throws Exception { public void testReadByteArray() throws Exception {
Mockito.when(eofwatcher.eofDetected(Mockito.<InputStream>any())).thenRet urn(Boolean.TRUE); Mockito.when(eofwatcher.eofDetected(Mockito.<InputStream>any())).thenRet urn(Boolean.TRUE);
Mockito.when(instream.read(Mockito.<byte []>any(), Mockito.anyInt(), Moc kito.anyInt())) Mockito.when(inStream.read(Mockito.<byte []>any(), Mockito.anyInt(), Moc kito.anyInt()))
.thenReturn(1, -1); .thenReturn(1, -1);
final byte[] tmp = new byte[1]; final byte[] tmp = new byte[1];
Assert.assertEquals(1, eofstream.read(tmp)); Assert.assertEquals(1, eofstream.read(tmp));
Assert.assertFalse(eofstream.isSelfClosed()); Assert.assertFalse(eofstream.isSelfClosed());
Assert.assertNotNull(eofstream.getWrappedStream()); Assert.assertNotNull(eofstream.getWrappedStream());
Mockito.verify(eofwatcher, Mockito.never()).eofDetected(instream); Mockito.verify(eofwatcher, Mockito.never()).eofDetected(inStream);
Assert.assertEquals(-1, eofstream.read(tmp)); Assert.assertEquals(-1, eofstream.read(tmp));
Assert.assertFalse(eofstream.isSelfClosed()); Assert.assertFalse(eofstream.isSelfClosed());
Assert.assertNull(eofstream.getWrappedStream()); Assert.assertNull(eofstream.getWrappedStream());
Mockito.verify(instream, Mockito.times(1)).close(); Mockito.verify(inStream, Mockito.times(1)).close();
Mockito.verify(eofwatcher).eofDetected(instream); Mockito.verify(eofwatcher).eofDetected(inStream);
Assert.assertEquals(-1, eofstream.read(tmp)); Assert.assertEquals(-1, eofstream.read(tmp));
} }
@Test @Test
public void testReadByteArrayIOError() throws Exception { public void testReadByteArrayIOError() throws Exception {
Mockito.when(eofwatcher.eofDetected(Mockito.<InputStream>any())).thenRet urn(Boolean.TRUE); Mockito.when(eofwatcher.eofDetected(Mockito.<InputStream>any())).thenRet urn(Boolean.TRUE);
Mockito.when(instream.read(Mockito.<byte []>any(), Mockito.anyInt(), Moc kito.anyInt())) Mockito.when(inStream.read(Mockito.<byte []>any(), Mockito.anyInt(), Moc kito.anyInt()))
.thenThrow(new IOException()); .thenThrow(new IOException());
final byte[] tmp = new byte[1]; final byte[] tmp = new byte[1];
try { try {
eofstream.read(tmp); eofstream.read(tmp);
Assert.fail("IOException expected"); Assert.fail("IOException expected");
} catch (final IOException ex) { } catch (final IOException ex) {
} }
Assert.assertFalse(eofstream.isSelfClosed()); Assert.assertFalse(eofstream.isSelfClosed());
Assert.assertNull(eofstream.getWrappedStream()); Assert.assertNull(eofstream.getWrappedStream());
Mockito.verify(eofwatcher).streamAbort(instream); Mockito.verify(eofwatcher).streamAbort(inStream);
} }
@Test @Test
public void testReadAfterAbort() throws Exception { public void testReadAfterAbort() throws Exception {
Mockito.when(eofwatcher.streamAbort(Mockito.<InputStream>any())).thenRet urn(Boolean.TRUE); Mockito.when(eofwatcher.streamAbort(Mockito.<InputStream>any())).thenRet urn(Boolean.TRUE);
eofstream.abortConnection(); eofstream.abortConnection();
try { try {
eofstream.read(); eofstream.read();
 End of changes. 18 change blocks. 
23 lines changed or deleted 23 lines changed or added

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