@Test public void testLoadQuestionFromTextInvalid() { JSONObject testQuestion = new JSONObject(); _thrown.expect(BatfishException.class); _thrown.expectMessage("Question in questionSource has no instance data"); Client.loadQuestionFromText(testQuestion.toString(), "questionSource"); }
static JSONObject loadQuestionFromText(String questionText, String questionSource) { try { JSONObject questionObj = new JSONObject(questionText); if (questionObj.has(BfConsts.PROP_INSTANCE) && !questionObj.isNull(BfConsts.PROP_INSTANCE)) { JSONObject instanceDataObj = questionObj.getJSONObject(BfConsts.PROP_INSTANCE); String instanceDataStr = instanceDataObj.toString(); InstanceData instanceData = BatfishObjectMapper.mapper() .readValue(instanceDataStr, new TypeReference<InstanceData>() {}); validateInstanceData(instanceData); return questionObj; } else { throw new BatfishException( String.format("Question in %s has no instance data", questionSource)); } } catch (JSONException | IOException e) { throw new BatfishException("Failed to process question", e); } }
Client extends AbstractClient implements IClient { static JSONObject loadQuestionFromText(String questionText, String questionSource) { try { JSONObject questionObj = new JSONObject(questionText); if (questionObj.has(BfConsts.PROP_INSTANCE) && !questionObj.isNull(BfConsts.PROP_INSTANCE)) { JSONObject instanceDataObj = questionObj.getJSONObject(BfConsts.PROP_INSTANCE); String instanceDataStr = instanceDataObj.toString(); InstanceData instanceData = BatfishObjectMapper.mapper() .readValue(instanceDataStr, new TypeReference<InstanceData>() {}); validateInstanceData(instanceData); return questionObj; } else { throw new BatfishException( String.format("Question in %s has no instance data", questionSource)); } } catch (JSONException | IOException e) { throw new BatfishException("Failed to process question", e); } } }
Client extends AbstractClient implements IClient { static JSONObject loadQuestionFromText(String questionText, String questionSource) { try { JSONObject questionObj = new JSONObject(questionText); if (questionObj.has(BfConsts.PROP_INSTANCE) && !questionObj.isNull(BfConsts.PROP_INSTANCE)) { JSONObject instanceDataObj = questionObj.getJSONObject(BfConsts.PROP_INSTANCE); String instanceDataStr = instanceDataObj.toString(); InstanceData instanceData = BatfishObjectMapper.mapper() .readValue(instanceDataStr, new TypeReference<InstanceData>() {}); validateInstanceData(instanceData); return questionObj; } else { throw new BatfishException( String.format("Question in %s has no instance data", questionSource)); } } catch (JSONException | IOException e) { throw new BatfishException("Failed to process question", e); } } Client(Settings settings);  Client(String[] args); }
Client extends AbstractClient implements IClient { static JSONObject loadQuestionFromText(String questionText, String questionSource) { try { JSONObject questionObj = new JSONObject(questionText); if (questionObj.has(BfConsts.PROP_INSTANCE) && !questionObj.isNull(BfConsts.PROP_INSTANCE)) { JSONObject instanceDataObj = questionObj.getJSONObject(BfConsts.PROP_INSTANCE); String instanceDataStr = instanceDataObj.toString(); InstanceData instanceData = BatfishObjectMapper.mapper() .readValue(instanceDataStr, new TypeReference<InstanceData>() {}); validateInstanceData(instanceData); return questionObj; } else { throw new BatfishException( String.format("Question in %s has no instance data", questionSource)); } } catch (JSONException | IOException e) { throw new BatfishException("Failed to process question", e); } } Client(Settings settings);  Client(String[] args); @Override BatfishLogger getLogger(); Settings getSettings(); void run(List<String> initialCommands); }
Client extends AbstractClient implements IClient { static JSONObject loadQuestionFromText(String questionText, String questionSource) { try { JSONObject questionObj = new JSONObject(questionText); if (questionObj.has(BfConsts.PROP_INSTANCE) && !questionObj.isNull(BfConsts.PROP_INSTANCE)) { JSONObject instanceDataObj = questionObj.getJSONObject(BfConsts.PROP_INSTANCE); String instanceDataStr = instanceDataObj.toString(); InstanceData instanceData = BatfishObjectMapper.mapper() .readValue(instanceDataStr, new TypeReference<InstanceData>() {}); validateInstanceData(instanceData); return questionObj; } else { throw new BatfishException( String.format("Question in %s has no instance data", questionSource)); } } catch (JSONException | IOException e) { throw new BatfishException("Failed to process question", e); } } Client(Settings settings);  Client(String[] args); @Override BatfishLogger getLogger(); Settings getSettings(); void run(List<String> initialCommands);  }