@Test
public void testFiltersToJSON() throws Exception {

  String expectedJSON = IOUtils.toString(getClass().getResource("/filters.json"));
  SecurityService securityService = EasyMock.createNiceMock(SecurityService.class);
  Organization organization = EasyMock.createNiceMock(Organization.class);
  EasyMock.expect(securityService.getOrganization()).andReturn(organization).anyTimes();
  EasyMock.expect(organization.getId()).andReturn("mh_default_org").anyTimes();
  EasyMock.replay(organization);
  EasyMock.replay(securityService);
  ListProvidersServiceImpl listProvidersService = new ListProvidersServiceImpl();
  SimpleSerializer serializer = new SimpleSerializer();
  listProvidersService.setSecurityService(securityService);
  final Map<String, String> license = new HashMap<String, String>();
  license.put("contributor1", "My first contributor");
  license.put("contributor2", "My second contributor");
  license.put("contributor3", "My third contributor");
  // Create test list provider
  listProvidersService.addProvider(ContributorsListProvider.DEFAULT, new ResourceListProvider() {
    @Override
    public String[] getListNames() {
      return new String[] { ContributorsListProvider.DEFAULT };
    }
    @Override
    public Map<String, String> getList(String listName, ResourceListQuery query)
            throws ListProviderException {
      return ListProviderUtil.filterMap(license, query);
    }
      @Override
      public boolean isTranslatable(String listName) {
        return false;
      }
    @Override
    public String getDefault() {
      return null;
    }
  }, organization.getId());
  // Prepare mock query
  List<ResourceListFilter<?>> filters = new ArrayList<ResourceListFilter<?>>();
  filters.add(SeriesListQuery.createContributorsFilter(Option.<String> none()));
  filters.add(new StringListFilter(""));
  ResourceListQueryImpl query = EasyMock.createNiceMock(ResourceListQueryImpl.class);
  EasyMock.expect(query.getAvailableFilters()).andReturn(filters).anyTimes();
  EasyMock.expect(query.getFilters()).andReturn(new ArrayList<ResourceListFilter<?>>()).anyTimes();
  EasyMock.expect(query.getLimit()).andReturn(Option.<Integer> none()).anyTimes();
  EasyMock.expect(query.getOffset()).andReturn(Option.<Integer> none()).anyTimes();
  EasyMock.replay(query);
  JValue result = JSONUtils.filtersToJSON(query, listProvidersService, organization);
  StreamingOutput stream = RestUtils.stream(serializer.fn.toJson(result));
  ByteArrayOutputStream resultStream = new ByteArrayOutputStream();
  try {
    stream.write(resultStream);
    assertThat(expectedJSON, SameJSONAs.sameJSONAs(resultStream.toString()));
  } finally {
    IOUtils.closeQuietly(resultStream);
  }
}