### Question:
URLStreamProvider implements StreamProvider { public HttpURLConnection processURL(String spec, String requestMethod, String body, Map<String, List<String>> headers) throws IOException { return processURL(spec, requestMethod, body == null ? null : body.getBytes(), headers); } URLStreamProvider(int connectionTimeout, int readTimeout,
                           ComponentSSLConfiguration configuration);  URLStreamProvider(int connectionTimeout, int readTimeout, String trustStorePath,
                           String trustStorePassword, String trustStoreType); void setSetupTruststoreForHttps(boolean setupTruststoreForHttps); boolean getSetupTruststoreForHttps(); @Override InputStream readFrom(String spec, String requestMethod, String params); @Override InputStream readFrom(String spec); HttpURLConnection processURL(String spec, String requestMethod, String body, Map<String, List<String>> headers); HttpURLConnection processURL(String spec, String requestMethod, InputStream body, Map<String, List<String>> headers); HttpURLConnection processURL(String spec, String requestMethod, byte[] body, Map<String, List<String>> headers); synchronized AppCookieManager getAppCookieManager(); static String appendCookie(String cookies, String newCookie); static final String COOKIE; }### Answer:
@Test public void testProcessURL() throws Exception { HttpURLConnection connection = createNiceMock(HttpURLConnection.class); AppCookieManager appCookieManager = createNiceMock(AppCookieManager.class); URLStreamProvider urlStreamProvider = createMockBuilder(URLStreamProvider.class). withConstructor(Integer.TYPE, Integer.TYPE, String.class, String.class, String.class). withArgs(1000, 1000, "path", "password", "type"). addMockedMethod("getAppCookieManager"). addMockedMethod("getConnection", String.class). createMock(); expect(urlStreamProvider.getAppCookieManager()).andReturn(appCookieManager).anyTimes(); expect(urlStreamProvider.getConnection("spec")).andReturn(connection); Map<String, List<String>> headerMap = new HashMap<>(); headerMap.put("Header1", Collections.singletonList("value")); headerMap.put("Cookie", Collections.singletonList("FOO=bar")); expect(appCookieManager.getCachedAppCookie("spec")).andReturn("APPCOOKIE=abcdef"); connection.setConnectTimeout(1000); connection.setReadTimeout(1000); connection.setRequestMethod("GET"); connection.setRequestProperty("Header1", "value"); connection.setRequestProperty("Cookie", "FOO=bar; APPCOOKIE=abcdef"); replay(urlStreamProvider, connection, appCookieManager); Assert.assertEquals(connection, urlStreamProvider.processURL("spec", "GET", (String) null, headerMap)); verify(urlStreamProvider, connection, appCookieManager); }
@Test public void testProcessURL_securityNotSetup() throws Exception { URLStreamProvider urlStreamProvider = createMockBuilder(URLStreamProvider.class). withConstructor(Integer.TYPE, Integer.TYPE, String.class, String.class, String.class). withArgs(1000, 1000, null, null, null). addMockedMethod("getAppCookieManager"). addMockedMethod("getConnection", String.class). createMock(); Map<String, List<String>> headerMap = new HashMap<>(); headerMap.put("Header1", Collections.singletonList("value")); headerMap.put("Cookie", Collections.singletonList("FOO=bar")); replay(urlStreamProvider); try { urlStreamProvider.processURL("https: Assert.fail("Expected IllegalStateException"); } catch (IllegalStateException e) { } verify(urlStreamProvider); }