package net.zephyrizing.http_server_test;

import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Arrays;
import java.util.stream.Stream;

import net.zephyrizing.http_server.HttpProtocol;
import net.zephyrizing.http_server.HttpRequest;

import org.junit.Test;

import static java.util.Arrays.asList;

import static net.zephyrizing.http_server.HttpRequest.Method.*;

import static org.junit.Assert.*;

public class HttpRequestTest {

    @Test
    public void canCreateGETRequest() {
        Stream<String> requestLines = Stream.of("GET / HTTP/1.1", "");
        HttpRequest request = HttpProtocol.requestFromLines(requestLines);
        assertEquals(GET, request.method());
        assertEquals(Paths.get("/"), request.path());
        assertEquals("1.1", request.protocolVersion());
    }

    @Test
    public void canCreatePOSTRequest() {
        Stream<String> requestLines = Stream.of("POST /root HTTP/1.0", "");
        HttpRequest request = HttpProtocol.requestFromLines(requestLines);
        assertEquals(POST, request.method());
        assertEquals(Paths.get("/root"), request.path());
        assertEquals("1.0", request.protocolVersion());
    }

    @Test
    public void canResolveTheRootPath() {
        Stream<String> requestLines = Stream.of("POST / HTTP/1.0", "");
        HttpRequest request = HttpProtocol.requestFromLines(requestLines);

        Path root = Paths.get("/root/path");

        Path requested = request.getResolvedPath(root);
        assertEquals(Paths.get("/root/path"), requested);
    }

    @Test
    public void canResolvePaths() {
        Stream<String> requestLines = Stream.of("POST /branch HTTP/1.0", "");
        HttpRequest request = HttpProtocol.requestFromLines(requestLines);

        Path root = Paths.get("/root/path");

        Path requested = request.getResolvedPath(root);
        assertEquals(Paths.get("/root/path/branch"), requested);
    }
}

@@ -505,143 +505,61 @@
     
-Stream%3CString%3E requestLines = Stream.of(%22GET / HTTP/1.1%22, %22%22);%0A        HttpRequest request = HttpProtocol.requestFromLines(requestLines
+HttpRequest request = new HttpRequest(GET, %22/%22, %221.1%22
 );%0A 
@@ -774,84 +774,8 @@
 ) %7B%0A
-        Stream%3CString%3E requestLines = Stream.of(%22POST /root HTTP/1.0%22, %22%22);%0A
     
@@ -803,51 +803,45 @@
 st =
+ new
  Http
-Protocol.requestFromLines(requestLines
+Request(POST, %22/root%22, %221.0%22
 );%0A 
@@ -1070,144 +1070,62 @@
     
-Stream%3CString%3E requestLines = Stream.of(%22POST / HTTP/1.0%22, %22%22);%0A        HttpRequest request = HttpProtocol.requestFromLines(requestLines
+HttpRequest request = new HttpRequest(POST, %22/%22, %221.0%22
 );%0A%0A
@@ -1349,150 +1349,68 @@
     
-Stream%3CString%3E requestLines = Stream.of(%22POST /branch HTTP/1.0%22, %22%22);%0A        HttpRequest request = HttpProtocol.requestFromLines(requestLines
+HttpRequest request = new HttpRequest(POST, %22/branch%22, %221.0%22
 );%0A%0A

Use a constructor in HttpRequest tests