<commit_before>package org.smoothbuild.lang.object.base;

import static org.hamcrest.Matchers.not;
import static org.testory.Testory.given;
import static org.testory.Testory.thenReturned;
import static org.testory.Testory.when;

import org.junit.Test;
import org.smoothbuild.db.hashed.Hash;
import org.smoothbuild.testing.TestingContext;

import okio.ByteString;

public class BlobTest extends TestingContext {
  private final ByteString bytes = ByteString.encodeUtf8("aaa");
  private final ByteString otherBytes = ByteString.encodeUtf8("bbb");
  private BlobBuilder blobBuilder;
  private Blob blob;
  private Blob blob2;
  private Hash hash;

  @Test
  public void creating_blob_without_content_creates_empty_blob() throws Exception {
    given(blobBuilder = blobBuilder());
    given(blob = blobBuilder.build());
    when(blob.source().readByteString());
    thenReturned(ByteString.of());
  }

  @Test
  public void type_of_blob_is_blob() throws Exception {
    given(blob = blob(bytes));
    when(blob).type();
    thenReturned(blobType());
  }

  @Test
  public void empty_blob_is_empty() throws Exception {
    given(blobBuilder = blobBuilder());
    given(blob = blobBuilder.build());
    when(blob.source().readByteString());
    thenReturned(ByteString.of());
  }

  @Test
  public void blob_has_content_passed_to_builder() throws Exception {
    given(blob = blob(bytes));
    when(blob.source().readByteString());
    thenReturned(bytes);
  }

  @Test
  public void blobs_with_equal_content_are_equal() throws Exception {
    given(blob = blob(bytes));
    given(blob2 = blob(bytes));
    when(blob);
    thenReturned(blob2);
  }

  @Test
  public void blobs_with_different_content_are_not_equal() throws Exception {
    given(blob = blob(bytes));
    given(blob2 = blob(otherBytes));
    when(blob);
    thenReturned(not(blob2));
  }

  @Test
  public void hash_of_blobs_with_equal_content_is_the_same() throws Exception {
    given(blob = blob(bytes));
    given(blob2 = blob(bytes));
    when(blob.hash());
    thenReturned(blob2.hash());
  }

  @Test
  public void hash_of_blobs_with_different_content_is_not_the_same() throws Exception {
    given(blob = blob(bytes));
    given(blob2 = blob(otherBytes));
    when(blob.hash());
    thenReturned(not(blob2.hash()));
  }

  @Test
  public void hash_code_of_blob_with_equal_content_is_the_same() throws Exception {
    given(blob = blob(bytes));
    given(blob2 = blob(bytes));
    when(blob.hashCode());
    thenReturned(blob2.hashCode());
  }

  @Test
  public void hash_code_of_blobs_with_different_values_is_not_the_same() throws Exception {
    given(blob = blob(bytes));
    given(blob2 = blob(otherBytes));
    when(blob.hashCode());
    thenReturned(not(blob2.hashCode()));
  }

  @Test
  public void blob_can_be_read_by_hash() throws Exception {
    given(blob = blob(bytes));
    given(hash = blob.hash());
    when(() -> objectDbOther().get(hash));
    thenReturned(blob);
  }

  @Test
  public void blob_read_by_hash_has_same_content() throws Exception {
    given(blob = blob(bytes));
    given(hash = blob.hash());
    when(((Blob) objectDbOther().get(hash)).source().readByteString());
    thenReturned(blob.source().readByteString());
  }

  @Test
  public void to_string() throws Exception {
    given(blob = blob(bytes));
    when(() -> blob.toString());
    thenReturned("Blob(...):" + blob.hash());
  }
}
<commit_msg>refactored BlobTest to use Truth framework<commit_after>package org.smoothbuild.lang.object.base;

import static com.google.common.truth.Truth.assertThat;

import org.junit.Test;
import org.smoothbuild.db.hashed.Hash;
import org.smoothbuild.testing.TestingContext;

import okio.ByteString;

public class BlobTest extends TestingContext {
  private final ByteString bytes = ByteString.encodeUtf8("aaa");
  private final ByteString otherBytes = ByteString.encodeUtf8("bbb");

  @Test
  public void creating_blob_without_content_creates_empty_blob() throws Exception {
    Blob blob = blobBuilder().build();
    assertThat(blob.source().readByteString())
        .isEqualTo(ByteString.of());
  }

  @Test
  public void type_of_blob_is_blob() {
    assertThat(blob(bytes).type())
        .isEqualTo(blobType());
  }

  @Test
  public void empty_blob_is_empty() throws Exception {
    Blob blob = blobBuilder().build();
    assertThat(blob.source().readByteString())
        .isEqualTo(ByteString.of());
  }

  @Test
  public void blob_has_content_passed_to_builder() throws Exception {
    Blob blob = blob(bytes);
    assertThat(blob.source().readByteString())
        .isEqualTo(bytes);
  }

  @Test
  public void blobs_with_equal_content_are_equal() {
    assertThat(blob(bytes))
        .isEqualTo(blob(bytes));
  }

  @Test
  public void blobs_with_different_content_are_not_equal() {
    assertThat(blob(bytes))
        .isNotEqualTo(blob(otherBytes));
  }

  @Test
  public void hash_of_blobs_with_equal_content_is_the_same() {
    assertThat(blob(bytes).hash())
        .isEqualTo(blob(bytes).hash());
  }

  @Test
  public void hash_of_blobs_with_different_content_is_not_the_same() {
    assertThat(blob(bytes).hash())
        .isNotEqualTo(blob(otherBytes).hash());
  }

  @Test
  public void hash_code_of_blob_with_equal_content_is_the_same() {
    assertThat(blob(bytes).hashCode())
        .isEqualTo(blob(bytes).hashCode());
  }

  @Test
  public void hash_code_of_blobs_with_different_values_is_not_the_same() {
    assertThat(blob(bytes).hashCode())
        .isNotEqualTo(blob(otherBytes).hashCode());
  }

  @Test
  public void blob_can_be_read_by_hash() {
    Blob blob = blob(bytes);
    Hash hash = blob.hash();
    assertThat(objectDbOther().get(hash))
        .isEqualTo(blob);
  }

  @Test
  public void blob_read_by_hash_has_same_content() throws Exception {
    Blob blob = blob(bytes);
    Hash hash = blob.hash();
    assertThat(((Blob) objectDbOther().get(hash)).source().readByteString())
        .isEqualTo(blob.source().readByteString());
  }

  @Test
  public void to_string() {
    Blob blob = blob(bytes);
    assertThat(blob.toString())
        .isEqualTo("Blob(...):" + blob.hash());
  }
}

{'fraction_non_alphanumeric': 0.13026444662095985, 'fraction_numerical': 0.00277505713352922, 'mean_word_length': 4.272805507745267, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '2274381', 'n_tokens_mistral': 2007, 'n_tokens_neox': 1980, 'n_words': 348}