예제 #1
0
  @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());
  }
예제 #2
0
  @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());
  }
예제 #3
0
  @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\"}"));
  }
예제 #4
0
  @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"));
  }
예제 #5
0
  @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));
  }
예제 #6
0
 @Test
 public void shouldNotBeNewIfThereIsID() throws JSONException {
   Child child = new Child();
   child.put(internal_id.getColumnName(), "xyz");
   assertThat(child.isNew(), is(false));
 }
예제 #7
0
 @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"));
 }