### Question:
SwitchableInputStream extends FilterInputStream { void switchStream(InputStream in) { this.in = in; } SwitchableInputStream();   }### Answer:
@Test public void testSwitchStream() throws Exception { SwitchableInputStream sin = new SwitchableInputStream(); InputStream in1 = createStrictMock(InputStream.class); InputStream in2 = createStrictMock(InputStream.class); expect(in1.read()).andReturn(1); replay(in1, in2); sin.switchStream(in1); assertEquals(1, sin.read()); verify(in1, in2); reset(in1, in2); expect(in2.read()).andReturn(2); replay(in1, in2); sin.switchStream(in2); assertEquals(2, sin.read()); verify(in1, in2); }