package ru.stqa.pft.addressbook.tests;

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

import java.util.List;

/**
 * Created by gis on 07.11.2016.
 */
public class ContactDeletionTests extends TestBase {

    @Test
    public void testContactDeletion() {
        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();
        app.getContactHelper().selectContact(contactsBefore.size() - 1);
        app.getContactHelper().deleteSelectedContract();
        app.getAlertHelper().accept();
        app.getNavigationHelper().gotoHome();

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

        contactsBefore.remove(contactsBefore.size() - 1);
        Assert.assertEquals(contactsBefore, contactsAfter);
    }
}

@@ -59,16 +59,60 @@
 Assert;%0A
+import org.testng.annotations.BeforeMethod;%0A
 import o
@@ -314,20 +314,28 @@
 %7B%0A%0A    @
-Test
+BeforeMethod
 %0A    pub
@@ -347,27 +347,27 @@
 oid 
-testContactDele
+ensurePrecondi
 tion
+s
 () %7B
@@ -720,16 +720,72 @@
       %7D%0A
+    %7D%0A%0A    @Test%0A    public void testContactDeletion() %7B
 %0A       

add method ensurePreconditions() to contact deletion tests