<commit_before>package ru.stqa.pft.addressbook.tests;

import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
import ru.stqa.pft.addressbook.model.ContactData;
import ru.stqa.pft.addressbook.model.Contacts;
import ru.stqa.pft.addressbook.model.GroupData;
import ru.stqa.pft.addressbook.model.Groups;

/**
 * Created by IrinaIv on 6/23/2017.
 */
public class ContactDeleteFromGroupTests extends TestBase {

  @BeforeMethod
  public void ensurePreconditions() {
    app.goTo().groupPage();
    if (app.db().groups().size() == 0) {
      app.goTo().groupPage();
      app.group().create(new GroupData().withName("test3"));
    }
    app.contact().homePage();
    Groups groups = app.db().groups();
    if (app.db().contacts().size() == 0) {
      app.goTo().contactPage();
      app.contact().create(new ContactData().withFirstname("I").withLastname("V")
              .withAddress("ad").withHomephone("1234").withMobilephone("1234")
              .withWorkphone("2345").withAllphones("").withEmail("<EMAIL>")
              .withEmail2("email").withEmail3("email").inGroup(groups.iterator().next()), true);
    }
  }

  @Test
  public void testContactDeleteFromGroup() {

    boolean deleted = false;
    app.contact().homePage();
    Groups allGroups = app.db().groups();
    Contacts before = app.db().contacts();
    for (ContactData deletedContact : before) {
      Groups beforeDeletedGroups = deletedContact.getGroups();
      for (GroupData group : allGroups) {
        if (beforeDeletedGroups.contains(group)) {
          app.contact().deleteContactFromGroup(deletedContact, group);
          deleted = true;
          break;
        }
      }
    }
    }
  }
<commit_msg>Added preconditions into the ContactDeleteFromGroupTests<commit_after>package ru.stqa.pft.addressbook.tests;

import org.openqa.selenium.support.ui.Select;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
import ru.stqa.pft.addressbook.model.ContactData;
import ru.stqa.pft.addressbook.model.Contacts;
import ru.stqa.pft.addressbook.model.GroupData;
import ru.stqa.pft.addressbook.model.Groups;

/**
 * Created by IrinaIv on 6/23/2017.
 */
public class ContactDeleteFromGroupTests extends TestBase {

  @BeforeMethod
  public void ensurePreconditions() {
    app.goTo().groupPage();
    if (app.db().groups().size() == 0) {
      app.goTo().groupPage();
      app.group().create(new GroupData().withName("test3"));
    }
    app.contact().homePage();
    Groups groups = app.db().groups();
    if (app.db().contacts().size() == 0) {
      app.goTo().contactPage();
      app.contact().create(new ContactData().withFirstname("I").withLastname("V")
              .withAddress("ad").withHomephone("1234").withMobilephone("1234")
              .withWorkphone("2345").withAllphones("").withEmail("<EMAIL>")
              .withEmail2("email").withEmail3("email").inGroup(groups.iterator().next()), true);
    }
  }

  @Test
  public void testContactDeleteFromGroup() {
    app.contact().homePage();
    Groups allGroups = app.db().groups();
    Contacts before = app.db().contacts();
    for (ContactData deletedContact : before) {
      Groups beforeDeletedGroups = deletedContact.getGroups();
      for (GroupData group : allGroups) {
        if (beforeDeletedGroups.contains(group)) {
          app.contact().deleteContactFromGroup(deletedContact, group);
        }
        if (!app.db().contacts().contains(group)) {
          app.contact().select(deletedContact, group);

        }
        app.contact().deleteContactFromGroup(deletedContact, group);
        app.contact().goToHomePageWithAllGroups(deletedContact, group);
      }
    }
  }
}


{'fraction_non_alphanumeric': 0.1575081610446137, 'fraction_numerical': 0.013057671381936888, 'mean_word_length': 3.4515738498789346, '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': '7665519', 'n_tokens_mistral': 1143, 'n_tokens_neox': 1110, 'n_words': 170}