@Test
public void testReadAsCurrent() throws Exception {

  URLStreamProvider streamProvider = createNiceMock(URLStreamProvider.class);
  HttpURLConnection urlConnection = createNiceMock(HttpURLConnection.class);
  InputStream inputStream = createNiceMock(InputStream.class);
  ViewContext viewContext = createNiceMock(ViewContext.class);
  Map<String, String> headers = new HashMap<String, String>();
  headers.put("header", "headerValue");
  Map<String, List<String>> headerMap = new HashMap<String, List<String>>();
  headerMap.put("header", Collections.singletonList("headerValue"));
  expect(streamProvider.processURL(eq("spec?doAs=joe"), eq("requestMethod"), aryEq("params".getBytes()), eq(headerMap))).andReturn(urlConnection);
  expect(urlConnection.getInputStream()).andReturn(inputStream);
  expect(viewContext.getUsername()).andReturn("joe").anyTimes();
  replay(streamProvider, urlConnection, inputStream, viewContext);
  ViewURLStreamProvider viewURLStreamProvider = new ViewURLStreamProvider(viewContext, streamProvider);
  Assert.assertEquals(inputStream, viewURLStreamProvider.readAsCurrent("spec", "requestMethod", "params", headers));
  verify(streamProvider, urlConnection, inputStream, viewContext);
}