package ru.stqa.pft.addressbook.tests;

import org.testng.Assert;
import org.testng.annotations.Test;
import ru.stqa.pft.addressbook.appmanager.HelperBase.FormAction;
import ru.stqa.pft.addressbook.model.ContactData;

import java.util.Comparator;
import java.util.HashSet;
import java.util.List;

/**
 * Created by gis on 09.11.2016.
 */
public class ContactModificationTests extends TestBase {

    @Test
    public void testContactModification() {
        app.getNavigationHelper().gotoHome();
        if (! app.getContactHelper().isThereAContact()) {
            ContactData contactData = new ContactData();
            contactData
                    .setFirstname("Testname")
                    .setLastname("Testsurname");
            app.getContactHelper().createContact(contactData);
        }

        List<ContactData> contactsBefore = app.getContactHelper().getContactList();

        ContactData contact = new ContactData();
        contact
                .setId(contactsBefore.get(contactsBefore.size() - 1).getId())
                .setFirstname("Foo")
                .setLastname("Khun")
                .setTitle("Ms.")
                .setAddress("Flat D, 6/F, Golden Industrial Center, Block 4, 182-190 Tai Lin Pai Road, Kwai Chung")
                .setHomePhone("(852) 2877-8933")
                .setEmail("hongkong@ihg.com");

        app.getContactHelper().modifyContact(contactsBefore.size() - 1, contact);

        List<ContactData> contactsAfter = app.getContactHelper().getContactList();
        Assert.assertEquals(contactsAfter.size(), contactsBefore.size());

        contactsBefore.remove(contactsBefore.size() - 1);
        contactsBefore.add(contact);
        Comparator<? super ContactData> byId = (g1, g2) -> Integer.compare(g1.getId(), g2.getId());
        contactsBefore.sort(byId);
        contactsAfter.sort(byId);
        Assert.assertEquals(contactsAfter, contactsBefore);
    }
}

@@ -59,16 +59,103 @@
 Assert;%0A
+import org.testng.annotations.BeforeClass;%0Aimport org.testng.annotations.BeforeMethod;%0A
 import o
@@ -182,16 +182,16 @@
 s.Test;%0A
-
 import r
@@ -481,20 +481,28 @@
 %7B%0A%0A    @
-Test
+BeforeMethod
 %0A    pub
@@ -514,31 +514,27 @@
 oid 
-testContactModifica
+ensurePrecondi
 tion
+s
 () %7B
@@ -887,16 +887,76 @@
       %7D%0A
+    %7D%0A%0A    @Test%0A    public void testContactModification() %7B
 %0A       

add method ensurePreconditions() to class ContactModificationTests