package benjamin.groehbiel.ch.shortener;

import com.fasterxml.jackson.databind.deser.DataFormatReaders;
import org.hamcrest.MatcherAssert;
import org.hamcrest.Matchers;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;

import java.net.URI;
import java.net.URISyntaxException;
import java.util.HashMap;
import java.util.Map;

import static org.hamcrest.CoreMatchers.equalTo;

public class UrlShortenerServiceTest {

    ShortenerService shortenerService;

    @Before
    public void before() {
        shortenerService = new ShortenerService();
    }

    @Test
    public void shouldGenerateAUniqueCodeForEachDistinctURI() throws URISyntaxException {
        URI inputUri = new URI("http://www.example.org");
        URI shortenedURI = shortenerService.shorten(inputUri);
        MatcherAssert.assertThat(shortenedURI.toString(), Matchers.equalTo("http://www.shortener.com/a"));
        URI anotherShortenedUri = new URI("http://www.example2.org");
        shortenedURI = shortenerService.shorten(anotherShortenedUri);
        MatcherAssert.assertThat(shortenedURI.toString(), Matchers.equalTo("http://www.shortener.com/b"));
    }

    @Test
    public void shouldReuseShortenedURIs() throws URISyntaxException {
        URI inputUri = new URI("http://www.example.org");

        URI shortenedURI = shortenerService.shorten(inputUri);

        MatcherAssert.assertThat(shortenedURI.toString(), Matchers.equalTo("http://www.shortener.com/a"));

        shortenedURI = shortenerService.shorten(inputUri);

        MatcherAssert.assertThat(shortenedURI.toString(), Matchers.equalTo("http://www.shortener.com/a"));
    }

    @Test
    public void shouldDecodeShortURIToOriginalURI() throws Exception {
        URI inputUri = new URI("http://www.example.org");
        URI shortenedURI = shortenerService.shorten(inputUri);

        URI expandedURI = shortenerService.expand("a");
        MatcherAssert.assertThat(expandedURI, equalTo(inputUri));
    }

}

@@ -894,24 +894,25 @@
 r.com/a%22));%0A
+%0A
         URI 
@@ -1292,17 +1292,16 @@
 .org%22);%0A
-%0A
         
@@ -1347,33 +1347,32 @@
 rten(inputUri);%0A
-%0A
         MatcherA
@@ -1514,33 +1514,32 @@
 rten(inputUri);%0A
-%0A
         MatcherA

improve readibility of test