ImmutableSearchResult implements SearchResult { public static ImmutableSearchResult of(final JsonArray items, @Nullable final Long nextPageOffset, @Nullable final String cursor) { return new ImmutableSearchResult(items, nextPageOffset, cursor); } private  ImmutableSearchResult(final JsonArray items, @Nullable final Long nextPageOffset,
            @Nullable final String cursor); static SearchResult empty(); static ImmutableSearchResult of(final JsonArray items,
            @Nullable final Long nextPageOffset,
            @Nullable final String cursor); static ImmutableSearchResult fromJson(final JsonObject jsonObject); @Override JsonArray getItems(); @Override Optional<Long> getNextPageOffset(); @Override Optional<String> getCursor(); @Override boolean hasNextPage(); @Override int getSize(); @Override boolean isEmpty(); @Override Stream<JsonValue> stream(); @Override Iterator<JsonValue> iterator(); @Override JsonObject toJson(final JsonSchemaVersion schemaVersion, final Predicate<JsonField> thePredicate); @Override boolean equals(final Object o); @Override int hashCode(); @Override String toString();  }
@Test public void toJsonWithAllFieldTypes() { final String itemsArray = "[1,2,3]"; final JsonArray items = JsonFactory.newArray(itemsArray); final long nextPageOffset = 10L; final ImmutableSearchResult searchResult = ImmutableSearchResult.of(items, nextPageOffset, null); final String jsonStr = searchResult.toJsonString(FieldType.regularOrSpecial()); assertThat(jsonStr).isEqualTo( "{\"__schemaVersion\":" + 2 + ",\"items\":" + itemsArray + ",\"nextPageOffset\":" + nextPageOffset + "}"); }
@Test public void toJsonWithRegularFieldTypes() { final String itemsArray = "[1,2,3]"; final JsonArray items = JsonFactory.newArray(itemsArray); final long nextPageOffset = 10L; final ImmutableSearchResult searchResult = ImmutableSearchResult.of(items, nextPageOffset, null); final String jsonStr = searchResult.toJsonString(); assertThat(jsonStr).isEqualTo("{\"items\":" + itemsArray + ",\"nextPageOffset\":" + nextPageOffset + "}"); }
@Test public void ensureSearchResultNewBuilderWorks() { final String itemsArray = "[1,2,3]"; final JsonArray items = JsonFactory.newArray(itemsArray); final long nextPageOffset = 10L; final ImmutableSearchResult searchResult = ImmutableSearchResult.of(items, nextPageOffset, null); final SearchResultBuilder searchResultBuilder = SearchResult.newBuilder() .addAll(items) .nextPageOffset(nextPageOffset); assertThat(searchResult).isEqualTo(searchResultBuilder.build()); }
@Test public void ensureRelationsToBuilderWorks() { final String itemsArray = "[1,2,3]"; final JsonArray items = JsonFactory.newArray(itemsArray); final long nextPageOffset = 10L; final ImmutableSearchResult searchResult = ImmutableSearchResult.of(items, nextPageOffset, null); DittoJsonAssertions.assertThat(searchResult).isEqualTo(searchResult.toBuilder().build()); }