@Test public void shouldRemoveFieldIfJSONArrayIsEmtpy() throws JSONException { Child child = new Child(); child.put("name", new JSONArray(Arrays.asList("one"))); assertThat(child.values().names().length(), equalTo(1)); child.put("name", new JSONArray()); assertNull(child.values().names()); }
@Test public void shouldRemoveFieldIfBlank() throws JSONException { Child child = new Child(); child.put("name", "test"); assertThat(child.values().names().length(), equalTo(1)); child.put("name", "\r \n \r \n"); assertNull(child.values().names()); }
@Test public void valuesShouldReturnAllExceptSystemFields() throws JSONException, IOException { Child child = new Child(); child.put("test1", "value1"); for (Database.ChildTableColumn column : Database.ChildTableColumn.systemFields()) { child.put(column.getColumnName(), "test"); } assertThat(child.values(), equalJSONIgnoreOrder("{\"test1\":\"value1\"}")); }
@Test public void shouldRemoveFieldIfNull() throws JSONException { Child child = new Child(); child.put("name", "test"); assertEquals(child.get("name"), "test"); Object value = null; child.put("name", value); assertNull(child.opt("name")); }
@Test public void testAtLeastOneFieldIsFilledExcludingIdAndOwner() throws JSONException { Child child = new Child("id1", "owner1", null); assertThat(child.isValid(), is(false)); child.put("test1", "value1"); assertThat(child.isValid(), is(true)); child.remove("test1"); assertThat(child.isValid(), is(false)); }
@Test public void shouldNotBeNewIfThereIsID() throws JSONException { Child child = new Child(); child.put(internal_id.getColumnName(), "xyz"); assertThat(child.isNew(), is(false)); }
@Test public void shouldTrimFieldValues() throws JSONException { Child child = new Child(); child.put("name", "\r\n line1 \r\n line2 \r\n \r\n"); assertThat(child.getString("name"), equalTo("line1 \r\n line2")); }