@Test public void testBuildResponseWithFrom() { NpmSearchResponse response = underTest.buildResponseForResults(generateBuckets(10, true, true), 20, 5); assertThat(response.getObjects(), hasSize(5)); assertThat(response.getTime(), not(nullValue())); assertThat(response.getTotal(), is(5)); assertThat(response.getObjects().get(0).getPackageEntry().getName(), is("name-5")); assertThat(response.getObjects().get(1).getPackageEntry().getName(), is("name-6")); assertThat(response.getObjects().get(2).getPackageEntry().getName(), is("name-7")); assertThat(response.getObjects().get(3).getPackageEntry().getName(), is("name-8")); assertThat(response.getObjects().get(4).getPackageEntry().getName(), is("name-9")); }
public NpmSearchResponse buildResponseForResults(final List<Terms.Bucket> buckets, final int size, final int from) { List<NpmSearchResponseObject> objects = buckets.stream() .map(bucket -> (TopHits) bucket.getAggregations().get("versions")) .map(TopHits::getHits) .map(searchHits -> searchHits.getAt(0)) .map(this::buildSearchResponseObject) .skip(from) .limit(size) .collect(toList()); return buildResponseForObjects(objects); }
NpmSearchResponseFactory extends ComponentSupport { public NpmSearchResponse buildResponseForResults(final List<Terms.Bucket> buckets, final int size, final int from) { List<NpmSearchResponseObject> objects = buckets.stream() .map(bucket -> (TopHits) bucket.getAggregations().get("versions")) .map(TopHits::getHits) .map(searchHits -> searchHits.getAt(0)) .map(this::buildSearchResponseObject) .skip(from) .limit(size) .collect(toList()); return buildResponseForObjects(objects); } }
NpmSearchResponseFactory extends ComponentSupport { public NpmSearchResponse buildResponseForResults(final List<Terms.Bucket> buckets, final int size, final int from) { List<NpmSearchResponseObject> objects = buckets.stream() .map(bucket -> (TopHits) bucket.getAggregations().get("versions")) .map(TopHits::getHits) .map(searchHits -> searchHits.getAt(0)) .map(this::buildSearchResponseObject) .skip(from) .limit(size) .collect(toList()); return buildResponseForObjects(objects); } @Inject  NpmSearchResponseFactory(final NpmSearchHitExtractor npmSearchHitExtractor); }
NpmSearchResponseFactory extends ComponentSupport { public NpmSearchResponse buildResponseForResults(final List<Terms.Bucket> buckets, final int size, final int from) { List<NpmSearchResponseObject> objects = buckets.stream() .map(bucket -> (TopHits) bucket.getAggregations().get("versions")) .map(TopHits::getHits) .map(searchHits -> searchHits.getAt(0)) .map(this::buildSearchResponseObject) .skip(from) .limit(size) .collect(toList()); return buildResponseForObjects(objects); } @Inject  NpmSearchResponseFactory(final NpmSearchHitExtractor npmSearchHitExtractor); NpmSearchResponse buildEmptyResponse(); NpmSearchResponse buildResponseForResults(final List<Terms.Bucket> buckets, final int size, final int from); NpmSearchResponse buildResponseForObjects(final List<NpmSearchResponseObject> objects); }
NpmSearchResponseFactory extends ComponentSupport { public NpmSearchResponse buildResponseForResults(final List<Terms.Bucket> buckets, final int size, final int from) { List<NpmSearchResponseObject> objects = buckets.stream() .map(bucket -> (TopHits) bucket.getAggregations().get("versions")) .map(TopHits::getHits) .map(searchHits -> searchHits.getAt(0)) .map(this::buildSearchResponseObject) .skip(from) .limit(size) .collect(toList()); return buildResponseForObjects(objects); } @Inject  NpmSearchResponseFactory(final NpmSearchHitExtractor npmSearchHitExtractor); NpmSearchResponse buildEmptyResponse(); NpmSearchResponse buildResponseForResults(final List<Terms.Bucket> buckets, final int size, final int from); NpmSearchResponse buildResponseForObjects(final List<NpmSearchResponseObject> objects);  }