### Question:
AdvertDAO extends CrudDAO<Advert> { public List<Advert> findByFilter(FilterDTO filter) { System.out.println(filter); System.out.println(filter.getBrand() == null); return this.getWrapper().wrapAndExecute(session -> session.createQuery( "from Advert as a " + "left join fetch a.model AS m " + "left join fetch a.body " + "left join fetch a.driveUnit " + "left join fetch a.engine " + "left join fetch a.transmission " + "left join fetch a.wheel " + "where (:brandFilter = true or m.brand = :brand) AND" + "(:photoFilter = true or a.photo is not null) AND" + "(:dateStartFilter = true or a.advertDate > :dateStart) AND" + "(:dateFinishFilter = true or a.advertDate < :dateFinish)", Advert.class ).setParameter("brandFilter", filter.getBrand() == null) .setParameter("brand", filter.getBrand()) .setParameter("photoFilter", !filter.isWithPhoto()) .setParameter("dateStartFilter", filter.getStartDate() == null) .setParameter("dateStart", filter.getStartDate()) .setParameter("dateFinishFilter", filter.getFinishDate() == null) .setParameter("dateFinish", filter.getFinishDate()) .list() ); } AdvertDAO(SessionFactory sf); List<Advert> findByFilter(FilterDTO filter);  }### Answer:
@Test public void findByPhotoFilter() { Advert firstEntity = this.getTestEntity(); firstEntity.setId(this.getTestDao().add(firstEntity)); Advert secondEntity = this.getSecondTestEntity(); secondEntity.setId(this.getTestDao().add(secondEntity)); FilterDTO filter = new FilterDTO(); filter.setWithPhoto(true); List<Advert> result = this.getTestDao().findByFilter(filter); assertTrue(result.contains(secondEntity)); assertFalse(result.contains(firstEntity)); }
@Test public void findByDateFilter() { FilterDTO filter = new FilterDTO(); filter.setStartDate(new Timestamp(new Date().getTime())); Advert entity = this.getSecondTestEntity(); entity.setId(this.getTestDao().add(entity)); assertThat(this.getTestDao().findByFilter(filter).get(0), is(entity)); }