@Test
public void testGetConnectionAs() throws Exception {

  URLStreamProvider streamProvider = createNiceMock(URLStreamProvider.class);
  HttpURLConnection urlConnection = createNiceMock(HttpURLConnection.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);
  replay(streamProvider, urlConnection);
  ViewURLStreamProvider viewURLStreamProvider = new ViewURLStreamProvider(viewContext, streamProvider);
  Assert.assertEquals(urlConnection, viewURLStreamProvider.getConnectionAs("spec",
                                                                           "requestMethod",
                                                                           "params",
                                                                           headers,
                                                                           "joe"));
  verify(streamProvider, urlConnection);
}