@Test
  public void testGetSearchClauseOneProjectIsFlag() throws Exception {
    final CustomFieldParamsImpl customFieldParams = new CustomFieldParamsImpl();
    customFieldParams.addValue(Collections.singleton("123"));
    final Map<String, Object> map =
        MapBuilder.<String, Object>newBuilder()
            .add(urlParameterName, customFieldParams)
            .add(
                SystemSearchConstants.forProject().getUrlParameter(),
                Collections.singletonList("-1"))
            .toMap();
    FieldValuesHolder values = new FieldValuesHolderImpl(map);
    final AtomicBoolean specialCalled = new AtomicBoolean(false);

    final IndexedInputHelper helper =
        new DefaultIndexedInputHelper<Version>(
            indexInfoResolver,
            operandResolver,
            fieldFlagOperandRegistry,
            searchContextVisibilityChecker) {
          @Override
          public Clause getClauseForNavigatorValues(final String clauseName, final Set values) {
            return null;
          }
        };

    transformer =
        new VersionCustomFieldSearchInputTransformer(
            urlParameterName,
            clauseNames,
            customField,
            indexInfoResolver,
            operandResolver,
            fieldFlagOperandRegistry,
            searchContextVisibilityChecker,
            versionResolver,
            customFieldInputHelper,
            versionManager) {
          @Override
          protected DefaultIndexedInputHelper getDefaultIndexedInputHelper() {
            throw new UnsupportedOperationException(
                "Should not have called through to the special indexed input helper");
          }

          @Override
          protected IndexedInputHelper getIndexedInputHelper() {
            specialCalled.set(true);
            return helper;
          }

          @Override
          protected String getClauseName(final User searcher, final ClauseNames clauseNames) {
            return primaryClauseName;
          }
        };
    replay();

    transformer.getSearchClause(theUser, values);
    assertTrue(specialCalled.get());
  }
  @Test
  public void testGetClauseFromParamsValuesGetFiltered() throws Exception {
    final String clauseName = "clauseName";

    final CustomField customField = mockController.getMock(CustomField.class);
    EasyMock.expect(customField.getName()).andStubReturn("ABC");
    EasyMock.expect(customFieldInputHelper.getUniqueClauseName(theUser, clauseName, "ABC"))
        .andStubReturn(clauseName);

    final CustomFieldParamsImpl customFieldParams = new CustomFieldParamsImpl();
    customFieldParams.addValue(CollectionBuilder.newBuilder("55", "-1", "").asMutableSet());

    final Set<String> expectedFilteredValues = CollectionBuilder.newBuilder("55").asMutableSet();

    final Clause expectedClause = mockController.getMock(Clause.class);

    final IndexedInputHelper indexedInputHelper = mockController.getMock(IndexedInputHelper.class);
    indexedInputHelper.getClauseForNavigatorValues(clauseName, expectedFilteredValues);
    mockController.setReturnValue(expectedClause);

    transformer =
        new VersionCustomFieldSearchInputTransformer(
            clauseName,
            new ClauseNames(clauseName),
            customField,
            indexInfoResolver,
            operandResolver,
            fieldFlagOperandRegistry,
            searchContextVisibilityChecker,
            versionResolver,
            customFieldInputHelper,
            versionManager) {
          @Override
          IndexedInputHelper getIndexedInputHelper() {
            return indexedInputHelper;
          }

          @Override
          boolean isVersionsNotRelatedToProjects(
              final Set<String> versionIdsFromHolder, final FieldValuesHolder fieldValuesHolder) {
            return false;
          }
        };

    mockController.replay();

    FieldValuesHolder holderValues =
        new FieldValuesHolderImpl(MapBuilder.singletonMap(urlParameterName, customFieldParams));
    assertEquals(
        expectedClause, transformer.getClauseFromParams(theUser, customFieldParams, holderValues));

    mockController.verify();
  }
  @Test
  public void testGetSearchClauseValuesPresentParamsNotEmpty() throws Exception {
    final String searcherId = "searcherId";
    final String clauseName = "clauseName";

    final CustomFieldParamsImpl customFieldParams = new CustomFieldParamsImpl();
    customFieldParams.addValue(Collections.singleton("dontcare"));

    final FieldValuesHolderImpl valuesHolder = new FieldValuesHolderImpl();
    valuesHolder.put(searcherId, customFieldParams);

    final AtomicBoolean wasCalled = new AtomicBoolean(false);
    final Clause expectedClause = new TerminalClauseImpl(clauseName, Operator.EQUALS, "blah");

    final VersionCustomFieldSearchInputTransformer transformer =
        new VersionCustomFieldSearchInputTransformer(
            searcherId,
            new ClauseNames(clauseName),
            mockController.getMock(CustomField.class),
            mockController.getMock(VersionIndexInfoResolver.class),
            mockController.getMock(JqlOperandResolver.class),
            mockController.getMock(FieldFlagOperandRegistry.class),
            searchContextVisibilityChecker,
            versionResolver,
            customFieldInputHelper,
            versionManager) {
          @Override
          protected Clause getClauseFromParams(
              final User searcher,
              final CustomFieldParams params,
              final FieldValuesHolder fieldValuesHolder) {
            wasCalled.set(true);
            return expectedClause;
          }
        };

    mockController.replay();

    assertEquals(expectedClause, transformer.getSearchClause(null, valuesHolder));
    assertTrue(wasCalled.get());

    mockController.verify();
  }