JSONBuilder { public JSONBuilder array(String key, Collection<?> values) { data.put(key, values); return this; }  JSONBuilder put(String key, @Nullable Object value); JSONBuilder put(String key, @Nullable Instant value); JSONBuilder put(String key, @Nullable Duration value); JSONBuilder putBase64(String key, byte[] data); JSONBuilder putKey(String key, PublicKey publickey); JSONBuilder object(String key); JSONBuilder array(String key, Collection<?> values); Map<String, Object> toMap(); JSON toJSON(); @Override String toString();  }
@Test public void testArray() { JSONBuilder res; JSONBuilder cb1 = new JSONBuilder(); res = cb1.array("ar", Collections.emptyList()); assertThat(res, is(sameInstance(cb1))); assertThat(cb1.toString(), is("{\"ar\":[]}")); JSONBuilder cb2 = new JSONBuilder(); res = cb2.array("ar", Arrays.asList(123)); assertThat(res, is(sameInstance(cb2))); assertThat(cb2.toString(), is("{\"ar\":[123]}")); JSONBuilder cb3 = new JSONBuilder(); res = cb3.array("ar", Arrays.asList(123, "foo", 456)); assertThat(res, is(sameInstance(cb3))); assertThat(cb3.toString(), is("{\"ar\":[123,\"foo\",456]}")); }