/*
 * See the NOTICE file distributed with this work for additional
 * information regarding copyright ownership.
 *
 * This is free software; you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License as
 * published by the Free Software Foundation; either version 2.1 of
 * the License, or (at your option) any later version.
 *
 * This software is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this software; if not, write to the Free
 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
 */
package org.xwiki.mentions.internal.listeners;

import org.junit.jupiter.api.Test;
import org.xwiki.mentions.internal.MentionsEventExecutor;
import org.xwiki.test.junit5.mockito.ComponentTest;
import org.xwiki.test.junit5.mockito.InjectMockComponents;
import org.xwiki.test.junit5.mockito.MockComponent;

import static org.mockito.Mockito.verify;

/**
 * Test of {@link MentionsApplicationReadyEventListener}.
 *
 * @version $Id$
 * @since 12.6RC1
 */
@ComponentTest
class MentionsApplicationReadyEventListenerTest
{
    @InjectMockComponents
    private MentionsApplicationReadyEventListener eventListener;

    @MockComponent
    private MentionsEventExecutor eventExecutor;

    @Test
    void onEvent()
    {
        this.eventListener.onEvent(null, null, null);
        verify(this.eventExecutor).startThreads();
    }
}

@@ -935,16 +935,74 @@
 eners;%0A%0A
+import javax.inject.Named;%0Aimport javax.inject.Provider;%0A%0A
 import o
@@ -1086,16 +1086,66 @@
 ecutor;%0A
+import org.xwiki.test.annotation.BeforeComponent;%0A
 import o
@@ -1300,16 +1300,133 @@
 onent;%0A%0A
+import com.xpn.xwiki.XWikiContext;%0A%0Aimport static org.mockito.Mockito.mock;%0Aimport static org.mockito.Mockito.times;%0A
 import s
@@ -1458,16 +1458,56 @@
 .verify;
+%0Aimport static org.mockito.Mockito.when;
 %0A%0A/**%0A *
@@ -1788,142 +1788,759 @@
     
-private MentionsEventExecutor eventExecutor;%0A%0A    @Test%0A    void onEvent()%0A    %7B%0A        this.eventListener.onEvent(null, null, null);
+@Named(%22readonly%22)%0A    private Provider%3CXWikiContext%3E contextProvider;%0A%0A    @MockComponent%0A    private MentionsEventExecutor eventExecutor;%0A%0A    @BeforeComponent(%22onEvent%22)%0A    void beforeOnEvent()%0A    %7B%0A        // Ensure that the context is not mocked for the onEvent test so that startThreads is not called during%0A        // initialize method.%0A        when(this.contextProvider.get()).thenReturn(null);%0A    %7D%0A%0A    @Test%0A    void onEvent()%0A    %7B%0A        this.eventListener.onEvent(null, null, null);%0A        verify(this.eventExecutor).startThreads();%0A    %7D%0A%0A    @BeforeComponent(%22initialize%22)%0A    void beforeInitialize()%0A    %7B%0A        when(this.contextProvider.get()).thenReturn(mock(XWikiContext.class));%0A    %7D%0A%0A    @Test%0A    void initialize()%0A    %7B
 %0A   

Replace Jobs with threads to handle mentions asynchronously