<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 java.util.Arrays;
import java.util.stream.Collectors;

import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.MatcherAssert.assertThat;
import static ru.stqa.pft.addressbook.appmanager.ContactHelper.ContactViewPageInfo.*;

/**
 * Created by gis on 04.12.2016.
 */
public class ContactViewTests extends TestBase {

    @BeforeMethod
    public void ensurePreconditions() {
        app.navigateTo().home();
        if (! app.contact().doesExist()) {
            ContactData contactData = ContactData.getWithRandomData();
            app.contact().create(contactData);
        }
    }

    @Test
    public void contactViewTest() {
        app.navigateTo().home();

        int contactId = app.contact().all().getRandom().getId();
        String contactInfoFromViewPageWithoutGroupInfo =
                app.contact().getContactInfoFromViewPageById(contactId, WITHOUT_GROUP_INFO);
        ContactData contactFromEditPage = app.contact().getInfoFromEditFormById(contactId);

        // assertions
        assertThat(contactInfoFromViewPageWithoutGroupInfo,
                equalTo(generateVeiwPageContendBy(contactFromEditPage)));
    }

    private String generateVeiwPageContendBy(ContactData contact) {
        StringBuilder viewPageContentBuilder = new StringBuilder();

        // Name line
        String newLine = Arrays.asList(contact.getFirstname(), contact.getMiddlename(), contact.getLastname())
                .stream().filter((s) -> !s.equals(""))
                .collect(Collectors.joining(" "));
        if (!newLine.equals("")) {
            viewPageContentBuilder.append(newLine + "\n");
        }

        // title<commit_msg>add method removeDoubleNewLine()<commit_after>package ru.stqa.pft.addressbook.tests;

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

import java.util.Arrays;
import java.util.stream.Collectors;

import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.MatcherAssert.assertThat;
import static ru.stqa.pft.addressbook.appmanager.ContactHelper.ContactViewPageInfo.*;

/**
 * Created by gis on 04.12.2016.
 */
public class ContactViewTests extends TestBase {

    @BeforeMethod
    public void ensurePreconditions() {
        app.navigateTo().home();
        if (! app.contact().doesExist()) {
            ContactData contactData = ContactData.getWithRandomData();
            app.contact().create(contactData);
        }
    }

    @Test
    public void contactViewTest() {
        app.navigateTo().home();

        int contactId = app.contact().all().getRandom().getId();
        String contactInfoFromViewPageWithoutGroupInfo =
                app.contact().getContactInfoFromViewPageById(contactId, WITHOUT_GROUP_INFO);
        ContactData contactFromEditPage = app.contact().getInfoFromEditFormById(contactId);

        // assertions
        assertThat(removeDoubleNewLine(contactInfoFromViewPageWithoutGroupInfo),
                equalTo(removeDoubleNewLine(generateVeiwPageContendBy(contactFromEditPage))));
    }

    private String removeDoubleNewLine(String text) {
        return text.replace("\n\n\n", "\n").replace("\n\n", "\n");
    }

    private String generateVeiwPageContendBy(ContactData contact) {
        StringBuilder viewPageContentBuilder = new StringBuilder();

        // Name line
        String newLine = Arrays.asList(contact.getFirstname(), contact.getMiddlename(), contact.getLastname())
                .stream().filter((s) -> !s.equals(""))
                .collect(Collectors.joining(" "));
        if (!newLine.equals("")) {
            viewPageContentBuilder.append(newLine + "\n");
        }

        // title
{'fraction_non_alphanumeric': 0.1179184824403999, 'fraction_numerical': 0.004101512432709562, 'mean_word_length': 3.2183783783783784, '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': '7491833', 'n_tokens_mistral': 1102, 'n_tokens_neox': 1072, 'n_words': 175}