# Filters and Junit tests

**URL:** <https://discuss.elastic.co/t/filters-and-junit-tests/9932>\
**Category:** Elasticsearch\
**Created:** [December 4, 2012, 12:44pm UTC](https://discuss.elastic.co/t/filters-and-junit-tests/9932 "2012-12-04T12:44:58Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Tatiana](https://avatars.discourse-cdn.com/v4/letter/t/e79b87/32.png) [@Tatiana](https://discuss.elastic.co/u/Tatiana)\
**Post date:** [December 4, 2012, 12:44pm UTC](https://discuss.elastic.co/t/filters-and-junit-tests/9932/1 "2012-12-04T12:44:58Z")

</div>

Hi  
I 'm implementing a custom query builder and I would like to test my  
methods.  
Basically I'm building a filter with "and" and "or" clause but I can't  
create Junit tests because elasticsearch doesn't give me any getter methods  
so I 'm not able to test if the filter I built was the one expected.  
also the toString method is not implemented.  
Would that be possible to get the toString method implemented or to get  
getter methods in order to be able to tests filters?

--

---

<div class="post-metadata">

**Author:** ![Igor\_Motov](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/igor_motov/32/45193_2.png) [@Igor\_Motov](https://discuss.elastic.co/u/Igor_Motov)\
**Post date:** [December 6, 2012, 7:47pm UTC](https://discuss.elastic.co/t/filters-and-junit-tests/9932/2 "2012-12-06T19:47:44Z")

</div>

You can use XContentBuilder to generate a query builder's  
json equivalent like this:

```
    BaseFilterBuilder filterBuilder = andFilter(termFilter("foo", 

```

"bar"), termFilter("foo", "baz"));  
XContentBuilder builder = XContentFactory.jsonBuilder();  
filterBuilder.toXContent(builder, ToXContent.EMPTY\_PARAMS);  
builder.close();  
String filterJson = builder.string(); // it will be  
"{"and":{"filters":[{"term":{"foo":"bar"}},{"term":{"foo":"baz"}}]}}"

On Tuesday, December 4, 2012 7:44:58 AM UTC-5, Tatiana wrote:

> Hi  
> I 'm implementing a custom query builder and I would like to test my  
> methods.  
> Basically I'm building a filter with "and" and "or" clause but I can't  
> create Junit tests because elasticsearch doesn't give me any getter methods  
> so I 'm not able to test if the filter I built was the one expected.  
> also the toString method is not implemented.  
> Would that be possible to get the toString method implemented or to get  
> getter methods in order to be able to tests filters?

--

---

<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:** [July 6, 2017, 3:01am UTC](https://discuss.elastic.co/t/filters-and-junit-tests/9932/3 "2017-07-06T03:01:02Z")

</div>

Closed on July 6, 2017, 3:01am UTC


