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

import static org.smoothbuild.builtin.file.match.Constants.DOUBLE_STAR;
import static org.smoothbuild.builtin.file.match.NamePattern.namePattern;
import static org.smoothbuild.util.Lists.list;
import static org.testory.Testory.given;
import static org.testory.Testory.thenReturned;
import static org.testory.Testory.thenThrown;
import static org.testory.Testory.when;

import org.junit.jupiter.api.Test;

public class NamePatternTest {
  private NamePattern pattern;

  @Test
  public void null_pattern_is_forbidden() {
    when(() -> namePattern(null));
    thenThrown(NullPointerException.class);
  }

  @Test
  public void slash_in_pattern_is_forbidden() {
    when(() -> namePattern("abc/def"));
    thenThrown(IllegalArgumentException.class);
  }

  @Test
  public void empty_pattern_is_forbidden() throws Exception {
    when(() -> namePattern(""));
    thenThrown(IllegalArgumentException.class);
  }

  @Test
  public void double_star_pattern_is_allowed() throws Exception {
    when(namePattern(DOUBLE_STAR));
    thenReturned();
  }

  @Test
  public void double_star_with_suffix_is_not_allowed() throws Exception {
    when(() -> namePattern(DOUBLE_STAR + "a"));
    thenThrown(IllegalArgumentException.class);
  }

  @Test
  public void double_star_with_prefix_is_not_allowed() throws Exception {
    when(() -> namePattern("a" + DOUBLE_STAR));
    thenThrown(IllegalArgumentException.class);
  }

  @Test
  public void three_star_pattern_is_not_allowed() throws Exception {
    when(() -> namePattern("***"));
    thenThrown(IllegalArgumentException.class);
  }

  // hasStars()

  @Test
  public void hasStars_returns_false_for_pattern_that_contains_no_stars() throws Exception {
    given(pattern = namePattern("abcdef"));
    when(pattern.hasStars());
    thenReturned(false);
  }

  @Test
  public void hasStars_returns_true_for_one_star_pattern() throws Exception {
    given(pattern = namePattern("*"));
    when(pattern.hasStars());
    thenReturned(true);
  }

  @Test
  public void hasStars_returns_true_for_pattern_that_contains_one_star() throws Exception {
    given(pattern = namePattern("abc*def"));
    when(pattern.hasStars());
    thenReturned(true);
  }

  @Test
  public void hasStars_returns_true_for_pattern_that_contains_two_stars() throws Exception {
    given(pattern = namePattern("abc*def*ghi"));
    when(pattern.hasStars());
    thenReturned(true);
  }

  // isSingleStar()

  @Test
  public void isSingleStar_returns_false_for_pattern_that_contains_one_star() throws Exception {
    given(pattern = namePattern("*abc"));
    when(pattern.isSingleStar());
    thenReturned(false);
  }

  @Test
  public void isSingleStar_returns_true_for_one_star_pattern() throws Exception {
    given(pattern = namePattern("*"));
    when(pattern.isSingleStar());
    thenReturned(true);
  }

  // isDoubleStar()

  @Test
  public void isDoubleStar_returns_false_for_pattern_that_contains_no_star() throws Exception {
    given(pattern = namePattern("abc"));
    when(pattern.isDoubleStar());
    thenReturned(false);
  }

  @Test
  public void isDoubleStar_returns_false_for_pattern_that_contains_one_star() throws Exception {
    given(pattern = namePattern("*abc"));
    when(pattern.isDoubleStar());
    thenReturned(false);
  }

  @Test
  public void isDoubleStar_returns_false_for_pattern_that_contains_two_disjoint_stars()
      throws Exception {
    given(pattern = namePattern("*abc*def"));
    when(pattern.isDoubleStar());
    thenReturned(false);
  }

  @Test
  public void isDoubleStar_returns_true_for_double_star_pattern() throws Exception {
    given(pattern = namePattern("**"));
    when(pattern.isDoubleStar());
    thenReturned(true);
  }

  // parts()

  @Test
  public void parts_returns_pattern_parts() throws Exception {
    given(pattern = namePattern("abc*def*ghi"));
    when(pattern.parts());
    thenReturned(list("abc", "*", "def", "*", "ghi"));
  }

  @Test
  public void single_star_pattern_has_one_part() throws Exception {
    given(pattern = namePattern("*"));
    when(pattern.parts());
    thenReturned(list("*"));
  }

  @Test
  public void double_star_pattern_has_one_part() throws Exception {
    given(pattern = namePattern("**"));
    when(pattern.parts());
    thenReturned(list("**"));
  }
}<commit_msg>refactored NamePatternTest to use Truth framework<commit_after>package org.smoothbuild.builtin.file.match;

import static com.google.common.truth.Truth.assertThat;
import static org.smoothbuild.builtin.file.match.Constants.DOUBLE_STAR;
import static org.smoothbuild.builtin.file.match.NamePattern.namePattern;
import static org.smoothbuild.testing.common.AssertCall.assertCall;

import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test;

@SuppressWarnings("ClassCanBeStatic")
public class NamePatternTest {
  @Nested
  class creating_pattern {
    @Test
    public void null_is_forbidden() {
      assertCall(() -> namePattern(null))
          .throwsException(NullPointerException.class);
    }

    @Test
    public void with_slash_is_forbidden() {
      assertCall(() -> namePattern("abc/def"))
          .throwsException(IllegalArgumentException.class);
    }

    @Test
    public void for_empty_string_is_forbidden() {
      assertCall(() -> namePattern(""))
          .throwsException(IllegalArgumentException.class);
    }

    @Test
    public void double_star_pattern_is_allowed() {
      namePattern(DOUBLE_STAR);
    }

    @Test
    public void double_star_with_suffix_is_not_allowed() {
      assertCall(() -> namePattern(DOUBLE_STAR + "a"))
          .throwsException(IllegalArgumentException.class);
    }

    @Test
    public void double_star_with_prefix_is_not_allowed() {
      assertCall(() -> namePattern("a" + DOUBLE_STAR))
          .throwsException(IllegalArgumentException.class);
    }

    @Test
    public void three_star_pattern_is_not_allowed() {
      assertCall(() -> namePattern("***"))
          .throwsException(IllegalArgumentException.class);
    }
  }

  @Nested
  class hasStars {
    @Test
    public void returns_false_for_pattern_that_contains_no_stars() {
      assertThat(namePattern("abcdef").hasStars())
          .isFalse();
    }

    @Test
    public void returns_true_for_one_star_pattern() {
      assertThat(namePattern("*").hasStars())
          .isTrue();
    }

    @Test
    public void returns_true_for_pattern_that_contains_one_star() {
      assertThat(namePattern("abc*def").hasStars())
          .isTrue();
    }

    @Test
    public void returns_true_for_pattern_that_contains_two_stars() {
      assertThat(namePattern("abc*def*ghi").hasStars())
          .isTrue();
    }
  }

  @Nested
  class isSingleStar {
    @Test
    public void returns_false_for_pattern_that_contains_one_star() {
      assertThat(namePattern("*abc").isSingleStar())
          .isFalse();
    }

    @Test
    public void returns_true_for_one_star_pattern() {
      assertThat(namePattern("*").isSingleStar())
          .isTrue();
    }
  }

  @Nested
  class isDoubleStart {
    @Test
    public void returns_false_for_pattern_that_contains_no_star() {
      assertThat(namePattern("abc").isDoubleStar())
          .isFalse();
    }

    @Test
    public void returns_false_for_pattern_that_contains_one_star() {
      assertThat(namePattern("*abc").isDoubleStar())
          .isFalse();
    }

    @Test
    public void returns_false_for_pattern_that_contains_two_disjoint_stars() {
      assertThat(namePattern("*abc*def").isDoubleStar())
          .isFalse();
    }

    @Test
    public void returns_true_for_double_star_pattern() {
      assertThat(namePattern("**").isDoubleStar())
          .isTrue();
    }
  }

  @Nested
  class parts {
    @Test
    public void returns_pattern_parts() {
      assertThat(namePattern("abc*def*ghi").parts())
          .containsExactly("abc", "*", "def", "*", "ghi")
          .inOrder();
    }

    @Test
    public void single_star_pattern_has_one_part() {
      assertThat(namePattern("*").parts())
          .containsExactly("*");
    }

    @Test
    public void double_star_pattern_has_one_part() {
      assertThat(namePattern("**").parts())
          .containsExactly("**");
    }
  }
}
{'fraction_non_alphanumeric': 0.1226598589837102, 'fraction_numerical': 0.0, 'mean_word_length': 3.9381752701080432, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 15, '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': '6543089', 'n_tokens_mistral': 2585, 'n_tokens_neox': 2532, 'n_words': 399}