@Test public void openShouldOpenAHttpURLConnectionAndInjectItIntoAHttpURLConnectionHttpChannel() throws Exception { URL url = PowerMockito.mock(URL.class); HttpURLConnection httpURLConnection = mock(HttpURLConnection.class); HttpURLConnectionHttpChannel expected = mock(HttpURLConnectionHttpChannel.class); MethodType methodType = MethodType.POST; whenNew(URL.class).withArguments("url").thenReturn(url); whenNew(HttpURLConnectionHttpChannel.class).withArguments(httpURLConnection, methodType).thenReturn(expected); when(url.openConnection()).thenReturn(httpURLConnection); HttpChannel actual = toTest.open(methodType, "url", null); assertSame(expected, actual); verify(httpURLConnection).setRequestMethod("POST"); }
public HttpChannel open(MethodType methodType, String url, Charset charset) throws IOException { HttpURLConnection con = (HttpURLConnection) new URL(url).openConnection(); con.setRequestMethod(methodType.name()); return new HttpURLConnectionHttpChannel(con, methodType); }
HttpURLConnectionHttpChannelFactory implements HttpChannelFactory { public HttpChannel open(MethodType methodType, String url, Charset charset) throws IOException { HttpURLConnection con = (HttpURLConnection) new URL(url).openConnection(); con.setRequestMethod(methodType.name()); return new HttpURLConnectionHttpChannel(con, methodType); } }
HttpURLConnectionHttpChannelFactory implements HttpChannelFactory { public HttpChannel open(MethodType methodType, String url, Charset charset) throws IOException { HttpURLConnection con = (HttpURLConnection) new URL(url).openConnection(); con.setRequestMethod(methodType.name()); return new HttpURLConnectionHttpChannel(con, methodType); }  }
HttpURLConnectionHttpChannelFactory implements HttpChannelFactory { public HttpChannel open(MethodType methodType, String url, Charset charset) throws IOException { HttpURLConnection con = (HttpURLConnection) new URL(url).openConnection(); con.setRequestMethod(methodType.name()); return new HttpURLConnectionHttpChannel(con, methodType); }  HttpChannel open(MethodType methodType, String url, Charset charset); }
HttpURLConnectionHttpChannelFactory implements HttpChannelFactory { public HttpChannel open(MethodType methodType, String url, Charset charset) throws IOException { HttpURLConnection con = (HttpURLConnection) new URL(url).openConnection(); con.setRequestMethod(methodType.name()); return new HttpURLConnectionHttpChannel(con, methodType); }  HttpChannel open(MethodType methodType, String url, Charset charset);  }