package com.ksu.addressbook.tests;

import com.ksu.addressbook.model.ContactData;
import com.ksu.addressbook.model.Contacts;
import com.ksu.addressbook.model.GroupData;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;

import static org.hamcrest.CoreMatchers.*;
import static org.hamcrest.MatcherAssert.*;
import static org.testng.Assert.assertEquals;

public class ContactCreationTests extends TestBase{

    String groupForContact;

    @BeforeMethod
    public void ensurePreconditions(){
        groupForContact = "GroupForContact";
        app.goTo().groupPage();
        if(! app.group().isThereASpecificGroup(groupForContact)){
            app.group().create(new GroupData().withName(groupForContact));
        }
        app.goTo().homePage();
    }

    @Test(enabled = true)
    public void testContactCreation() {
        Contacts before = app.contact().all();
        ContactData contact = new ContactData().withFirstname("Fekla").withLastname("Pupyrkina").withNickname("FeklaP").
                withAddress("The Mars, 1st street").withFax("000").withMobilePhone("111").withHomePhone("222").
                withWorkPhone("333").withEmail("fekla.pupyrkina@ino.planet").withGroup(groupForContact);
        app.contact().create(contact);
        assertEquals(app.contact().getContactCount(), before.size() + 1);
        Contacts after = app.contact().all();
        assertThat(after, equalTo(before.withAdded(contact.withId(after.stream().mapToInt(g -> g.getId()).max().getAsInt()))));

    }

}

@@ -29,16 +29,87 @@
 tests;%0A%0A
+import com.google.gson.Gson;%0Aimport com.google.gson.reflect.TypeToken;%0A
 import c
@@ -311,1002 +311,1596 @@
 ons.
-Test;%0A%0Aimport static org.hamcrest.CoreMatchers.*;%0Aimport static org.hamcrest.MatcherAssert.*;%0Aimport static org.testng.Assert.assertEquals;%0A%0Apublic class ContactCreationTests extends TestBase%7B%0A%0A    String groupForContact;%0A%0A    @BeforeMethod%0A    public void ensurePreconditions()%7B%0A        groupForContact = %22GroupForContact%22;%0A        app.goTo().groupPage();%0A        if(! app.group().isThereASpecificGroup(groupForContact))%7B%0A            app.group().create(new GroupData().withName(groupForContact));%0A        %7D%0A        app.goTo().homePage();%0A    %7D%0A%0A    @Test(enabled = true)%0A    public void testContactCreation() %7B%0A        Contacts before = app.contact().all();%0A        ContactData contact = new ContactData().withFirstname(%22Fekla%22).withLastname(%22Pupyrkina%22).withNickname(%22FeklaP%22).%0A                withAddress(%22The Mars, 1st street%22).withFax(%22000%22).withMobilePhone(%22111%22).withHomePhone(%22222%22).%0A                withWorkPhone(%22333%22).withEmail(%22fekla.pupyrkina@ino.planet%22).withGroup(groupForContact
+DataProvider;%0Aimport org.testng.annotations.Test;%0A%0Aimport java.io.BufferedReader;%0Aimport java.io.File;%0Aimport java.io.FileReader;%0Aimport java.io.IOException;%0Aimport java.security.Provider;%0Aimport java.util.Iterator;%0Aimport java.util.List;%0Aimport java.util.stream.Collectors;%0A%0Aimport static org.hamcrest.CoreMatchers.*;%0Aimport static org.hamcrest.MatcherAssert.*;%0Aimport static org.testng.Assert.assertEquals;%0A%0Apublic class ContactCreationTests extends TestBase%7B%0A%0A    @DataProvider%0A    Iterator%3CObject%5B%5D%3E validContactsFromJson() throws IOException %7B%0A        BufferedReader reader = new BufferedReader(new FileReader(new File(%22src/test/resources/contactData.json%22)));%0A        String json = %22%22;%0A        String line = reader.readLine();%0A        while(line != null)%7B%0A            json += line;%0A            line = reader.readLine();%0A        %7D%0A        Gson gson = new Gson();%0A        List%3CContactData%3E contacts = gson.fromJson(json, new TypeToken%3CList%3CContactData%3E%3E()%7B%7D.getType());%0A        return contacts.stream().map((c) -%3E new Object%5B%5D%7Bc%7D).collect(Collectors.toList()).iterator();%0A    %7D%0A%0A    String groupForContact;%0A%0A    @BeforeMethod%0A    public void ensurePreconditions()%7B%0A        groupForContact = %22GroupForContact%22;%0A        app.goTo().groupPage();%0A        if(! app.group().isThereASpecificGroup(groupForContact))%7B%0A            app.group().create(new GroupData().withName(groupForContact));%0A        %7D%0A        app.goTo().homePage();%0A    %7D%0A%0A    @Test(dataProvider = %22validContactsFromJson%22)%0A    public void testContactCreation(ContactData contact) %7B%0A        Contacts before = app.contact().all(
 );%0A 
@@ -2151,14 +2151,14 @@
 Int(
-g
+c
  -%3E 
-g
+c
 .get

Make contactCreation test parameterized