2121 */
2222package com .influxdb .exceptions ;
2323
24+ import java .util .Map ;
2425import java .util .function .Predicate ;
2526import javax .annotation .Nonnull ;
2627import javax .annotation .Nullable ;
2728
29+ import com .google .gson .JsonObject ;
2830import okhttp3 .MediaType ;
2931import okhttp3 .Protocol ;
3032import okhttp3 .Request ;
3133import okhttp3 .ResponseBody ;
3234import org .assertj .core .api .Assertions ;
33- import org .json .JSONObject ;
3435import org .junit .jupiter .api .Test ;
3536import org .junit .platform .runner .JUnitPlatform ;
3637import org .junit .runner .RunWith ;
@@ -160,7 +161,7 @@ void errorBody() {
160161 Response <Object > response = errorResponse ("Wrong query" , 501 , 15 , "{\" error\" : \" error-body\" }" );
161162 throw new InfluxException (new HttpException (response ));
162163 })
163- .matches ((Predicate <Throwable >) throwable -> ((InfluxException ) throwable ).errorBody ().toString ( ).equals ("{ \" error\" : \" error -body\" } " ));
164+ .matches ((Predicate <Throwable >) throwable -> ((InfluxException ) throwable ).errorBody ().get ( "error" ).equals ("error-body" ));
164165 }
165166
166167 @ Test
@@ -201,9 +202,10 @@ void errorBodyReadAgain() {
201202 throw new InfluxException (new HttpException (response ));
202203 })
203204 .matches ((Predicate <Throwable >) throwable -> {
204- JSONObject errorBody1 = ((InfluxException ) throwable ).errorBody ();
205- JSONObject errorBody2 = ((InfluxException ) throwable ).errorBody ();
206- return errorBody1 .toString ().equals ("{\" error\" :\" error-body\" }" ) && errorBody1 .equals (errorBody2 );
205+ Map errorBody1 = ((InfluxException ) throwable ).errorBody ();
206+ Map errorBody2 = ((InfluxException ) throwable ).errorBody ();
207+ return errorBody1 .get ("error" ).equals ("error-body" )
208+ && errorBody1 .equals (errorBody2 );
207209 });
208210 }
209211
@@ -214,7 +216,7 @@ void errorBodyResponseNull() {
214216 .assertThatThrownBy (() -> {
215217 throw new InfluxException (new IllegalStateException ("unExpectedError" ));
216218 })
217- .matches ((Predicate <Throwable >) throwable -> ((InfluxException ) throwable ).errorBody ().toString (). equals ( "{}" ));
219+ .matches ((Predicate <Throwable >) throwable -> ((InfluxException ) throwable ).errorBody ().isEmpty ( ));
218220 }
219221
220222 @ Test
@@ -224,7 +226,7 @@ void errorBodyResponseWithoutBody() {
224226 .assertThatThrownBy (() -> {
225227 throw new InfluxException (new HttpException (errorResponse ("Wrong query" )));
226228 })
227- .matches ((Predicate <Throwable >) throwable -> ((InfluxException ) throwable ).errorBody ().toString (). equals ( "{}" ));
229+ .matches ((Predicate <Throwable >) throwable -> ((InfluxException ) throwable ).errorBody ().isEmpty ( ));
228230 }
229231
230232 @ Test
@@ -237,7 +239,7 @@ void message() {
237239 .hasMessage ("Wrong query" )
238240 .matches ((Predicate <Throwable >) throwable -> ((InfluxException ) throwable ).status () == 0 )
239241 .matches ((Predicate <Throwable >) throwable -> ((InfluxException ) throwable ).reference () == 0 )
240- .matches ((Predicate <Throwable >) throwable -> ((InfluxException ) throwable ).errorBody ().toString (). equals ( "{}" ));
242+ .matches ((Predicate <Throwable >) throwable -> ((InfluxException ) throwable ).errorBody ().isEmpty ( ));
241243
242244 }
243245
@@ -251,7 +253,7 @@ void messageNull() {
251253 .hasMessage (null )
252254 .matches ((Predicate <Throwable >) throwable -> ((InfluxException ) throwable ).status () == 0 )
253255 .matches ((Predicate <Throwable >) throwable -> ((InfluxException ) throwable ).reference () == 0 )
254- .matches ((Predicate <Throwable >) throwable -> ((InfluxException ) throwable ).errorBody ().toString (). equals ( "{}" ));
256+ .matches ((Predicate <Throwable >) throwable -> ((InfluxException ) throwable ).errorBody ().isEmpty ( ));
255257
256258 }
257259
@@ -264,7 +266,7 @@ void nullResponse() {
264266 .hasMessage (null )
265267 .matches ((Predicate <Throwable >) throwable -> ((InfluxException ) throwable ).status () == 0 )
266268 .matches ((Predicate <Throwable >) throwable -> ((InfluxException ) throwable ).reference () == 0 )
267- .matches ((Predicate <Throwable >) throwable -> ((InfluxException ) throwable ).errorBody ().toString (). equals ( "{}" ));
269+ .matches ((Predicate <Throwable >) throwable -> ((InfluxException ) throwable ).errorBody ().isEmpty ( ));
268270 }
269271
270272 @ Nonnull
0 commit comments