package com.example.android.tasse;

import com.example.android.tasse.api.JourneysVehicleReader;
import com.squareup.okhttp.HttpUrl;
import com.squareup.okhttp.OkHttpClient;
import com.squareup.okhttp.mockwebserver.MockResponse;
import com.squareup.okhttp.mockwebserver.MockWebServer;

import junit.framework.TestCase;

public class JourneysVehicleReaderTest extends TestCase {

    MockWebServer mMockWebServer;
    private OkHttpClient mOkHttpClient;

    public void setUp() throws Exception {
        super.setUp();
        mOkHttpClient = new OkHttpClient();
        mMockWebServer = new MockWebServer();
        mMockWebServer.start();
    }

    public void tearDown() throws Exception {
        mMockWebServer.shutdown();
    }

    public void testLoadFromNetwork() throws Exception {
        final HttpUrl url = mMockWebServer.url("/journeys/api/1/vehicle-activity");

        mMockWebServer.enqueue(new MockResponse().setBody("it's all cool"));

        final JourneysVehicleReader journeysVehicleReader = new JourneysVehicleReader(mOkHttpClient);
        journeysVehicleReader.loadFromNetwork(url.toString());
        assertTrue(journeysVehicleReader.getVehicles().isEmpty());

    }

}
@@ -371,16 +371,1110 @@
 Case %7B%0A%0A
+    String json = %22%7B %5Cn%22 +%0A            %22  %5C%22status%5C%22 : %5C%22success%5C%22, %5Cn%22 +%0A            %22  %5C%22body%5C%22 : %5B %5Cn%22 +%0A            %22    %7B %5Cn%22 +%0A            %22      %5C%22monitoredVehicleJourney%5C%22 : %7B %5Cn%22 +%0A            %22        %5C%22lineRef%5C%22 : %5C%221%5C%22, %5Cn%22 +%0A            %22        %5C%22vehicleLocation%5C%22 : %7B %5C%22longitude%5C%22 : %5C%2223.9074487%5C%22, %5C%22latitude%5C%22 : %5C%2261.4930180%5C%22 %7D, %5Cn%22 +%0A            %22        %5C%22operatorRef%5C%22 : %5C%22Paunu%5C%22, %5Cn%22 +%0A            %22        %5C%22vehicleRef%5C%22 : %5C%22Paunu_166%5C%22, %5Cn%22 +%0A            %22        %5C%22journeyPatternRef%5C%22 : %5C%221A%5C%22, %5Cn%22 +%0A            %22        %5C%22onwardCalls%5C%22 : %5B %5Cn%22 +%0A            %22          %7B %5Cn%22 +%0A            %22            %5C%22expectedArrivalTime%5C%22 : %5C%222015-10-22T09:29:00+03:00%5C%22, %5Cn%22 +%0A            %22            %5C%22expectedDepartureTime%5C%22 : %5C%222015-10-22T09:29:00+03:00%5C%22, %5Cn%22 +%0A            %22            %5C%22stopPointRef%5C%22 : %5C%22http://data.itsfactory.fi/journeys/api/1/stop-points/5132%5C%22, %5Cn%22 +%0A            %22            %5C%22order%5C%22 : %5C%2250%5C%22 %5Cn%22 +%0A            %22          %7D%5Cn%22 +%0A            %22        %5D%5Cn%22 +%0A            %22      %7D%5Cn%22 +%0A            %22    %7D%5Cn%22 +%0A            %22  %5D%5Cn%22 +%0A            %22%7D%22;%0A
     Mock
@@ -1538,16 +1538,42 @@
 pClient;
+%0A    private HttpUrl mUrl;
 %0A%0A    pu
@@ -1749,24 +1749,96 @@
 ver.start();
+%0A%0A        mUrl = mMockWebServer.url(%22/journeys/api/1/vehicle-activity%22);
 %0A    %7D%0A%0A    
@@ -1981,92 +1981,8 @@
 on %7B
-%0A        final HttpUrl url = mMockWebServer.url(%22/journeys/api/1/vehicle-activity%22);
 %0A%0A  
@@ -2041,23 +2041,12 @@
 ody(
-%22it's all cool%22
+json
 ));%0A
@@ -2194,17 +2194,18 @@
 Network(
-u
+mU
 rl.toStr
@@ -2271,17 +2271,19 @@
 s().
-isEmpty()
+size() == 1
 );%0A%0A

Fix test for JourneysVehicleReader.