ConfigPayloadBuilder { public Array getArray(String name) { Array a = arrayMap.get(name); if (a == null) { validateArray(name); a = new Array(configDefinition, name); arrayMap.put(name, a); } return a; } ConfigPayloadBuilder();  ConfigPayloadBuilder(ConfigDefinition configDefinition); private  ConfigPayloadBuilder(String value); private  ConfigPayloadBuilder(ConfigDefinition configDefinition, String value); private  ConfigPayloadBuilder(ConfigPayloadBuilder other);  ConfigPayloadBuilder(ConfigPayload payload); void setField(String name, String value); ConfigPayloadBuilder getObject(String name); Array getArray(String name); void resolve(Cursor parent); ConfigPayloadBuilder override(ConfigPayloadBuilder other); String getValue(); void setValue(String value); MapBuilder getMap(String name); ConfigDefinition getConfigDefinition();  }
@Test public void require_that_arrays_are_created() { ConfigPayloadBuilder builder = new ConfigPayloadBuilder(); ConfigPayloadBuilder.Array array = builder.getArray("foo"); assertNotNull(array); }
@Test public void require_that_arrays_can_be_appended_simple_values() { ConfigPayloadBuilder builder = new ConfigPayloadBuilder(); ConfigPayloadBuilder.Array array = builder.getArray("foo"); array.append("bar"); array.append("baz"); array.append("bim"); assertThat(array.getElements().size(), is(3)); Cursor root = createSlime(builder); Cursor a = root.field("foo"); assertEquals("bar", a.entry(0).asString()); assertEquals("baz", a.entry(1).asString()); assertEquals("bim", a.entry(2).asString()); }
@Test public void require_that_arrays_can_be_indexed_simple_values() { ConfigPayloadBuilder builder = new ConfigPayloadBuilder(); ConfigPayloadBuilder.Array array = builder.getArray("foo"); array.set(3, "bar"); array.set(2, "baz"); array.set(6, "bim"); array.set(4, "bum"); Cursor root = createSlime(builder); Cursor a = root.field("foo"); assertEquals("bar", a.entry(0).asString()); assertEquals("baz", a.entry(1).asString()); assertEquals("bim", a.entry(2).asString()); assertEquals("bum", a.entry(3).asString()); }
@Test public void require_that_get_can_be_used_instead() { ConfigPayloadBuilder builder = new ConfigPayloadBuilder(); ConfigPayloadBuilder.Array array = builder.getArray("foo"); ConfigPayloadBuilder b1 = array.get(0); ConfigPayloadBuilder b2 = array.get(1); ConfigPayloadBuilder b3 = array.get(0); ConfigPayloadBuilder b4 = array.get(1); assertThat(b1, is(b3)); assertThat(b2, is(b4)); ConfigPayloadBuilder.Array array_indexed = builder.getArray("bar"); ConfigPayloadBuilder bi3 = array_indexed.set(3); ConfigPayloadBuilder bi1 = array_indexed.set(1); ConfigPayloadBuilder bi32 = array_indexed.get(3); ConfigPayloadBuilder bi12 = array_indexed.get(1); assertThat(bi12, is(bi1)); assertThat(bi32, is(bi3)); }
@Test(expected=IllegalStateException.class) public void require_that_append_conflicts_with_index() { ConfigPayloadBuilder builder = new ConfigPayloadBuilder(); ConfigPayloadBuilder.Array array = builder.getArray("foo"); array.set(0, "bar"); array.append("baz"); }
@Test(expected=IllegalStateException.class) public void require_that_index_conflicts_with_append() { ConfigPayloadBuilder builder = new ConfigPayloadBuilder(); ConfigPayloadBuilder.Array array = builder.getArray("foo"); array.append("baz"); array.set(0, "bar"); }
@Test(expected=IllegalArgumentException.class) public void require_that_arrays_must_exist() { builderWithDef.getArray("arraydoesnotexist"); }
@Test public void require_that_definition_is_passed_to_childarray() { ConfigPayloadBuilder.Array nestedArray = builderWithDef.getArray("myarray"); nestedArray.append("1337"); }
@Test(expected=IllegalArgumentException.class) public void require_that_definition_is_passed_to_childarray_but_invalid_field_will_throw() { ConfigPayloadBuilder.Array nestedArray = builderWithDef.getArray("myarray"); nestedArray.append("invalid"); }