package com.github.onsdigital.perkin.transform;

import org.junit.Test;

import static org.hamcrest.core.Is.is;
import static org.junit.Assert.assertThat;

public class NumberServiceTest {

    private NumberService classUnderTest;

    @Test
    public void shouldStartAtCorrectNumber() {
        //Given
        classUnderTest = new NumberService("test", 5L, 10L);

        //When
        long start = classUnderTest.getNext();

        //Then
        assertThat(start, is(5L));
    }

    @Test
    public void shouldWrapAroundToStart() {
        //Given
        long start = 5L;
        classUnderTest = new NumberService("test", start, 10L);
        classUnderTest.reset();

        //When / Then
        for (int i = 0; i < 6; i++) {
            long sequence = classUnderTest.getNext();
            assertThat(sequence, is(start + i));
        }

        //Then
        long sequence = classUnderTest.getNext();
        assertThat(sequence, is(start));
    }
}

@@ -958,11 +958,653 @@
 );%0A    %7D
+%0A%0A    @Test%0A    public void shouldWrapAroundToStartWhenSaved() %7B%0A        //Given%0A        long start = 5L;%0A        classUnderTest = new NumberService(%22test%22, start, 10L);%0A        classUnderTest.reset();%0A%0A        //When / Then%0A        for (int i = 0; i %3C 6; i++) %7B%0A            // Re-initialise (and re-load) on every increment:%0A            classUnderTest = new NumberService(%22test%22, start, 10L);%0A            long sequence = classUnderTest.getNext();%0A            assertThat(sequence, is(start + i));%0A        %7D%0A%0A        //Then%0A        long sequence = new NumberService(%22test%22, start, 10L).getNext();%0A        assertThat(sequence, is(start));%0A    %7D
 %0A%7D%0A

Test for looping a sequence when the value is saved on every increment.