### Question:
ViewURLStreamProvider implements org.apache.ambari.view.URLStreamProvider, URLConnectionProvider { @Override public HttpURLConnection getConnectionAs(String spec, String requestMethod, String body, Map<String, String> headers, String userName) throws IOException { return getConnection(addDoAs(spec, userName), requestMethod, body, headers); } protected  ViewURLStreamProvider(ViewContext viewContext, URLStreamProvider streamProvider); @Override InputStream readFrom(String spec, String requestMethod, String body, Map<String, String> headers); @Override InputStream readFrom(String spec, String requestMethod, InputStream body, Map<String, String> headers); @Override InputStream readAs(String spec, String requestMethod, String body, Map<String, String> headers,
                            String userName); @Override InputStream readAs(String spec, String requestMethod, InputStream body, Map<String, String> headers,
                            String userName); @Override InputStream readAsCurrent(String spec, String requestMethod, String body, Map<String, String> headers); @Override InputStream readAsCurrent(String spec, String requestMethod, InputStream body, Map<String, String> headers); @Override HttpURLConnection getConnection(String spec,
                                         String requestMethod,
                                         String body,
                                         Map<String, String> headers); @Override HttpURLConnection getConnection(String spec,
                                         String requestMethod,
                                         InputStream body,
                                         Map<String, String> headers); @Override HttpURLConnection getConnectionAs(String spec,
                                           String requestMethod,
                                           String body,
                                           Map<String, String> headers,
                                           String userName); @Override HttpURLConnection getConnectionAs(String spec,
                                           String requestMethod,
                                           InputStream body,
                                           Map<String, String> headers,
                                           String userName); @Override HttpURLConnection getConnectionAsCurrent(String spec,
                                                  String requestMethod,
                                                  String body,
                                                  Map<String, String> headers); @Override HttpURLConnection getConnectionAsCurrent(String spec,
                                                  String requestMethod,
                                                  InputStream body,
                                                  Map<String, String> headers);  }### Answer:
@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<>(); headers.put("header", "headerValue"); Map<String, List<String>> headerMap = new HashMap<>(); 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); }