package de.skuzzle.jeve;

import java.util.Arrays;
import java.util.Collection;
import java.util.concurrent.ExecutorService;
import java.util.function.Supplier;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameters;
import org.mockito.Mockito;

import de.skuzzle.jeve.providers.ExecutorAware;
import de.skuzzle.jeve.stores.DefaultListenerStore;
import de.skuzzle.jeve.util.StringEvent;
import de.skuzzle.jeve.util.StringListener;

/**
 * Runs all basic tests for all default provided event providers.
 *
 * @author Simon Taddiken
 */
@RunWith(Parameterized.class)
public class ThreadedEventProviderIT extends
        EventProviderTestBase<DefaultListenerStore> {

    /**
     * Parameterizes the test instances.
     *
     * @return Collection of parameters for the constructor of
     *         {@link EventProviderTestBase}.
     */
    @Parameters
    public static final Collection<Object[]> getParameters() {
        return Arrays.asList(
                new Object[] { EventProvider.configure().store(DefaultListenerStore.create().synchronizedView()).useParallelProvider().createSupplier() },
                new Object[] { EventProvider.configure().store(DefaultListenerStore.create().synchronizedView()).useAsynchronousProvider().createSupplier() },
                new Object[] { EventProvider.configure().store(DefaultListenerStore.create().synchronizedView()).useParallelProvider().and().statistics().createSupplier() },
                new Object[] { EventProvider.configure().store(DefaultListenerStore.create().synchronizedView()).useAsynchronousProvider().and().statistics().createSupplier() }
                );
    }

    /**
     * Creates new BasicEventProviderTests
     *
     * @param factory Factory to create a single provider
     */
    public ThreadedEventProviderIT(
            Supplier<? extends EventProvider<DefaultListenerStore>> factory) {
        super(factory);
    }

    @Test(expected = IllegalArgumentException.class)
    public void setThreadPoolNull() {
        if (this.subject instanceof ExecutorAware) {
            final ExecutorAware ea = (ExecutorAware) this.subject;
            ea.setExecutorService(null);
        }
        throw new IllegalArgumentException();
    }

    @Test
    public void testSetExecutor() {
        if (this.subject instanceof ExecutorAware) {
            final ExecutorAware ea = (ExecutorAware) this.subject;
            final ExecutorService executor = Mockito.mock(ExecutorService.class);
            ea.setExecutorService(executor);
            final StringListener listener = Mockito.mock(StringListener.class);
            this.subject.listeners().add(StringListener.class, listener);

            this.subject.dispatch(new StringEvent(this.subject, ""),
                    StringListener::onStringEvent);

            Mockito.verify(executor).execute(Mockito.any());
        }
    }
}

@@ -155,16 +155,41 @@
 plier;%0A%0A
+import org.junit.Assume;%0A
 import o
@@ -2109,35 +2109,49 @@
 ull() %7B%0A        
-if 
+Assume.assumeTrue
 (this.subject in
@@ -2165,34 +2165,33 @@
 f ExecutorAware)
- %7B
+;
 %0A            fin
@@ -2287,64 +2287,8 @@
 l);%0A
-        %7D%0A        throw new IllegalArgumentException();%0A
     
@@ -2348,11 +2348,25 @@
     
-if 
+Assume.assumeTrue
 (thi
@@ -2400,23 +2400,18 @@
 orAware)
- %7B%0A    
+;%0A
         
@@ -2457,36 +2457,32 @@
 ) this.subject;%0A
-    
         final Ex
@@ -2535,36 +2535,32 @@
 Service.class);%0A
-    
         ea.setEx
@@ -2588,28 +2588,24 @@
 r);%0A        
-    
 final String
@@ -2656,28 +2656,24 @@
 ner.class);%0A
-    
         this
@@ -2735,28 +2735,24 @@
 );%0A%0A        
-    
 this.subject
@@ -2812,20 +2812,16 @@
         
-   
- 
 StringLi
@@ -2841,28 +2841,24 @@
 ingEvent);%0A%0A
-    
         Mock
@@ -2906,18 +2906,8 @@
 ));%0A
-        %7D%0A
     

Add assumptions