package io.reflectoring.coderadar.adapter;

import io.reflectoring.coderadar.vcs.UnableToCloneRepositoryException;
import io.reflectoring.coderadar.vcs.adapter.CloneRepositoryAdapter;
import io.reflectoring.coderadar.vcs.port.driver.clone.CloneRepositoryCommand;
import java.io.File;
import java.io.IOException;
import java.net.URL;
import org.apache.tomcat.util.http.fileupload.FileUtils;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;

public class CloneRepositoryAdapterTest {

  @TempDir public File folder;

  @Test
  public void test() throws UnableToCloneRepositoryException {
    URL testRepoURL = this.getClass().getClassLoader().getResource("test-repository");

    CloneRepositoryAdapter cloneRepositoryAdapter = new CloneRepositoryAdapter();
    cloneRepositoryAdapter.cloneRepository(
        new CloneRepositoryCommand(testRepoURL.toString(), folder, "", ""));

    Assertions.assertEquals(3, folder.list().length);
    Assertions.assertEquals(".git", folder.list()[0]);
    Assertions.assertEquals("GetMetricsForCommitCommand.java", folder.list()[1]);
    Assertions.assertEquals("testModule1", folder.list()[2]);
  }

  @AfterEach
  public void tearDown() throws IOException {
    FileUtils.deleteDirectory(folder);
  }
}

@@ -326,16 +326,41 @@
 et.URL;%0A
+import java.util.Arrays;%0A
 import o
@@ -1083,68 +1083,123 @@
 sert
-Equals(%22.git%22, folder.list()%5B0%5D);%0A    Assertions.assertEqual
+True(Arrays.asList(folder.list()).contains(%22.git%22));%0A    Assertions.assertTrue(Arrays.asList(folder.list()).contain
 s(%22G
@@ -1233,26 +1233,9 @@
 ava%22
-, folder.list()%5B1%5D
+)
 );%0A 
@@ -1258,46 +1258,65 @@
 sert
-Equals(%22testModule1%22, folder.list()%5B2%5D
+True(Arrays.asList(folder.list()).contains(%22testModule1%22)
 );%0A 

fix tests not running on Linux