JsonGenerator { public static JsonValue createJsonArray(Collection<?> collection) throws JsonException { if (collection == null) { return new NullValue(); } return createJsonValue(collection, COLLECTION); }  static JsonValue createJsonArray(Collection<?> collection); static JsonValue createJsonArray(Object array); static JsonValue createJsonObjectFromMap(Map<String, ?> map); static JsonValue createJsonObject(Object object);  }
@Test public void convertsArrayToJson() throws Exception { Book[] books = new Book[]{junitBook, csharpBook, javaScriptBook}; JsonValue jsonArray = JsonGenerator.createJsonArray(books); assertTrue(jsonArray.isArray()); assertionHelper.assertThatJsonArrayHasAllItemsFromArray(books, jsonArray); }
@Test(expected = JsonException.class) public void doesNotAcceptOtherThanArrayArgumentsWhenCreateJsonArray() throws Exception { JsonGenerator.createJsonArray(junitBook); }
@Test public void convertsNullArrayToJson() throws Exception { JsonValue jsonValue = JsonGenerator.createJsonArray((Object)null); assertTrue(jsonValue.isNull()); }
@Test public void convertsListToJson() throws Exception { List<Book> books = newArrayList(junitBook, csharpBook, javaScriptBook); JsonValue jsonArray = JsonGenerator.createJsonArray(books); assertTrue(jsonArray.isArray()); assertionHelper.assertThatJsonArrayHasAllItemsFromCollection(books, jsonArray); }
@Test public void convertsSetToJsonArray() throws Exception { Set<Book> books = newHashSet(junitBook, csharpBook, javaScriptBook); JsonValue jsonArray = JsonGenerator.createJsonArray(books); assertTrue(jsonArray.isArray()); assertionHelper.assertThatJsonArrayHasAllItemsFromCollection(books, jsonArray); }
@Test public void convertsNullCollectionToJson() throws Exception { JsonValue jsonValue = JsonGenerator.createJsonArray(null); assertTrue(jsonValue.isNull()); }
@UseDataProvider("collectionsOfComplexObjectsForConvertToJson") @Test public void convertsCollectionsOfComplexObjectsToJson(Collection<Object> objects) throws Exception { JsonValue jsonValue = JsonGenerator.createJsonArray(objects); assertTrue(jsonValue.isArray()); assertionHelper.assertThatJsonArrayHasAllItemsFromCollection(objects, jsonValue); }