@@ -0,0 +1,2984 @@
+// Copyright (C) 2020 The Android Open Source Project%0A//%0A// Licensed under the Apache License, Version 2.0 (the %22License%22);%0A// you may not use this file except in compliance with the License.%0A// You may obtain a copy of the License at%0A//%0A// http://www.apache.org/licenses/LICENSE-2.0%0A//%0A// Unless required by applicable law or agreed to in writing, software%0A// distributed under the License is distributed on an %22AS IS%22 BASIS,%0A// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.%0A// See the License for the specific language governing permissions and%0A// limitations under the License.%0Apackage com.googlesource.gerrit.plugins.its.phabricator.conduit;%0A%0Aimport static com.google.common.truth.Truth.assertThat;%0A%0Aimport com.google.common.collect.Lists;%0Aimport com.google.gson.JsonArray;%0Aimport com.google.gson.JsonObject;%0Aimport com.googlesource.gerrit.plugins.its.base.testutil.LoggingMockingTestCase;%0Aimport com.googlesource.gerrit.plugins.its.phabricator.conduit.results.PhabObject;%0Aimport java.util.List;%0Aimport java.util.stream.Stream;%0Aimport org.junit.Test;%0A%0Apublic class SearchUtilsTest extends LoggingMockingTestCase %7B%0A  @Test%0A  public void testStreamEmpty() throws Exception %7B%0A    JsonObject searchResult = new JsonObject();%0A    searchResult.add(%22data%22, new JsonArray());%0A%0A    SearchUtils searchUtils = createSearchUtils();%0A    Stream%3CPhabObject%3E stream = searchUtils.stream(searchResult, PhabObject.class);%0A    List%3CString%3E streamAsPhidList = Lists.newArrayList(stream.map(o -%3E o.getPhid()).iterator());%0A    assertThat(streamAsPhidList).isEmpty();%0A  %7D%0A%0A  @Test%0A  public void testStreamSingle() throws Exception %7B%0A    JsonArray data = new JsonArray();%0A    data.add(createJsonOfPhabObject(%22PHID1%22));%0A%0A    JsonObject searchResult = new JsonObject();%0A    searchResult.add(%22data%22, data);%0A%0A    SearchUtils searchUtils = createSearchUtils();%0A    Stream%3CPhabObject%3E stream = searchUtils.stream(searchResult, PhabObject.class);%0A    List%3CString%3E streamAsPhidList = Lists.newArrayList(stream.map(o -%3E o.getPhid()).iterator());%0A    assertThat(streamAsPhidList).containsExactly(%22PHID1%22);%0A  %7D%0A%0A  @Test%0A  public void testStreamMultiple() throws Exception %7B%0A    JsonArray data = new JsonArray();%0A    data.add(createJsonOfPhabObject(%22PHID1%22));%0A    data.add(createJsonOfPhabObject(%22PHID2%22));%0A    data.add(createJsonOfPhabObject(%22PHID3%22));%0A%0A    JsonObject searchResult = new JsonObject();%0A    searchResult.add(%22data%22, data);%0A%0A    SearchUtils searchUtils = createSearchUtils();%0A    Stream%3CPhabObject%3E stream = searchUtils.stream(searchResult, PhabObject.class);%0A    List%3CString%3E streamAsPhidList = Lists.newArrayList(stream.map(o -%3E o.getPhid()).iterator());%0A    assertThat(streamAsPhidList).containsExactly(%22PHID1%22, %22PHID2%22, %22PHID3%22);%0A  %7D%0A%0A  private SearchUtils createSearchUtils() %7B%0A    return new SearchUtils();%0A  %7D%0A%0A  private JsonObject createJsonOfPhabObject(String phid) %7B%0A    JsonObject ret = new JsonObject();%0A    ret.addProperty(%22phid%22, phid);%0A%0A    return ret;%0A  %7D%0A%7D%0A

Add tests for SearchUtils