@Test public void testBuildResponseWithSize() { NpmSearchResponse response = underTest.buildResponseForResults(generateBuckets(5, true, true), 3, 0); assertThat(response.getObjects(), hasSize(3)); assertThat(response.getTime(), not(nullValue())); assertThat(response.getTotal(), is(3)); assertThat(response.getObjects().get(0).getPackageEntry().getName(), is("name-0")); assertThat(response.getObjects().get(1).getPackageEntry().getName(), is("name-1")); assertThat(response.getObjects().get(2).getPackageEntry().getName(), is("name-2")); }
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);  }