// Path: src/test/java/com/github/havarunner/TestHelper.java
// public static <T> void addHundredTimes(T item, List<T> items) throws InterruptedException {
//     for (int i = 0; i < 100; i++) {
//         Thread.sleep(1); // Sleep to increase chances of context switching
//         items.add(item);
//     }
// }
// 
// Path: src/test/java/com/github/havarunner/TestHelper.java
// public static void assertAllEqual(int expected, List<Integer> integers) {
//     assertTrue(allEqual(expected, integers));
// }
// 
// Path: src/test/java/com/github/havarunner/TestHelper.java
// public static void run(HavaRunner havaRunner, RunNotifier runNotifier) {
//     havaRunner.run(runNotifier);
// }


import com.github.havarunner.ConcurrencyControl;
import com.github.havarunner.HavaRunner;
import com.github.havarunner.TestAndParameters;
import com.github.havarunner.annotation.RunSequentially;
import com.github.havarunner.annotation.Scenarios;
import com.google.common.base.Predicate;
import com.google.common.collect.Collections2;
import com.google.common.collect.Iterables;
import com.google.common.collect.Lists;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.runners.Enclosed;
import org.junit.runner.RunWith;
import javax.annotation.Nullable;
import java.util.Collection;
import java.util.List;
import static com.github.havarunner.ConcurrencyControl.semaphore;
import static com.github.havarunner.TestHelper.addHundredTimes;
import static com.github.havarunner.TestHelper.assertAllEqual;
import static com.github.havarunner.TestHelper.run;
import static com.google.common.collect.Collections2.filter;
import static org.junit.Assert.*;
            });
        }
    }

    public static class when_there_is_only_one_test {
        static List<Integer> items = Lists.newArrayList();

        @BeforeClass
        public static void runTest() {
            run(new HavaRunner(SeqTest.class));
        }

        @Test
        public void HavaRunner_can_run_sequentially_only_tests_of_same_instance() {
            if (items.get(0).equals(1)) { // if-else, because we can't be sure of the order in which the test methods are run
                assertAllEqual(1, items.subList(0, 100));
                assertAllEqual(2, items.subList(100, 200));
            } else {
                assertAllEqual(2, items.subList(0, 100));
                assertAllEqual(1, items.subList(100, 200));
            }
        }

        @RunSequentially(
            because = "this test doesn't thrive in the concurrent world",
            with = RunSequentially.SequentialityContext.TESTS_OF_SAME_INSTANCE
        )
        static class SeqTest {
            @Test
            void test1() throws InterruptedException {
// Path: src/test/java/com/github/havarunner/TestHelper.java
// public static <T> void addHundredTimes(T item, List<T> items) throws InterruptedException {
//     for (int i = 0; i < 100; i++) {
//         Thread.sleep(1); // Sleep to increase chances of context switching
//         items.add(item);
//     }
// }
// 
// Path: src/test/java/com/github/havarunner/TestHelper.java
// public static void assertAllEqual(int expected, List<Integer> integers) {
//     assertTrue(allEqual(expected, integers));
// }
// 
// Path: src/test/java/com/github/havarunner/TestHelper.java
// public static void run(HavaRunner havaRunner, RunNotifier runNotifier) {
//     havaRunner.run(runNotifier);
// }


// Path: src/test/java/com/github/havarunner/sequentiality/RunSequentiallyTestsOfSameInstance.java
import com.github.havarunner.ConcurrencyControl;
import com.github.havarunner.HavaRunner;
import com.github.havarunner.TestAndParameters;
import com.github.havarunner.annotation.RunSequentially;
import com.github.havarunner.annotation.Scenarios;
import com.google.common.base.Predicate;
import com.google.common.collect.Collections2;
import com.google.common.collect.Iterables;
import com.google.common.collect.Lists;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.runners.Enclosed;
import org.junit.runner.RunWith;
import javax.annotation.Nullable;
import java.util.Collection;
import java.util.List;
import static com.github.havarunner.ConcurrencyControl.semaphore;
import static com.github.havarunner.TestHelper.addHundredTimes;
import static com.github.havarunner.TestHelper.assertAllEqual;
import static com.github.havarunner.TestHelper.run;
import static com.google.common.collect.Collections2.filter;
import static org.junit.Assert.*;

            });
        }
    }

    public static class when_there_is_only_one_test {
        static List<Integer> items = Lists.newArrayList();

        @BeforeClass
        public static void runTest() {
            run(new HavaRunner(SeqTest.class));
        }

        @Test
        public void HavaRunner_can_run_sequentially_only_tests_of_same_instance() {
            if (items.get(0).equals(1)) { // if-else, because we can't be sure of the order in which the test methods are run
                assertAllEqual(1, items.subList(0, 100));
                assertAllEqual(2, items.subList(100, 200));
            } else {
                assertAllEqual(2, items.subList(0, 100));
                assertAllEqual(1, items.subList(100, 200));
            }
        }

        @RunSequentially(
            because = "this test doesn't thrive in the concurrent world",
            with = RunSequentially.SequentialityContext.TESTS_OF_SAME_INSTANCE
        )
        static class SeqTest {
            @Test
            void test1() throws InterruptedException {
                addHundredTimes(1, items);