<commit_before>package com.sbishyr.junit.easytools.runner;

import com.sbishyr.junit.easytools.model.annotation.DataProducer;
import com.sbishyr.junit.easytools.model.annotation.ProducedValue;
import com.sbishyr.junit.easytools.model.annotation.ProducedValues;
import org.junit.Test;
import org.junit.runner.JUnitCore;
import org.junit.runner.Result;
import org.junit.runner.RunWith;

import java.util.LinkedList;
import java.util.Queue;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.function.Supplier;

import static com.sbishyr.junit.easytools.utils.ResultAssertions.assertResultHasNoFailures;
import static org.assertj.core.api.Assertions.assertThat;

/**
 * @author by <NAME>
 */
public class JUnitDataProducerComplexTest {

    @RunWith(JUnitDataProducer.class)
    public static class ComplexProducerClass {

        //Not possible to use Result.getRunCount() because it counts unique method that has run.
        //But we need to check that the same method has run 3 times
        private static final AtomicInteger count = new AtomicInteger();

        private static final Queue<String> providedValues = new LinkedList<>();
        static {
            providedValues.add("firstString");
            providedValues.add("2String");
            providedValues.add("thirdOne");
        }

        //The copy the providedValues as long as we expect each value one by one to be provided
        private static final Queue<String> expectedValues = new LinkedList<>(providedValues);

        @DataProducer
        public static Supplier<String> stringSupplier = providedValues::poll;

        @Test
        @ProducedValues(iterations = 3)
        public void a(String s) {
            assertThat(s).isEqualTo(expectedValues.poll());
            count.getAndIncrement();
        }
    }

    @RunWith(JUnitDataProducer.class)
    public static class NamedDataProducer {

        @DataProducer
        public static Supplier<String> firstSupplier = () -> "firstSupplier";

        @DataProducer(name = "usedSupplier")
        public static Supplier<String> secondSupplier = () -> "secondSupplier";

        @Test
        public void a(@ProducedValue(producer = "usedSupplier") String s) {
            assertThat(s).isEqualTo("secondSupplier");
        }

        @Test
        public void b(@ProducedValue(producer = "firstSupplier") String s) {
            assertThat(s).isEqualTo("firstSupplier");
        }
    }

    @Test
    public void shouldSupportRepeatableTestsRun() throws Exception {
        Result result = JUnitCore.runClasses(ComplexProducerClass.class);
        assertThat(ComplexProducerClass.count.get()).isEqualTo(3);
        assertResultHasNoFailures(result);
    }

    @Test
    public void shouldProvideValueFromNamedProducer() throws Exception {
        Result result = JUnitCore.runClasses(NamedDataProducer.class);
        assertThat(result.getRunCount()).isEqualTo(2);
        assertResultHasNoFailures(result);
    }
}<commit_msg>Issue tests for issue #11<commit_after>package com.sbishyr.junit.easytools.runner;

import com.sbishyr.junit.easytools.model.annotation.DataProducer;
import com.sbishyr.junit.easytools.model.annotation.ProducedValue;
import com.sbishyr.junit.easytools.model.annotation.ProducedValues;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.JUnitCore;
import org.junit.runner.Result;
import org.junit.runner.RunWith;

import java.util.LinkedList;
import java.util.Queue;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.function.Supplier;

import static com.sbishyr.junit.easytools.utils.ResultAssertions.assertResultHasNoFailures;
import static org.assertj.core.api.Assertions.assertThat;

/**
 * @author by <NAME>
 */
public class JUnitDataProducerComplexTest {

    @RunWith(JUnitDataProducer.class)
    public static class ComplexProducerClass {

        //Not possible to use Result.getRunCount() because it counts unique method that has run.
        //But we need to check that the same method has run 3 times
        private static final AtomicInteger count = new AtomicInteger();

        private static final Queue<String> providedValues = new LinkedList<>();
        static {
            providedValues.add("firstString");
            providedValues.add("2String");
            providedValues.add("thirdOne");
        }

        //The copy the providedValues as long as we expect each value one by one to be provided
        private static final Queue<String> expectedValues = new LinkedList<>(providedValues);

        @DataProducer
        public static Supplier<String> stringSupplier = providedValues::poll;

        @Test
        @ProducedValues(iterations = 3)
        public void a(String s) {
            assertThat(s).isEqualTo(expectedValues.poll());
            count.getAndIncrement();
        }
    }

    @RunWith(JUnitDataProducer.class)
    public static class NamedDataProducer {

        @DataProducer
        public static Supplier<String> firstSupplier = () -> "firstSupplier";

        @DataProducer(name = "usedSupplier")
        public static Supplier<String> secondSupplier = () -> "secondSupplier";

        @Test
        public void a(@ProducedValue(producer = "usedSupplier") String s) {
            assertThat(s).isEqualTo("secondSupplier");
        }

        @Test
        public void b(@ProducedValue(producer = "firstSupplier") String s) {
            assertThat(s).isEqualTo("firstSupplier");
        }
    }

    @RunWith(JUnitDataProducer.class)
    public static class MultipleProducersOfTheSameType {

        //Not possible to use Result.getRunCount() because it counts unique method that has run.
        //But we need to check that the same method has run 2 times
        private static final AtomicInteger count = new AtomicInteger();

        @DataProducer
        public static Supplier<String> firstSupplier = () -> "firstSupplier";

        @DataProducer
        public static Supplier<String> secondSupplier = () -> "secondSupplier";

        private static final Queue<String> providedValues = new LinkedList<>();
        static {
            providedValues.add("firstSupplier");
            providedValues.add("secondSupplier");
        }

        @BeforeClass
        public static void setUpCounter() {
            count.set(0);
        }

        @Test
        public void a(String s) {
            assertThat(s).isEqualTo(providedValues.poll());
            count.incrementAndGet();
        }
    }

    @Test
    public void shouldSupportRepeatableTestsRun() throws Exception {
        Result result = JUnitCore.runClasses(ComplexProducerClass.class);
        assertThat(ComplexProducerClass.count.get()).isEqualTo(3);
        assertResultHasNoFailures(result);
    }

    @Test
    public void shouldProvideValueFromNamedProducer() throws Exception {
        Result result = JUnitCore.runClasses(NamedDataProducer.class);
        assertThat(result.getRunCount()).isEqualTo(2);
        assertResultHasNoFailures(result);
    }

    @Test
    public void shouldRunWithMultipleProvidersOfTheSameType() throws Exception {
        Result result = JUnitCore.runClasses(MultipleProducersOfTheSameType.class);
        assertResultHasNoFailures(result);
        assertThat(MultipleProducersOfTheSameType.count.intValue()).isEqualTo(2);
    }
}
{'fraction_non_alphanumeric': 0.09417714598141061, 'fraction_numerical': 0.002050300710770913, 'mean_word_length': 3.15266742338252, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 29, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7491260', 'n_tokens_mistral': 2006, 'n_tokens_neox': 1966, 'n_words': 450}