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

import org.hamcrest.MatcherAssert;
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;
import ru.stqa.pft.addressbook.tests.TestBase;
import static org.hamcrest.CoreMatchers.*;
import static org.hamcrest.MatcherAssert.*;
/**
 * Created by user on 24.09.17.
 */
public class ContactAddGroup extends TestBase {

    @BeforeMethod
    public void beforeMethodGroup(){
        app.goTo().groupPage();
        if (app.db().groups().size() == 0){
            app.group().create(new GroupData().withName("group1"));
        }
    }

    @BeforeMethod
    public void beforeMethodContact(){
        app.goTo().homePage();
        if (app.db().contacts().size() == 0){
            app.goTo().createContact();
            app.contact().create(new ContactData().
                    withFname("Firstname").withMname("MiddleName").withLname("LastName").
                    withPhone1("777 334 52 31").withEmail1("<EMAIL>"));
        }
    }

    @BeforeMethod(dependsOnMethods = "beforeMethodContact",
            description = "Проверка, что есть контакт, которому можно добавить группу, иначе создаем контакт")
    public void beforeMethodContactForGroup(){
        app.goTo().homePage();
        Contacts contacts = app.db().contacts();
        Groups groups = app.db().groups();
        int i = 0;
        for (ContactData contact : contacts){
            if (contact.getGroups().size() == groups.size())
                i++;
        }
        if (i == contacts.size()){
            app.goTo().createContact();
            app.contact().create(new ContactData().
                    withFname("Firstname").withMname("MiddleName").withLname("LastName").
                    withPhone1("777 334 52 31").withEmail1("<EMAIL>"));
        }
    }


    @Test
    public void testContactAddGroup() throws InterruptedException {
        Contacts contacts = app.db().contacts();
        Groups groups = app.db().groups();

        // берем контакт, у которого не все группы
        ContactData editedContact = app.contact().searchContactForGroup(contacts, groups);

        //ContactData editedContact = contacts.iterator().next();
        GroupData group = app.contact().groupForContact(editedContact, groups);

        // достаём из БД изменяемый контакт
        ContactData contactBefore = app.db().contact(editedContact.getId());

        app.goTo().homePage();
        app.contact().contactAddGroup(editedContact, group);

        // достаём из БД измененный контакт
        ContactData contactAfter = app.db().contact(editedContact.getId());

        assertThat(contactBefore.getGroups(),equalTo(contactAfter.getGroups().without(group)));

    }

}<commit_msg>add group<commit_after>package ru.stqa.pft.addressbook.tests.contact;

import org.hamcrest.MatcherAssert;
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;
import ru.stqa.pft.addressbook.tests.TestBase;
import static org.hamcrest.CoreMatchers.*;
import static org.hamcrest.MatcherAssert.*;
/**
 * Created by user on 24.09.17.
 */
public class ContactAddGroup extends TestBase {

    @BeforeMethod
    public void beforeMethodGroup(){
        app.goTo().groupPage();
        if (app.db().groups().size() == 0){
            app.group().create(new GroupData().withName("group1"));
        }
    }

    @BeforeMethod
    public void beforeMethodContact(){
        app.goTo().homePage();
        if (app.db().contacts().size() == 0){
            app.goTo().createContact();
            app.contact().create(new ContactData().
                    withFname("Firstname").withMname("MiddleName").withLname("LastName").
                    withPhone1("777 334 52 31").withEmail1("<EMAIL>"));
        }
    }

    @BeforeMethod(dependsOnMethods = "beforeMethodContact",
            description = "Проверка, что есть контакт, которому можно добавить группу, иначе создаем контакт")
    public void beforeMethodContactForGroup(){
        app.goTo().homePage();
        Contacts contacts = app.db().contacts();
        Groups groups = app.db().groups();
        int i = 0;
        for (ContactData contact : contacts){
            if (contact.getGroups().size() == groups.size())
                i++;
        }
        if (i == contacts.size()){
            app.goTo().createContact();
            app.contact().create(new ContactData().
                    withFname("Firstname").withMname("MiddleName").withLname("LastName").
                    withPhone1("777 334 52 31").withEmail1("<EMAIL>"));
        }
    }


    @Test
    public void testContactAddGroup() throws InterruptedException {
        Contacts contacts = app.db().contacts();
        Groups groups = app.db().groups();

        // берем контакт, у которого не все группы
        ContactData editedContact = app.contact().searchContactForGroup(contacts, groups);

        // выбираем группу, которой еще нет у контакта
        GroupData group = app.contact().groupForContact(editedContact, groups);

        // достаём из БД изменяемый контакт
        ContactData contactBefore = app.db().contact(editedContact.getId());

        app.goTo().homePage();
        app.contact().contactAddGroup(editedContact, group);

        // достаём из БД измененный контакт
        ContactData contactAfter = app.db().contact(editedContact.getId());

        assertThat(contactBefore.getGroups(),equalTo(contactAfter.getGroups().without(group)));

    }

}
{'fraction_non_alphanumeric': 0.13733538566786385, 'fraction_numerical': 0.011629895672994698, 'mean_word_length': 2.7875647668393784, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, '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': '538973', 'n_tokens_mistral': 1756, 'n_tokens_neox': 1705, 'n_words': 317}