@Test
  public void testInitMissingParam() {
    MockControl mockRendererComponentFactoryDescriptorControl =
        MockClassControl.createControl(RendererComponentFactoryDescriptor.class);
    RendererComponentFactoryDescriptor mockRendererComponentFactoryDescriptor =
        (RendererComponentFactoryDescriptor)
            mockRendererComponentFactoryDescriptorControl.getMock();
    mockRendererComponentFactoryDescriptor.getPlugin();
    mockRendererComponentFactoryDescriptorControl.setReturnValue(null);
    mockRendererComponentFactoryDescriptor.getParams();
    mockRendererComponentFactoryDescriptorControl.setReturnValue(new HashMap());
    mockRendererComponentFactoryDescriptor.getCompleteKey();
    mockRendererComponentFactoryDescriptorControl.setReturnValue("pluginkey");
    mockRendererComponentFactoryDescriptorControl.replay();

    SimpleRendererComponentFactory simpleRendererComponentFactory =
        new SimpleRendererComponentFactory();
    try {
      simpleRendererComponentFactory.init(mockRendererComponentFactoryDescriptor);
      fail("Expected exception");
    } catch (PluginParseException e) {
      assertTrue(e.getMessage().indexOf("is missing the required") > 0);
      assertTrue(e.getMessage().indexOf("pluginkey") > 0);
    }
  }
  @Test
  public void testGetModifications() throws ModzRegistryException {
    Modifications mods = new Modifications();

    final MockControl mockModzDetectorControl = MockClassControl.createControl(ModzDetector.class);
    final ModzDetector mockModzDetector = (ModzDetector) mockModzDetectorControl.getMock();
    mockModzDetector.getModifiedFiles();
    mockModzDetectorControl.setDefaultReturnValue(mods);

    mockModzDetectorControl.replay();
    HashRegistryCacheImpl registry =
        new HashRegistryCacheImpl(mockModzDetector, new SoftReference(null));

    assertSame(mods, registry.getModifications());
  }
  @Test
  public void testInitInvalidClass() {
    MockControl mockRendererComponentFactoryDescriptorControl =
        MockClassControl.createControl(RendererComponentFactoryDescriptor.class);
    RendererComponentFactoryDescriptor mockRendererComponentFactoryDescriptor =
        (RendererComponentFactoryDescriptor)
            mockRendererComponentFactoryDescriptorControl.getMock();
    Mock mockPlugin = new Mock(Plugin.class);

    mockRendererComponentFactoryDescriptor.getPlugin();
    mockRendererComponentFactoryDescriptorControl.setReturnValue(null);
    Map params = new HashMap();
    params.put("rendererComponentClass", "com.test.invalid.class");
    mockRendererComponentFactoryDescriptor.getParams();
    mockRendererComponentFactoryDescriptorControl.setReturnValue(params);
    mockRendererComponentFactoryDescriptor.getCompleteKey();
    mockRendererComponentFactoryDescriptorControl.setReturnValue("pluginkey");
    mockRendererComponentFactoryDescriptor.getPlugin();
    mockRendererComponentFactoryDescriptorControl.setReturnValue(mockPlugin.proxy());
    mockPlugin.expectAndThrow(
        "loadClass",
        new Constraint[] {new IsEqual("com.test.invalid.class"), new IsAnything()},
        new ClassNotFoundException());
    mockRendererComponentFactoryDescriptorControl.replay();

    SimpleRendererComponentFactory simpleRendererComponentFactory =
        new SimpleRendererComponentFactory() {
          RendererComponent loadRendererComponent(Class rendererComponentClass)
              throws ClassNotFoundException {
            throw new ClassNotFoundException();
          }
        };

    try {
      simpleRendererComponentFactory.init(mockRendererComponentFactoryDescriptor);
      fail("Expected exception");
    } catch (PluginParseException e) {
      assertTrue(e.getMessage().indexOf("Could not load renderer") >= 0);
      assertTrue(e.getMessage().indexOf("pluginkey") > 0);
      assertTrue(e.getMessage().indexOf("com.test.invalid.class") > 0);
    }
  }
  @Test
  public void testDoRelevantClausesFitDelegates() throws Exception {
    final boolean theResult = false;
    final Query query = null;

    final MockControl mockNavigatorStructureCheckerControl =
        MockClassControl.createControl(NavigatorStructureChecker.class);
    final NavigatorStructureChecker mockNavigatorStructureChecker =
        (NavigatorStructureChecker) mockNavigatorStructureCheckerControl.getMock();
    mockNavigatorStructureChecker.checkSearchRequest(query, searchContext);
    mockNavigatorStructureCheckerControl.setReturnValue(theResult);
    mockNavigatorStructureCheckerControl.replay();

    @SuppressWarnings({"unchecked"})
    final VersionCustomFieldSearchInputTransformer transformer =
        new VersionCustomFieldSearchInputTransformer(
            "clauseName",
            new ClauseNames("clauseName"),
            mockController.getMock(CustomField.class),
            mockController.getMock(VersionIndexInfoResolver.class),
            mockController.getMock(JqlOperandResolver.class),
            mockController.getMock(FieldFlagOperandRegistry.class),
            searchContextVisibilityChecker,
            versionResolver,
            customFieldInputHelper,
            versionManager) {
          @Override
          NavigatorStructureChecker createNavigatorStructureChecker() {
            return mockNavigatorStructureChecker;
          }
        };

    mockController.replay();

    assertEquals(theResult, transformer.doRelevantClausesFitFilterForm(null, query, searchContext));
    mockNavigatorStructureCheckerControl.verify();
    mockController.verify();
  }
  @Test
  public void testInitSuccessful() throws PluginParseException {
    MockControl mockRendererComponentFactoryDescriptorControl =
        MockClassControl.createControl(RendererComponentFactoryDescriptor.class);
    RendererComponentFactoryDescriptor mockRendererComponentFactoryDescriptor =
        (RendererComponentFactoryDescriptor)
            mockRendererComponentFactoryDescriptorControl.getMock();
    Mock mockPlugin = new Mock(Plugin.class);

    final Mock mockRendererComponent = new Mock(RendererComponent.class);
    final RendererComponent originalRendererComponent =
        (RendererComponent) mockRendererComponent.proxy();
    mockRendererComponentFactoryDescriptor.getPlugin();
    mockRendererComponentFactoryDescriptorControl.setReturnValue(null);
    Map params = new HashMap();
    params.put("rendererComponentClass", "java.lang.String");
    mockRendererComponentFactoryDescriptor.getParams();
    mockRendererComponentFactoryDescriptorControl.setReturnValue(params);
    mockRendererComponentFactoryDescriptor.getCompleteKey();
    mockRendererComponentFactoryDescriptorControl.setReturnValue("pluginkey");
    mockRendererComponentFactoryDescriptor.getPlugin();
    mockRendererComponentFactoryDescriptorControl.setReturnValue(mockPlugin.proxy());
    mockRendererComponentFactoryDescriptorControl.replay();

    SimpleRendererComponentFactory simpleRendererComponentFactory =
        new SimpleRendererComponentFactory() {
          RendererComponent loadRendererComponent(Class rendererComponentClass)
              throws ClassNotFoundException {
            return originalRendererComponent;
          }
        };

    simpleRendererComponentFactory.init(mockRendererComponentFactoryDescriptor);
    RendererComponent rendererComponent = simpleRendererComponentFactory.getRendererComponent();
    assertNotNull(rendererComponent);
    assertEquals(originalRendererComponent, rendererComponent);
  }
  /**
   * Test that the manager executes the correct search to find the recent comments.
   *
   * @param issueIds the issue ids to limit the comment search by.
   * @param request the search request being used to find the comments. This is the request that is
   *     normally used to find all the issue ids to form the scope of the comment search. The
   *     request may also be used to add extra "update date" criteria to the comment search.
   * @param user the user performing the search.
   * @param includeDates true if and only if the passed search request should be used to create
   *     extra "update date" criteria.
   * @param expectedQuery the query that we expect to be generated by the manager.
   * @throws Exception this is a test, just rethrow for a failure.
   */
  private void _testGetRecentComments(
      final List<Long> issueIds,
      final SearchRequest request,
      final User user,
      final boolean includeDates,
      final org.apache.lucene.search.Query expectedQuery)
      throws Exception {
    // the issue searcher is never called, but we need it there.
    final MockControl mockIssueSearcherControl =
        MockClassControl.createControl(IndexSearcher.class);
    final IndexSearcher mockIssueSearcher = (IndexSearcher) mockIssueSearcherControl.getMock();
    mockIssueSearcherControl.replay();

    // this is where we check to make sure search lucene with the correct comment.
    final MockControl mockCommentSearcherControl =
        MockClassControl.createControl(IndexSearcher.class);
    final IndexSearcher mockCommentSearcher = (IndexSearcher) mockCommentSearcherControl.getMock();

    final Sort sort =
        new Sort(
            new SortField[] {
              new SortField(DocumentConstants.COMMENT_UPDATED, SortField.STRING, true)
            });
    final ArgumentsMatcher compositeArgumentsMatcher =
        ArgumentsMatcherBuilder.newNaturalBuilder()
            .addDefaultMatcher()
            .addDefaultMatcher()
            .addArgumentMatcher(Sort.class, new LuceneSortMatcher())
            .asArgumentsMatcher();

    mockCommentSearcher.search(expectedQuery, Integer.MAX_VALUE, sort);
    mockCommentSearcherControl.setMatcher(compositeArgumentsMatcher);
    mockCommentSearcherControl.setReturnValue(null);
    mockCommentSearcherControl.replay();

    final MockSearchProviderFactory factory = new MockSearchProviderFactory();
    factory.addRegistration(SearchProviderFactory.ISSUE_INDEX, mockIssueSearcher);
    factory.addRegistration(SearchProviderFactory.COMMENT_INDEX, mockCommentSearcher);

    // create a IssueSearchProvider that will return our constant list of ids.
    MockIssueSearchProvider mockIssueSearchProvider =
        new MockIssueSearchProvider(issueIds, user, request.getQuery());
    final SearchService service = EasyMock.createMock(SearchService.class);
    EasyMock.expect(service.doesQueryFitFilterForm(user, request.getQuery()))
        .andReturn(includeDates);
    EasyMock.replay(service);

    MyLuceneQueryModifier myLuceneQueryModifier = new MyLuceneQueryModifier();

    CommentService commentService = EasyMock.createMock(CommentService.class);
    JqlOperandResolver jqlOperandResolver = MockJqlOperandResolver.createSimpleSupport();
    final DefaultRecentCommentManager defaultCommentManager =
        new DefaultRecentCommentManager(
            commentService,
            factory,
            mockIssueSearchProvider,
            dateSupport,
            jqlOperandResolver,
            service,
            myLuceneQueryModifier);
    defaultCommentManager.getRecentComments(request, user);

    mockIssueSearcherControl.verify();
    mockCommentSearcherControl.verify();
  }