<commit_before>package org.smoothbuild.builtin.file;

import static org.assertj.core.api.Assertions.assertThat;
import static org.smoothbuild.fs.base.Path.path;

import java.io.IOException;

import org.junit.Test;
import org.smoothbuild.fs.base.Path;
import org.smoothbuild.integration.IntegrationTestCase;
import org.smoothbuild.object.err.DuplicatePathError;
import org.smoothbuild.parse.err.SyntaxError;
import org.smoothbuild.testing.type.impl.FakeFile;
import org.smoothbuild.testing.type.impl.FakeFileSet;

import com.google.common.collect.Iterables;

public class FileSetSmoothTest extends IntegrationTestCase {

  @Test
  public void setWithTrailingCommaIsAllowed() throws Exception {
    Path dir = path("destination/dir");
    FakeFile file1 = file(path("file/path/file1.txt"));
    FakeFile file2 = file(path("file/path/file2.txt"));
    file1.createContentWithFilePath();
    file2.createContentWithFilePath();

    StringBuilder builder = new StringBuilder();
    builder.append("myfiles : [ file(" + file1.path() + "), file(" + file2.path() + "), ];\n");
    builder.append("run : myfiles | save(" + dir + ");\n");
    script(builder.toString());

    // when
    smoothApp.run("run");

    // then
    messages.assertNoProblems();
    FakeFileSet resultFiles = fileSet(dir);
    assertThat(Iterables.size(resultFiles)).isEqualTo(2);
  }

  @Test
  public void setWithOnlyCommaIsForbidden() throws Exception {
    // given
    script("run : [ , ];");

    // when
    smoothApp.run("run");

    // then
    messages.assertOnlyProblem(SyntaxError.class);
  }

  @Test
  public void saveFileSetWithTwoFiles() throws IOException {
    // given
    Path dir = path("destination/dir");
    FakeFile file1 = file(path("file/path/file1.txt"));
    FakeFile file2 = file(path("file/path/file2.txt"));
    file1.createContentWithFilePath();
    file2.createContentWithFilePath();

    StringBuilder builder = new StringBuilder();
    builder.append("myfiles : [ file(" + file1.path() + "), file(" + file2.path() + ") ];\n");
    builder.append("run : myfiles | save(" + dir + ");\n");
    script(builder.toString());

    // when
    smoothApp.run("run");

    // then
    messages.assertNoProblems();
    FakeFileSet resultFiles = fileSet(dir);
    resultFiles.file(file1.path()).assertContentContainsFilePath();
    resultFiles.file(file2.path()).assertContentContainsFilePath();
    assertThat(Iterables.size(resultFiles)).isEqualTo(2);
  }

  @Test
  public void saveFileSetWithOneFile() throws IOException {
    // given
    Path dir = path("destination/dir");
    FakeFile file1 = file(path("file/path/file1.txt"));
    file1.createContentWithFilePath();

    StringBuilder builder = new StringBuilder();
    builder.append("myfiles : [ file(" + file1.path() + ") ];\n");
    builder.append("run : myfiles | save(" + dir + ");\n");
    script(builder.toString());

    // when
    smoothApp.run("run");

    // then
    messages.assertNoProblems();
    FakeFileSet resultFiles = fileSet(dir);
    resultFiles.file(file1.path()).assertContentContainsFilePath();
    assertThat(Iterables.size(resultFiles)).isEqualTo(1);
  }

  @Test
  public void saveEmptyFileSet() throws IOException {
    // given
    Path dir = path("destination/dir");

    StringBuilder builder = new StringBuilder();
    builder.append("myfiles : [ ];\n");
    builder.append("run : myfiles | save(" + dir + ");\n");
    script(builder.toString());

    // when
    smoothApp.run("run");

    // then
    messages.assertNoProblems();
    FakeFileSet resultFiles = fileSet(dir);
    assertThat(Iterables.size(resultFiles)).isEqualTo(0);
  }

  @Test
  public void fileSetWithDuplicatedFiles() throws Exception {
    // given
    FakeFile file1 = file(path("file/path/file1.txt"));
    file1.createContentWithFilePath();

    script("run : [ file(" + file1.path() + "), file(" + file1.path() + ") ];\n");

    // when
    smoothApp.run("run");

    // then
    messages.assertOnlyProblem(DuplicatePathError.class);
  }
}<commit_msg>refactored FileSetSmoothTest<commit_after>package org.smoothbuild.builtin.file;

import static org.assertj.core.api.Assertions.assertThat;
import static org.smoothbuild.fs.base.Path.path;

import java.io.IOException;

import org.junit.Test;
import org.smoothbuild.fs.base.Path;
import org.smoothbuild.integration.IntegrationTestCase;
import org.smoothbuild.object.err.DuplicatePathError;
import org.smoothbuild.parse.err.SyntaxError;
import org.smoothbuild.testing.type.impl.FakeFileSet;

import com.google.common.collect.Iterables;

public class FileSetSmoothTest extends IntegrationTestCase {
  Path path1 = path("file/path/file1.txt");
  Path path2 = path("file/path/file2.txt");

  @Test
  public void setWithTrailingCommaIsAllowed() throws Exception {
    Path dir = path("destination/dir");
    fileSystem.createFileContainingItsPath(path1);
    fileSystem.createFileContainingItsPath(path2);

    StringBuilder builder = new StringBuilder();
    builder.append("myfiles : [ file(" + path1 + "), file(" + path2 + "), ];\n");
    builder.append("run : myfiles | save(" + dir + ");\n");
    script(builder.toString());

    // when
    smoothApp.run("run");

    // then
    messages.assertNoProblems();
    FakeFileSet resultFiles = fileSet(dir);
    assertThat(Iterables.size(resultFiles)).isEqualTo(2);
  }

  @Test
  public void setWithOnlyCommaIsForbidden() throws Exception {
    // given
    script("run : [ , ];");

    // when
    smoothApp.run("run");

    // then
    messages.assertOnlyProblem(SyntaxError.class);
  }

  @Test
  public void saveFileSetWithTwoFiles() throws IOException {
    // given
    Path dir = path("destination/dir");
    fileSystem.createFileContainingItsPath(path1);
    fileSystem.createFileContainingItsPath(path2);

    StringBuilder builder = new StringBuilder();
    builder.append("myfiles : [ file(" + path1 + "), file(" + path2 + ") ];\n");
    builder.append("run : myfiles | save(" + dir + ");\n");
    script(builder.toString());

    // when
    smoothApp.run("run");

    // then
    messages.assertNoProblems();
    FakeFileSet resultFiles = fileSet(dir);
    resultFiles.file(path1).assertContentContainsFilePath();
    resultFiles.file(path2).assertContentContainsFilePath();
    assertThat(Iterables.size(resultFiles)).isEqualTo(2);
  }

  @Test
  public void saveFileSetWithOneFile() throws IOException {
    // given
    Path dir = path("destination/dir");

    fileSystem.createFileContainingItsPath(path1);

    StringBuilder builder = new StringBuilder();
    builder.append("myfiles : [ file(" + path1 + ") ];\n");
    builder.append("run : myfiles | save(" + dir + ");\n");
    script(builder.toString());

    // when
    smoothApp.run("run");

    // then
    messages.assertNoProblems();
    FakeFileSet resultFiles = fileSet(dir);
    resultFiles.file(path1).assertContentContainsFilePath();
    assertThat(Iterables.size(resultFiles)).isEqualTo(1);
  }

  @Test
  public void saveEmptyFileSet() throws IOException {
    // given
    Path dir = path("destination/dir");

    StringBuilder builder = new StringBuilder();
    builder.append("myfiles : [ ];\n");
    builder.append("run : myfiles | save(" + dir + ");\n");
    script(builder.toString());

    // when
    smoothApp.run("run");

    // then
    messages.assertNoProblems();
    FakeFileSet resultFiles = fileSet(dir);
    assertThat(Iterables.size(resultFiles)).isEqualTo(0);
  }

  @Test
  public void fileSetWithDuplicatedFiles() throws Exception {
    // given
    fileSystem.createFileContainingItsPath(path1);

    script("run : [ file(" + path1 + "), file(" + path1 + ") ];\n");

    // when
    smoothApp.run("run");

    // then
    messages.assertOnlyProblem(DuplicatePathError.class);
  }
}
{'fraction_non_alphanumeric': 0.15029051000645577, 'fraction_numerical': 0.00723047127178825, 'mean_word_length': 3.775585696670777, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3022249', 'n_tokens_mistral': 2396, 'n_tokens_neox': 2323, 'n_words': 419}