package com.github.mazzeb.gradle.autoversion;

import org.junit.Before;
import org.junit.Test;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;

import java.io.InputStream;
import java.io.PrintStream;

import static com.github.mazzeb.gradle.autoversion.Version.versionBuilder;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.core.Is.is;

public class InteractiveVersionReaderTest {

    @Mock
    InputStream inputStream;

    @Mock
    PrintStream printStream;

    @InjectMocks
    InteractiveVersionReader interactiveVersionReader;

    @Before
    public void setUp() throws Exception {
        MockitoAnnotations.initMocks(this);
    }

    @Test
    public void shouldParseVersionStringWithoutLabel() throws Exception {
        String string = "1.4.2";

        Version version = interactiveVersionReader.parseVersion(string);

        assertThat(version, is(versionBuilder()
                .withMajor(1L)
                .withMinor(4L)
                .withPatch(2L)
                .build()));

    }

    @Test
    public void shouldParseVersionStringWithLabel() throws Exception {
        String string = "1.4.2-SNAPSHOT";

        Version version = interactiveVersionReader.parseVersion(string);

        assertThat(version, is(versionBuilder()
                .withMajor(1L)
                .withMinor(4L)
                .withPatch(2L)
                .withLabel("SNAPSHOT")
                .build()));

    }

    @Test
    public void shouldParseVersionStringWithLabelAndSomeRandomStuff() throws Exception {
        String string = "1.4.2-beta23.1-SNAPSHOT";

        Version version = interactiveVersionReader.parseVersion(string);

        assertThat(version, is(versionBuilder()
                .withMajor(1L)
                .withMinor(4L)
                .withPatch(2L)
                .withLabel("beta23.1-SNAPSHOT")
                .build()));

    }
}
@@ -111,85 +111,54 @@
 ito.
-InjectMocks;%0Aimport org.mockito.Mock;%0Aimport org.mockito.MockitoAnnotations;%0A
+Mockito;%0A%0Aimport java.io.ByteArrayInputStream;
 %0Aimp
@@ -211,16 +211,118 @@
 tream;%0A%0A
+import static com.github.mazzeb.gradle.autoversion.InteractiveVersionReader.interactiveVersionReader;%0A
 import s
@@ -479,16 +479,186 @@
 e.Is.is;
+%0Aimport static org.mockito.ArgumentMatchers.eq;%0Aimport static org.mockito.Mockito.mock;%0Aimport static org.mockito.Mockito.times;%0Aimport static org.mockito.Mockito.verify;
 %0A%0Apublic
@@ -696,26 +696,16 @@
 Test %7B%0A%0A
-    @Mock%0A
     Inpu
@@ -728,19 +728,8 @@
 eam;
-%0A%0A    @Mock
 %0A   
@@ -757,26 +757,8 @@
 eam;
-%0A%0A    @InjectMocks
 %0A   
@@ -877,41 +877,208 @@
     
-MockitoAnnotations.initMocks(this
+inputStream = new ByteArrayInputStream(%221.4.2-SNAPSHOT%22.getBytes());%0A        printStream = mock(PrintStream.class);%0A        interactiveVersionReader = interactiveVersionReader(inputStream, printStream
 );%0A 
@@ -1957,32 +1957,33 @@
 ows Exception %7B%0A
+%0A
         String s
@@ -2300,25 +2300,484 @@
      .build()));
+%0A    %7D%0A%0A    @Test%0A    public void shouldReadVersion() throws Exception %7B%0A        String prompt = %22please enter version%22;%0A%0A        Version version = interactiveVersionReader.readVersion(prompt);%0A%0A        verify(printStream, times(1)).print(eq(prompt));%0A        assertThat(version, is(versionBuilder()%0A                .withMajor(1L)%0A                .withMinor(4L)%0A                .withPatch(2L)%0A                .withLabel(%22SNAPSHOT%22)%0A                .build()));
 %0A%0A    %7D%0A%7D

implement version commandline scanner