@@ -99,7 +99,7 @@ public void testGetError() throws URISyntaxException, IOException {
9999
100100 Mockito .when (mockHttpURLConnection .getResponseCode ()).thenReturn (HttpURLConnection .HTTP_INTERNAL_ERROR );
101101 ByteArrayInputStream stubInputStream = new ByteArrayInputStream (Files .asCharSource (
102- new File ("/Users/bilalal-shahwany/repos/java/kerberos/java-client/client/ src/test/resources/split-change-special-characters.json" ), Charsets .UTF_8 ).read ().getBytes (Charsets .UTF_8 ));
102+ new File ("src/test/resources/split-change-special-characters.json" ), Charsets .UTF_8 ).read ().getBytes (Charsets .UTF_8 ));
103103 when (mockHttpURLConnection .getInputStream ()).thenReturn (stubInputStream );
104104
105105 SplitHttpClientKerberosImpl splitHtpClientKerberos = SplitHttpClientKerberosImpl .create (decorator , "qwerty" , metadata ());
@@ -111,13 +111,16 @@ public void testGetError() throws URISyntaxException, IOException {
111111 @ Test (expected = IllegalStateException .class )
112112 public void testException () throws URISyntaxException , InvocationTargetException , NoSuchMethodException ,
113113 IllegalAccessException , IOException {
114- URI rootTarget = URI .create ("https://api.split.io/splitChanges?since=1234567" );
115- CloseableHttpClient httpClientMock = TestHelper .mockHttpClient ("split-change-special-characters.json" ,
116- HttpStatus .SC_INTERNAL_SERVER_ERROR );
114+ HttpURLConnection mockHttpURLConnection = Mockito .mock (HttpURLConnection .class );
117115 RequestDecorator decorator = null ;
118116
119- SplitHttpClient splitHtpClient = SplitHttpClientImpl .create (httpClientMock , decorator , "qwerty" , metadata ());
120- splitHtpClient .get (rootTarget ,
117+ Mockito .when (mockHttpURLConnection .getResponseCode ()).thenReturn (HttpURLConnection .HTTP_INTERNAL_ERROR );
118+ ByteArrayInputStream stubInputStream = new ByteArrayInputStream (Files .asCharSource (
119+ new File ("src/test/resources/split-change-special-characters.json" ), Charsets .UTF_8 ).read ().getBytes (Charsets .UTF_8 ));
120+ when (mockHttpURLConnection .getInputStream ()).thenReturn (stubInputStream );
121+
122+ SplitHttpClientKerberosImpl splitHtpClientKerberos = SplitHttpClientKerberosImpl .create (decorator , "qwerty" , metadata ());
123+ SplitHttpResponse splitHttpResponse = splitHtpClientKerberos ._get (mockHttpURLConnection ,
121124 new FetchOptions .Builder ().cacheControlHeaders (true ).build (), null );
122125 }
123126
@@ -178,11 +181,13 @@ public void testPotParameters() throws URISyntaxException, IOException {
178181 assertThat (connectionCaptor .getValue ().getURL ().toString (), is (equalTo (new URL ("https://kubernetesturl.com/split/api/testImpressions/bulk" ).toString ())));
179182 }
180183
181- @ Test ( expected = IOException . class )
182- public void testPosttException () throws URISyntaxException , IOException {
184+ @ Test
185+ public void testPosttError () throws URISyntaxException , IOException {
183186 HttpURLConnection mockHttpURLConnection = Mockito .mock (HttpURLConnection .class );
184187 RequestDecorator decorator = new RequestDecorator (null );
188+ ByteArrayOutputStream mockOs = Mockito .mock ( ByteArrayOutputStream .class );
185189 Mockito .when (mockHttpURLConnection .getResponseCode ()).thenReturn (HttpURLConnection .HTTP_INTERNAL_ERROR );
190+ when (mockHttpURLConnection .getOutputStream ()).thenReturn (mockOs );
186191
187192 SplitHttpClientKerberosImpl splitHtpClientKerberos = SplitHttpClientKerberosImpl .create (decorator , "qwerty" , metadata ());
188193 SplitHttpResponse splitHttpResponse = splitHtpClientKerberos ._post (mockHttpURLConnection ,
@@ -191,6 +196,17 @@ public void testPosttException() throws URISyntaxException, IOException {
191196 Assert .assertEquals (HttpStatus .SC_INTERNAL_SERVER_ERROR , (long ) splitHttpResponse .statusCode ());
192197 }
193198
199+ @ Test (expected = IllegalStateException .class )
200+ public void testPosttException () throws URISyntaxException , IOException {
201+ HttpURLConnection mockHttpURLConnection = Mockito .mock (HttpURLConnection .class );
202+ RequestDecorator decorator = null ;
203+ Mockito .when (mockHttpURLConnection .getResponseCode ()).thenReturn (HttpURLConnection .HTTP_OK );
204+
205+ SplitHttpClientKerberosImpl splitHtpClientKerberos = SplitHttpClientKerberosImpl .create (decorator , "qwerty" , metadata ());
206+ SplitHttpResponse splitHttpResponse = splitHtpClientKerberos ._post (mockHttpURLConnection ,
207+ Utils .toJsonEntity (Arrays .asList (new String [] { "A" , "B" , "C" , "D" })), null );
208+ }
209+
194210 private SDKMetadata metadata () {
195211 return new SDKMetadata ("java-1.2.3" , "1.2.3.4" , "someIP" );
196212 }
0 commit comments