BatchError implements Parcelable { @NonNull @Api(2.3) public BatchErrorInfo getError() { return mError; } protected  BatchError(); protected  BatchError(Parcel in); @Override int describeContents(); @Override void writeToParcel(Parcel dest, int flags); @Nullable static BatchError deserialize(@Nullable String batchError, @NonNull Parser.Factory parser); @NonNull @Api(2.3) BatchErrorInfo getError(); static final Creator<BatchError> CREATOR; }
@Test public void thatErrorIsParcelable() throws JSONException { BatchOperationResult instance = new BatchOperationResult(BatchOperator.DELETE, 0, false, new JSONObject("{\n" + " \"error\": {\n" + " \"status\": 403,\n" + " \"message\": \"You can not update an instance of a module that does not belong to you or does not exist\",\n" + " \"extra\": {},\n" + " \"type\": \"HaloError\"\n" + " }\n" + " }")); BatchError error = instance.getDataError(); BatchError parcelInstance = TestUtils.testParcel(error, BatchError.CREATOR); assertThat(error.getError().mMessage).isEqualTo(parcelInstance.getError().mMessage); }
@Test public void thatCanReachErrorInfoData() throws JSONException { JSONObject errorExtra = new JSONObject("{\n" + " \"error\": {\n" + " \"status\": 403,\n" + " \"message\": \"You can not update an instance of a module that does not belong to you or does not exist\",\n" + " \"extra\": {\n" + " \"field\": \"amount\",\n" + " \"error\": \"validator.8\",\n" + " \"message\": \"Please check the text field, it should be a string\"\n" + " },\n" + " \"type\": \"HaloError\"\n" + " }\n" + " }"); BatchOperationResult instance = new BatchOperationResult(BatchOperator.DELETE, 0, false, errorExtra); BatchError error = instance.getDataError(); BatchErrorInfo errorInfo = error.getError(); assertThat(errorInfo.getStatus()).isEqualTo(403); assertThat(errorInfo.getType()).isEqualTo("HaloError"); assertThat(errorInfo.getMessage()).contains("belong to you or does not exist"); assertThat(errorInfo.getExtra().toString()).contains("validator.8"); }