package ru.stqa.pft.addressbook.tests;

import org.apache.xpath.operations.String;
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;

public class ContactEmailsTests extends TestBase {
    @BeforeMethod
    public void ensurePreconditions() {
        app.goToHomePage();
        if (app.contact().all().size() == 0) {
            app.goTo().addNewPage();
            app.contact().create(new ContactData()
                    .withFirstname("Daria").withLastname("Churkina").withPhone("123").withEmail("daria.churkina@inbox.ru").withGroup("Test1"));
            app.goToHomePage();
        }
    }

    @Test
    public void testContactEmails() {
        ContactData contact = app.contact().all().iterator().next();
        ContactData contactInfoFromEditForm = app.contact().infoFromEditForm(contact);
        assertThat(contact.getAllEmails(), equalTo(mergeEmails(contactInfoFromEditForm)));
    }

    private String mergeEmails(ContactData contact) {
        return Arrays.asList(contact.getEmail(), contact.getEmail2(), contact.getEmail3())
                .stream().filter((s) -> !s.equals(""))
                .map(ContactPhoneTests::cleaned)
                .collect(Collectors.joining("\n"));
    }
}

@@ -31,17 +31,19 @@
 k.tests;
-%0A
+%0D%0A%0D
 %0Aimport 
@@ -77,16 +77,17 @@
 .String;
+%0D
 %0Aimport 
@@ -122,16 +122,17 @@
 eMethod;
+%0D
 %0Aimport 
@@ -159,16 +159,17 @@
 ns.Test;
+%0D
 %0Aimport 
@@ -210,17 +210,19 @@
 actData;
-%0A
+%0D%0A%0D
 %0Aimport 
@@ -238,16 +238,17 @@
 .Arrays;
+%0D
 %0Aimport 
@@ -275,17 +275,19 @@
 lectors;
-%0A
+%0D%0A%0D
 %0Aimport 
@@ -327,16 +327,17 @@
 equalTo;
+%0D
 %0Aimport 
@@ -381,17 +381,19 @@
 ertThat;
-%0A
+%0D%0A%0D
 %0Apublic 
@@ -435,16 +435,19 @@
 stBase %7B
+%0D%0A%0D
 %0A    @Be
@@ -456,16 +456,17 @@
 reMethod
+%0D
 %0A    pub
@@ -493,24 +493,25 @@
 nditions() %7B
+%0D
 %0A        app
@@ -518,32 +518,33 @@
 .goToHomePage();
+%0D
 %0A        if (app
@@ -574,16 +574,17 @@
  == 0) %7B
+%0D
 %0A       
@@ -608,24 +608,25 @@
 ddNewPage();
+%0D
 %0A           
@@ -664,16 +664,17 @@
 ctData()
+%0D
 %0A       
@@ -805,24 +805,25 @@
 p(%22Test1%22));
+%0D
 %0A           
@@ -842,16 +842,17 @@
 ePage();
+%0D
 %0A       
@@ -853,23 +853,26 @@
        %7D
+%0D
 %0A    %7D
-%0A
+%0D%0A%0D
 %0A    @Te
@@ -873,16 +873,17 @@
    @Test
+%0D
 %0A    pub
@@ -912,16 +912,40 @@
 ails() %7B
+%0D%0A%09%09app.goToHomePage();%0D
 %0A       
@@ -1005,16 +1005,17 @@
 .next();
+%0D
 %0A       
@@ -1093,16 +1093,17 @@
 ontact);
+%0D
 %0A       
@@ -1185,23 +1185,26 @@
 Form)));
+%0D
 %0A    %7D
-%0A
+%0D%0A%0D
 %0A    pri
@@ -1249,16 +1249,17 @@
 ntact) %7B
+%0D
 %0A       
@@ -1341,16 +1341,17 @@
 mail3())
+%0D
 %0A       
@@ -1397,16 +1397,17 @@
 als(%22%22))
+%0D
 %0A       
@@ -1447,16 +1447,17 @@
 cleaned)
+%0D
 %0A       
@@ -1504,13 +1504,116 @@
 %22));
+%0D
 %0A    %7D
+%0D%0A%09%0D%0A%09public static String cleaned(String phone) %7B%0D%0A        return phone.replaceAll(%22%5C%5Cs%22, %22%22);%0D%0A    %7D%0D
 %0A%7D
-%0A

Add files via upload