package ru.sfwt.mt.addressbook.tests;

import org.testng.annotations.Test;
import ru.sfwt.mt.addressbook.model.AddressData;
import ru.sfwt.mt.addressbook.model.Addresses;

import java.io.File;

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

public class AddressCreationTests extends TestBase{

  @Test
  public void testAddressCreation() {
    app.goTo().homePage();
    Addresses before = app.contact().all();
    app.goTo().addressCreationPage();
    //AddressData address = new AddressData().withFirstname("name").withLastname("last").withGroup("test1");
    File photo = new File("/src/test/resources/images.jpg");
    AddressData address = new AddressData().withFirstname("name").withLastname("last").withPhoto(photo).withGroup("test1");
    app.contact().create(address);
    app.goTo().homePage();
    assertThat(app.contact().count(), equalTo(before.size() +1));
    Addresses after = app.contact().all();
    assertThat(after, equalTo(before.withAdded(
            address.withId(after.stream().mapToInt((ad) -> ad.getId()).max().getAsInt()))));
  }

  @Test (enabled = false)
  public void testBadAddressCreation() {
    app.goTo().homePage();
    Addresses before = app.contact().all();
    app.goTo().addressCreationPage();
    AddressData address = new AddressData().withFirstname("name'").withLastname("last").withGroup("test1");
    app.contact().create(address);
    app.goTo().homePage();
    assertThat(app.contact().count(), equalTo(before.size()));
    Addresses after = app.contact().all();
    assertThat(after, equalTo(before));
  }

  @Test (enabled = false)
  public void testCurrentDir() {
    File currentDir = new File(".");
    System.out.println(currentDir.getAbsolutePath());
    File photo = new File("/src/test/resources/images.jpg");
    System.out.println(photo.getAbsolutePath());
    System.out.println(photo.exists());
  }

}

@@ -28,24 +28,68 @@
 ook.tests;%0A%0A
+import org.testng.annotations.DataProvider;%0A
 import org.t
@@ -229,16 +229,94 @@
 io.File;
+%0Aimport java.util.ArrayList;%0Aimport java.util.Iterator;%0Aimport java.util.List;
 %0A%0Aimport
@@ -468,20 +468,535 @@
 se%7B%0A%0A  @
-Test
+DataProvider%0A  public Iterator%3CObject%5B%5D%3E validContact() %7B%0A    List%3CObject%5B%5D%3E list = new ArrayList%3CObject%5B%5D%3E();%0A    list.add(new Object%5B%5D %7Bnew AddressData().withFirstname(%22name1%22).withLastname(%22last1%22).withGroup(%22test1%22)%7D);%0A    list.add(new Object%5B%5D %7Bnew AddressData().withFirstname(%22name2%22).withLastname(%22last2%22).withGroup(%22test1%22)%7D);%0A    list.add(new Object%5B%5D %7Bnew AddressData().withFirstname(%22name2%22).withLastname(%22last2%22).withGroup(%22test1%22)%7D);%0A    return list.iterator();%0A%0A  %7D%0A%0A  @Test(dataProvider = %22validContact%22)
 %0A  publi
@@ -1014,32 +1014,51 @@
 AddressCreation(
+AddressData address
 ) %7B%0A    app.goTo
@@ -1162,110 +1162,477 @@
     
-//AddressData address = new AddressData().withFirstname(%22name%22).withLastname(%22last%22).withGroup(%22test1%22
+app.contact().create(address);%0A    app.goTo().homePage();%0A    assertThat(app.contact().count(), equalTo(before.size() +1));%0A    Addresses after = app.contact().all();%0A    assertThat(after, equalTo(before.withAdded(%0A            address.withId(after.stream().mapToInt((ad) -%3E ad.getId()).max().getAsInt()))));%0A  %7D%0A  @Test%0A  public void testAddressCreationPhoto() %7B%0A    app.goTo().homePage();%0A    Addresses before = app.contact().all();%0A    app.goTo().addressCreationPage(
 );%0A 

Create @DataProvider in AddressCreationTests