
package com.speedment.runtime.core.internal.stream.parallel;

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import static org.junit.jupiter.api.Assertions.*;


/**
 *
 * @author pemi
 */
final class SingletonSpliteratorTest extends BaseSpliteratorTest {

    private static final int VALUE = 43;

    @BeforeEach
    void setUp() {
        instance = new SingletonSpliterator<>(VALUE, 0);
    }

    @Test
    void testTrySplit() {
        printTestName();
        assertNull(instance.trySplit());
    }

    @Test
    void testForEachRemaining() {
        printTestName();
        final List<Integer> expected = Collections.singletonList(VALUE);
        final List<Integer> list = new ArrayList<>();
        instance.forEachRemaining(list::add);
        assertEquals(expected, list);
        instance.forEachRemaining(list::add);
        assertEquals(expected, list);
    }

    @Test
    void testTryAdvance() {
        printTestName();
        assertTrue(instance.tryAdvance(DO_NOTHING));
        assertFalse(instance.tryAdvance(DO_NOTHING));
    }

    @Test
    void testEstimateSize() {
        printTestName();
        assertEquals(1, instance.estimateSize());
        instance.tryAdvance(DO_NOTHING);
        assertEquals(0, instance.estimateSize());
        instance.tryAdvance(DO_NOTHING);
        assertEquals(0, instance.estimateSize());
    }

}
