<commit_before>package io.growingabit.app.tasks.deferred;

import java.lang.reflect.Field;

import org.junit.Assert;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;

import com.googlecode.objectify.Key;
import com.googlecode.objectify.ObjectifyService;

import io.growingabit.app.dao.StudentEmailSignupStageDao;
import io.growingabit.app.dao.UserDao;
import io.growingabit.app.model.StudentConfirmationEmail;
import io.growingabit.app.model.StudentEmailSignupStage;
import io.growingabit.app.model.User;
import io.growingabit.app.utils.gson.GsonFactory;
import io.growingabit.testUtils.BaseGaeTest;

public class DeferredTaskSendVerificationEmailTest extends BaseGaeTest {

  @Before
  public void setUp() {
    ObjectifyService.register(User.class);
    ObjectifyService.register(StudentEmailSignupStage.class);
  }

  @Test
  public void keyNull() {
    DeferredTaskSendVerificationEmail d = new DeferredTaskSendVerificationEmail(null);
    try {
      d.run();
      assert true;
    } catch (Throwable t) {
      Assert.fail("Should not throws exception");
    }
  }

  @Test
  public void keyEmpty() {
    DeferredTaskSendVerificationEmail d = new DeferredTaskSendVerificationEmail("");
    try {
      d.run();
      assert true;
    } catch (Throwable t) {
      Assert.fail("Should not throws exception");
    }
  }

  @Test
  public void notAKey() {
    DeferredTaskSendVerificationEmail d = new DeferredTaskSendVerificationEmail("foo");
    try {
      d.run();
      assert true;
    } catch (Throwable t) {
      Assert.fail("Should not throws exception");
    }

  }

  @Test
  public void wrongKey() {
    DeferredTaskSendVerificationEmail d = new DeferredTaskSendVerificationEmail(Key.create(StudentEmailSignupStage.class, 1L).toWebSafeString());
    try {
      d.run();
      assert true;
    } catch (Throwable t) {
      Assert.fail("Should not throws exception");
    }
  }


  @Test
  @Ignore
  public void checkEquals() {

    try {
      StudentEmailSignupStage s = new StudentEmailSignupStage();
      s.setData(new StudentConfirmationEmail("<EMAIL>"));

      User user = new User();
      user.setId("id");
      new UserDao().persist(user);
      s.setUser(Key.create(User.class, user.getId()));

      StudentEmailSignupStageDao dao = new StudentEmailSignupStageDao();
      dao.persist(s);

      DeferredTaskSendVerificationEmail d = new DeferredTaskSendVerificationEmail(s.getWebSafeKey());

      Field f = DeferredTaskSendVerificationEmail.class.getDeclaredField("studentEmailSignupStageWebsafeString");
      f.setAccessible(true);
      String studentEmailSignupStageWebsafeString = (String) f.get(d);
      StudentEmailSignupStage stage = dao.find(studentEmailSignupStageWebsafeString);

      Assert.assertNotNull(stage.getData().getEmail());
      Assert.assertNotNull(stage.getData().getVerificationCode());
      Assert.assertNotNull(stage.getData().getTsExpiration());

      Assert.assertEquals(GsonFactory.getGsonInstance().toJson(s), GsonFactory.getGsonInstance().toJson(stage));

    } catch (Exception e) {
      e.printStackTrace();
      Assert.fail();
    }

  }


}<commit_msg>Rimosso Assert al posto di assertThat<commit_after>package io.growingabit.app.tasks.deferred;

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

import java.lang.reflect.Field;

import org.junit.Assert;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;

import com.googlecode.objectify.Key;
import com.googlecode.objectify.ObjectifyService;

import io.growingabit.app.dao.StudentEmailSignupStageDao;
import io.growingabit.app.dao.UserDao;
import io.growingabit.app.model.StudentConfirmationEmail;
import io.growingabit.app.model.StudentEmailSignupStage;
import io.growingabit.app.model.User;
import io.growingabit.testUtils.BaseGaeTest;

public class DeferredTaskSendVerificationEmailTest extends BaseGaeTest {

  @Before
  public void setUp() {
    ObjectifyService.register(User.class);
    ObjectifyService.register(StudentEmailSignupStage.class);
  }

  @Test
  public void keyNull() {
    DeferredTaskSendVerificationEmail d = new DeferredTaskSendVerificationEmail(null);
    try {
      d.run();
      assert true;
    } catch (Throwable t) {
      Assert.fail("Should not throws exception");
    }
  }

  @Test
  public void keyEmpty() {
    DeferredTaskSendVerificationEmail d = new DeferredTaskSendVerificationEmail("");
    try {
      d.run();
      assert true;
    } catch (Throwable t) {
      Assert.fail("Should not throws exception");
    }
  }

  @Test
  public void notAKey() {
    DeferredTaskSendVerificationEmail d = new DeferredTaskSendVerificationEmail("foo");
    try {
      d.run();
      assert true;
    } catch (Throwable t) {
      Assert.fail("Should not throws exception");
    }

  }

  @Test
  public void wrongKey() {
    DeferredTaskSendVerificationEmail d = new DeferredTaskSendVerificationEmail(Key.create(StudentEmailSignupStage.class, 1L).toWebSafeString());
    try {
      d.run();
      assert true;
    } catch (Throwable t) {
      Assert.fail("Should not throws exception");
    }
  }


  @Test
  @Ignore
  public void checkEquals() {

    try {
      StudentEmailSignupStage s = new StudentEmailSignupStage();
      s.setData(new StudentConfirmationEmail("<EMAIL>"));

      User user = new User();
      user.setId("id");
      new UserDao().persist(user);
      s.setUser(Key.create(User.class, user.getId()));

      StudentEmailSignupStageDao dao = new StudentEmailSignupStageDao();
      dao.persist(s);

      DeferredTaskSendVerificationEmail d = new DeferredTaskSendVerificationEmail(s.getWebSafeKey());

      Field f = DeferredTaskSendVerificationEmail.class.getDeclaredField("studentEmailSignupStageWebsafeString");
      f.setAccessible(true);
      String studentEmailSignupStageWebsafeString = (String) f.get(d);
      StudentEmailSignupStage stage = dao.find(studentEmailSignupStageWebsafeString);

      assertThat(stage.getData().getEmail()).isNotNull();
      assertThat(stage.getData().getVerificationCode()).isNotNull();
      assertThat(stage.getData().getTsExpiration()).isNotNull();

      assertThat(stage.getData().getEmail()).isEqualTo(s.getData().getEmail());
      assertThat(stage.getData().getVerificationCode()).isEqualTo(s.getData().getVerificationCode());
      assertThat(stage.getData().getTsExpiration()).isEqualTo(s.getData().getTsExpiration());

    } catch (Exception e) {
      e.printStackTrace();
      Assert.fail();
    }

  }


}
{'fraction_non_alphanumeric': 0.11362238622386224, 'fraction_numerical': 0.0003075030750307503, 'mean_word_length': 3.969442322383499, 'pattern_counts': {'":': 0, '<': 5, '<?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': '4829243', 'n_tokens_mistral': 1988, 'n_tokens_neox': 1960, 'n_words': 345}