package com.google.graphgeckos.dashboard.buildbot;

import com.google.graphgeckos.dashboard.fetchers.buildbot.BuildBotClient;
import com.squareup.okhttp.mockwebserver.MockResponse;
import com.squareup.okhttp.mockwebserver.MockWebServer;
import org.junit.Test;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.junit.jupiter.MockitoExtension;
import org.springframework.boot.test.mock.mockito.MockBean;

import java.io.IOException;

@ExtendWith(MockitoExtension.class)
public class BuildBotClientTest {

  public static MockWebServer webServer;

  @BeforeAll
  static void setUp() {
    webServer = new MockWebServer();
  }

  @AfterAll
  public static void tearDown() throws IOException {
    webServer.shutdown();
  }

  private final BuildBotTestInfo JSON_WITHOUT_UNKNOWN_FIELDS =
    new BuildBotTestInfo("no_unknown_fields_json");

  @Test
  public void jsonWithoutUnknownFieldsIsParsedCorrectly() {
    String baseUrl = String.format("http://localhost:%s", webServer.getPort());
    BuildBotClient.setBaseUrl(baseUrl);

    webServer.enqueue(new MockResponse()
      .setBody(JSON_WITHOUT_UNKNOWN_FIELDS.getContent())
      .setHeader("Content-Type", "application/json"));
  }


}

@@ -134,208 +134,87 @@
 com.
-squareup.okhttp.mockwebserver.MockResponse;%0Aimport com.squareup.okhttp.mockwebserver.MockWebServer;%0Aimport org.junit.Test;%0Aimport org.junit.jupiter.api.AfterAll;%0Aimport org.junit.jupiter.api.BeforeAll
+google.graphgeckos.dashboard.storage.DatastoreRepository;%0Aimport org.junit.Test
 ;%0Aim
@@ -262,16 +262,48 @@
 ndWith;%0A
+import org.mockito.InjectMocks;%0A
 import o
@@ -410,37 +410,8 @@
 n;%0A%0A
-import java.io.IOException;%0A%0A
 @Ext
@@ -483,685 +483,222 @@
 %0A%0A  
-public static MockWebServer webServer;%0A%0A  @BeforeAll%0A  static void setUp() %7B%0A    webServer = new MockWebServer();%0A  %7D%0A%0A  @AfterAll%0A  public static void tearDown() throws IOException %7B%0A    webServer.shutdown();%0A  %7D%0A%0A  private final BuildBotTestInfo JSON_WITHOUT_UNKNOWN_FIELDS =%0A    new BuildBotTestInfo(%22no_unknown_fields_json%22);%0A%0A  @Test%0A  public void jsonWithoutUnknownFieldsIsParsedCorrectly() %7B%0A    String baseUrl = String.format(%22http://localhost:%25s%22, webServer.getPort());%0A    BuildBotClient.setBaseUrl(baseUrl);%0A%0A    webServer.enqueue(new MockResponse()%0A      .setBody(JSON_WITHOUT_UNKNOWN_FIELDS.getContent())%0A      .setHeader(%22Content-Type%22, %22application/json%22)
+@MockBean%0A  DatastoreRepository datastoreRepository;%0A%0A  @InjectMocks%0A  BuildBotClient client;%0A%0A  @Test%0A  public void allFieldAreOfExpectedFormat() %7B%0A    BuildBotClient.run(%22llvm-clang-x86_64-win-fast%22, 23346
 );%0A
+%0A
   %7D%0A%0A
-%0A
 %7D%0A

add test