# Mockito Test for Elastic Java api client

**URL:** <https://discuss.elastic.co/t/mockito-test-for-elastic-java-api-client/315773>\
**Category:** Elasticsearch\
**Tags:** language-clients\
**Created:** [October 4, 2022, 12:23pm UTC](https://discuss.elastic.co/t/mockito-test-for-elastic-java-api-client/315773 "2022-10-04T12:23:56Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![painless\_elastic](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/painless_elastic/32/94652_2.png) [@painless\_elastic](https://discuss.elastic.co/u/painless_elastic)\
**Post date:** [October 4, 2022, 12:23pm UTC](https://discuss.elastic.co/t/mockito-test-for-elastic-java-api-client/315773/1 "2022-10-04T12:23:56Z")

</div>

I have tried to mock the response for the below method, but it's not working. Not able to mock the **search.hits().hits()** method.

```auto
SearchResponse<Product> search = client.search(s -> s
    .index("products")
    .query(q -> q
        .term(t -> t
            .field("name")
            .value(v -> v.stringValue("bicycle"))
        )),
    Product.class);

for (Hit<Product> hit: search.hits().hits()) {
    processProduct(hit.source());
}

```

Any idea how to do that?

CC - @swallez

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [October 25, 2022, 8:24am UTC](https://discuss.elastic.co/t/mockito-test-for-elastic-java-api-client/315773/2 "2022-10-25T08:24:36Z")

</div>

This topic was automatically closed 20 days after the last reply. New replies are no longer allowed.
