### Question:
RLParamParser { public RLParams getParams(String jsonStr) { JSONObject jsonParams = new JSONObject(jsonStr); RLParams params = new RLParams(); if (jsonParams.has("params")) { JSONArray paramList = jsonParams.getJSONArray("params"); for (int i = 0; i < paramList.length(); i++){ JSONObject jsonParam = paramList.getJSONObject(i); String varName = jsonParam.getString("name"); String stringType = jsonParam.getString("type"); Object value; JSONArray jsonArray; switch (stringType) { case "string": value = jsonParam.getString("val"); params.add(varName, value); break; case "bool": value = jsonParam.getBoolean("val"); params.add(varName, value); break; case "long": value = jsonParam.getLong("val"); params.add(varName, value); break; case "int": value = jsonParam.getInt("val"); params.add(varName, value); break; case "double": value = jsonParam.getDouble("val"); params.add(varName, value); break; case "string_array": List<String> strArr = new ArrayList<String>(); jsonArray = jsonParam.getJSONArray("val"); for (int j = 0; j < jsonArray.length(); j++){ strArr.add(jsonArray.getString(j)); } params.add(varName, strArr); break; case "bool_array": List<Boolean> boolArr = new ArrayList<Boolean>(); jsonArray = jsonParam.getJSONArray("val"); for (int j = 0; j < jsonArray.length(); j++){ boolArr.add(jsonArray.getBoolean(j)); } params.add(varName, boolArr); break; case "int_array": List<Integer> intArr = new ArrayList<Integer>(); jsonArray = jsonParam.getJSONArray("val"); for (int j = 0; j < jsonArray.length(); j++){ intArr.add(jsonArray.getInt(j)); } params.add(varName, intArr); break; case "double_array": List<Double> doubleArr = new ArrayList<Double>(); jsonArray = jsonParam.getJSONArray("val"); for (int j = 0; j < jsonArray.length(); j++){ doubleArr.add(jsonArray.getDouble(j)); } params.add(varName, doubleArr); break; } } return params; } else { throw new JSONException("Object needs to have params as root"); } }  RLParams getParams(String jsonStr); RLParams getParamsFile(String filename);  }### Answer:
@Test public void testReadJsonIntArray(){ RLParamParser parser = new RLParamParser(); RLParams params = parser.getParams("{\"params\" : [{\"type\": \"int_array\", \"name\": \"numc\", \"val\": [1,2,4]}]}"); List<Integer> numc = (List<Integer>) params.get("numc"); Integer[] expectedNumc = new Integer[]{1, 2, 4}; assertArrayEquals(numc.toArray(), expectedNumc); }
@Test public void testManyParams(){ RLParamParser parser = new RLParamParser(); RLParams params = parser.getParams("{\"params\" : [{\"type\": \"int\", \"name\": \"numc\", \"val\": 1}," + "{\"type\": \"string\", \"name\": \"strval\", \"val\": \"hello\"}]}"); Integer numc = (Integer) params.get("numc"); String strval = (String) params.get("strval"); assertEquals(numc, (Integer) 1); assertEquals(strval, "hello"); }
@Test public void testReadJsonStringArray(){ RLParamParser parser = new RLParamParser(); RLParams params = parser.getParams("{\"params\" : [{\"type\": \"string_array\", \"name\": \"numv\", \"val\": [\"asd\", \"asda\"]}]}"); List<String> numv = (List<String>) params.get("numv"); String[] expectedNumv = new String[]{"asd", "asda"}; assertArrayEquals(numv.toArray(), expectedNumv); }