package ru.stqa.pft.addressbook.tests;

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

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.MatcherAssert.assertThat;

public class ContactCreationTest extends TestBase {

  @DataProvider
  public Iterator<Object[]> validContacts() throws IOException {
    List<Object[]> list = new ArrayList<Object[]>();
    BufferedReader reader = new BufferedReader(new FileReader(new File("src/test/resources/contacts.csv")));
    String line = reader.readLine();
    while (line != null) {
      String[] split = line.split(";");
      list.add(new Object[] {new ContactData().withFirstname(split[0]).withLastname(split[1])
      .withAddress(split[2]).withHomephone(split[3]).withMobilephone(split[4]).withWorkphone(split[5])
      .withEmai1(split[6]).withEmail2(split[7]).withEmail3(split[8]).withGroup(split[9])});
      line = reader.readLine();
    }
    return list.iterator();
  }


  @Test (dataProvider = "validContacts")
  public void testContactCreation(ContactData contact) {
    app.goTo().homePage();
    Contacts before = app.contact().all();
    app.contact().initContactCreation();
    app.contact().create(contact, true);
    assertThat(app.contact().count(), equalTo(before.size() + 1));
    Contacts after = app.contact().all();
    assertThat(after, equalTo(
            before.withAdded(contact.withId(after.stream().mapToInt((c) -> c.getId()).max().getAsInt()))));
  }

  @Test
  public void testContactCreationPhoto() {
    app.goTo().homePage();
    Contacts before = app.contact().all();
    app.contact().initContactCreation();
    File photo = new File("src/test/resources/photo1.jpg");
    ContactData contact = new ContactData()
            .withFirstname("Kate").withLastname("Test").withPhoto(photo).withAddress("Tests").withHomephone("111")
            .withMobilephone("222").withWorkphone("333").withEmai1("anna@gmail.com")
            .withGroup("[none]");
    app.contact().create(contact, true);
    assertThat(app.contact().count(), equalTo(before.size() + 1));
    Contacts after = app.contact().all();
    assertThat(after, equalTo(
            before.withAdded(contact.withId(after.stream().mapToInt((c) -> c.getId()).max().getAsInt()))));
  }

}


@@ -927,17 +927,16 @@
 Object%5B%5D
- 
 %7Bnew Con
@@ -993,16 +993,24 @@
 lit%5B1%5D)%0A
+        
       .w
@@ -1104,16 +1104,24 @@
 lit%5B5%5D)%0A
+        
       .w
@@ -1280,49 +1280,8 @@
 %7D%0A%0A%0A
-  @Test (dataProvider = %22validContacts%22)%0A
   pu

Reformate code in ContactCreationTest.