CheckBoxes extends BaseView { @Override protected void initialize() { try { super.initialize(); for (String option : formField.getLocalizedOptionStrings()) getCheckBoxGroup().addView(createCheckBoxFor(option)); } catch (JSONException e) { e.printStackTrace(); throw new RuntimeException(e); } } CheckBoxes(Context context);  CheckBoxes(Context context, AttributeSet attrs); @Override void setEnabled(boolean enabled);  }
@Test public void testStoreCheckedValueIntoChildJSONObject() throws JSONException { field.setOptionStrings(new HashMap<String, List<String>>(){{put("en", Arrays.asList("one", "two", "three"));}}); view.initialize(field, child); CheckBox checkBox1 = checkCheckBoxAtIndex(0, true); JSONArray options = new JSONArray(); options.put(checkBox1.getText()); assertEquals(options.toString(), (child.get(field.getId())).toString()); CheckBox checkBox2 = checkCheckBoxAtIndex(1, true); options.put(checkBox2.getText()); assertEquals(options.toString(), child.get(field.getId()).toString()); }
@Test public void testRemoveUncheckedCheckBoxValuesFromChildJSONObject() throws JSONException { field.setOptionStrings(new HashMap<String, List<String>>(){{put("en", Arrays.asList("one", "two", "three"));}}); view.initialize(field, child); CheckBox checkBox1 = checkCheckBoxAtIndex(0, true); JSONArray options = new JSONArray(); options.put(checkBox1.getText()); assertEquals(options.toString(), (child.get(field.getId())).toString()); CheckBox checkBox2 = checkCheckBoxAtIndex(1, true); options.put(checkBox2.getText()); assertEquals(options.toString(), child.get(field.getId()).toString()); checkBox1.setChecked(false); assertEquals("two", ((JSONArray)child.get(field.getId())).get(0)); }