// Path: src/main/java/com/github/hermannpencole/nifi/config/model/ConfigException.java
// public class ConfigException extends RuntimeException {
//     public ConfigException(Throwable e) {
//         super(e);
//     }
// 
//     public ConfigException(String s, Throwable e) {
//         super(s,e);
//     }
// 
//     public ConfigException(String s) {
//         super(s);
//     }
// }
// 
// Path: src/main/java/com/github/hermannpencole/nifi/config/model/TimeoutException.java
// public class TimeoutException extends RuntimeException {
//     public TimeoutException(Throwable e) {
//         super(e);
//     }
// 
//     public TimeoutException(String s, Throwable e) {
//         super(s,e);
//     }
// 
//     public TimeoutException(String s) {
//         super(s);
//     }
// }
// 
// Path: src/main/java/com/github/hermannpencole/nifi/config/utils/FunctionUtils.java
// public final class FunctionUtils {
//     /**
//      * The logger.
//      */
//     private final static Logger LOG = LoggerFactory.getLogger(FunctionUtils.class);
// 
//     private FunctionUtils() { }
// 
//     public static void runTimeout(Runnable function, int timeout) {
//         java.util.concurrent.ExecutorService executor = Executors.newSingleThreadExecutor();
//         final Future future = executor.submit(function);
//         try {
//             if (timeout < 0 ) {
//                 future.get();
//             } else {
//                 future.get(timeout, TimeUnit.SECONDS);
//             }
//         } catch (ExecutionException e) {
//             LOG.debug(e.getMessage(),e);
//             future.cancel(true);
//             if (e.getCause() instanceof ConfigException) {
//                 throw (ConfigException)e.getCause();
//             }
//             throw new ConfigException(e.getCause());
//         } catch (InterruptedException e) {
//             future.cancel(true);
//             throw new ConfigException(e);
//         } catch (java.util.concurrent.TimeoutException e) {
//             future.cancel(true);
//             throw new TimeoutException(e);
//         } finally {
//             executor.shutdownNow();
//         }
// 
//     }
// 
//     public static void runWhile(Supplier<Boolean> function, int interval) {
//        while (function.get()) {
//            try {
//                //interval are in second
//                Thread.sleep(interval * 1000);
//            } catch (InterruptedException e) {
//                throw new ConfigException(e);
//            }
//        }
//     }
// 
//     public static void runWhile(Supplier<Boolean> function, int interval, int timeout) {
//         runTimeout(() -> runWhile(function, interval ), timeout);
//     }
// 
//     public static Optional<ProcessGroupEntity> findByComponentName(List<ProcessGroupEntity> listGroup, String name) {
//         return listGroup.stream()
//                 .filter(item -> item.getComponent() != null && item.getComponent().getName().trim().equals(name.trim()))
//                 .findFirst();
//     }
// }


import com.github.hermannpencole.nifi.config.model.ConfigException;
import com.github.hermannpencole.nifi.config.model.TimeoutException;
import com.github.hermannpencole.nifi.config.utils.FunctionUtils;
import com.github.hermannpencole.nifi.swagger.ApiException;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.runners.MockitoJUnitRunner;
import java.io.IOException;
import java.net.URISyntaxException;
import static org.junit.Assert.assertEquals;
package com.github.hermannpencole.nifi.utils;




/**
 * API tests for AccessApi
 */
@RunWith(MockitoJUnitRunner.class)
public class FunctionUtilsTest {

    private int result = 0;

    @Test(expected = TimeoutException.class)
    public void runWhileTimeOutTest() throws ApiException, IOException, URISyntaxException {
        FunctionUtils.runWhile(() -> true, 1, 1);
    }

    @Test
    public void runWhileTest() throws ApiException, IOException, URISyntaxException {
        this.result = 0;
        FunctionUtils.runWhile(() -> {this.result +=1; return this.result != 2;}, 1, 10);
        assertEquals(2, this.result);
    }

    @Test(expected = ConfigException.class)
    public void runWhileExceptionTest() throws ApiException, IOException, URISyntaxException {
        this.result = 0;
        FunctionUtils.runWhile(() -> { throw new IndexOutOfBoundsException();}, 1, -1);
        assertEquals(2, this.result);
    }

// Path: src/main/java/com/github/hermannpencole/nifi/config/model/ConfigException.java
// public class ConfigException extends RuntimeException {
//     public ConfigException(Throwable e) {
//         super(e);
//     }
// 
//     public ConfigException(String s, Throwable e) {
//         super(s,e);
//     }
// 
//     public ConfigException(String s) {
//         super(s);
//     }
// }
// 
// Path: src/main/java/com/github/hermannpencole/nifi/config/model/TimeoutException.java
// public class TimeoutException extends RuntimeException {
//     public TimeoutException(Throwable e) {
//         super(e);
//     }
// 
//     public TimeoutException(String s, Throwable e) {
//         super(s,e);
//     }
// 
//     public TimeoutException(String s) {
//         super(s);
//     }
// }
// 
// Path: src/main/java/com/github/hermannpencole/nifi/config/utils/FunctionUtils.java
// public final class FunctionUtils {
//     /**
//      * The logger.
//      */
//     private final static Logger LOG = LoggerFactory.getLogger(FunctionUtils.class);
// 
//     private FunctionUtils() { }
// 
//     public static void runTimeout(Runnable function, int timeout) {
//         java.util.concurrent.ExecutorService executor = Executors.newSingleThreadExecutor();
//         final Future future = executor.submit(function);
//         try {
//             if (timeout < 0 ) {
//                 future.get();
//             } else {
//                 future.get(timeout, TimeUnit.SECONDS);
//             }
//         } catch (ExecutionException e) {
//             LOG.debug(e.getMessage(),e);
//             future.cancel(true);
//             if (e.getCause() instanceof ConfigException) {
//                 throw (ConfigException)e.getCause();
//             }
//             throw new ConfigException(e.getCause());
//         } catch (InterruptedException e) {
//             future.cancel(true);
//             throw new ConfigException(e);
//         } catch (java.util.concurrent.TimeoutException e) {
//             future.cancel(true);
//             throw new TimeoutException(e);
//         } finally {
//             executor.shutdownNow();
//         }
// 
//     }
// 
//     public static void runWhile(Supplier<Boolean> function, int interval) {
//        while (function.get()) {
//            try {
//                //interval are in second
//                Thread.sleep(interval * 1000);
//            } catch (InterruptedException e) {
//                throw new ConfigException(e);
//            }
//        }
//     }
// 
//     public static void runWhile(Supplier<Boolean> function, int interval, int timeout) {
//         runTimeout(() -> runWhile(function, interval ), timeout);
//     }
// 
//     public static Optional<ProcessGroupEntity> findByComponentName(List<ProcessGroupEntity> listGroup, String name) {
//         return listGroup.stream()
//                 .filter(item -> item.getComponent() != null && item.getComponent().getName().trim().equals(name.trim()))
//                 .findFirst();
//     }
// }


// Path: src/test/java/com/github/hermannpencole/nifi/utils/FunctionUtilsTest.java
import com.github.hermannpencole.nifi.config.model.ConfigException;
import com.github.hermannpencole.nifi.config.model.TimeoutException;
import com.github.hermannpencole.nifi.config.utils.FunctionUtils;
import com.github.hermannpencole.nifi.swagger.ApiException;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.runners.MockitoJUnitRunner;
import java.io.IOException;
import java.net.URISyntaxException;
import static org.junit.Assert.assertEquals;

package com.github.hermannpencole.nifi.utils;




/**
 * API tests for AccessApi
 */
@RunWith(MockitoJUnitRunner.class)
public class FunctionUtilsTest {

    private int result = 0;

    @Test(expected = TimeoutException.class)
    public void runWhileTimeOutTest() throws ApiException, IOException, URISyntaxException {
        FunctionUtils.runWhile(() -> true, 1, 1);
    }

    @Test
    public void runWhileTest() throws ApiException, IOException, URISyntaxException {
        this.result = 0;
        FunctionUtils.runWhile(() -> {this.result +=1; return this.result != 2;}, 1, 10);
        assertEquals(2, this.result);
    }

    @Test(expected = ConfigException.class)
    public void runWhileExceptionTest() throws ApiException, IOException, URISyntaxException {
        this.result = 0;
        FunctionUtils.runWhile(() -> { throw new IndexOutOfBoundsException();}, 1, -1);
        assertEquals(2, this.result);
    }

    @Test(expected = ConfigException.class)