package ru.stqa.jft.addressbook.tests;


import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
import ru.stqa.jft.addressbook.model.GroupData;
import ru.stqa.jft.addressbook.model.Groups;


import java.io.*;
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 GroupCreationTests extends TestBase {

    @DataProvider
    public Iterator<Object[]> validGroups() throws IOException {
    List<Object[]> list = new ArrayList<Object[]>();
    BufferedReader reader = new BufferedReader(new FileReader(new File("src/test/resources/groups.csv")));
    String line = reader.readLine();
    while(line != null) {
        String split[] = line.split(";");
        list.add(new Object[] {new GroupData().withName(split[0]).withHeader(split[1]).withFooter(split[2])});
        line = reader.readLine();
    }
    return list.iterator();
    }

    @Test(dataProvider = "validGroups")
    public void testGroupCreation(GroupData group) {
        app.goTo().groupPage();
        Groups before = app.group().all();
        app.group().create(group);
        assertThat(app.group().count(), equalTo(before.size() + 1));
        Groups after = app.group().all();
        assertThat(after, equalTo(
                before.withAdded(group.withId(after.stream().mapToInt((g) -> g.getId()).max().getAsInt()))));

    }

    @Test (enabled = false)
    public void testBadGroupCreation() {
        app.goTo().groupPage();
        Groups before = app.group().all();
        GroupData group = new GroupData().withName("test'");
        app.group().create(group);
        assertThat(app.group().count(), equalTo(before.size()));
        Groups after = app.group().all();
        assertThat(after, equalTo(before));
    }
}

@@ -30,24 +30,153 @@
 ok.tests;%0A%0A%0A
+import com.sun.xml.internal.org.jvnet.fastinfoset.stax.LowLevelFastInfosetStreamWriter;%0Aimport com.thoughtworks.xstream.XStream;%0A
 import org.t
@@ -433,16 +433,52 @@
 il.List;
+%0Aimport java.util.stream.Collectors;
 %0A%0Aimport
@@ -864,17 +864,38 @@
 ups.
-csv
+xml
 %22)));%0A
+    String xml = %22%22;%0A
     
@@ -965,193 +965,231 @@
     
-String split%5B%5D = line.split(%22;%22);%0A        list.add(new Object%5B%5D %7Bnew GroupData().withName(split%5B0%5D).withHeader(split%5B1%5D).withFooter(split%5B2%5D)%7D);%0A        line = reader.readLine(
+xml+= line;%0A        line = reader.readLine();%0A    %7D%0A        XStream xstream = new XStream();%0A        xstream.processAnnotations(GroupData.class);%0A        List%3CGroupData%3E groups = (List%3CGroupData%3E) xstream.fromXML(xml
 );%0A    
-%7D%0A
     
@@ -1195,20 +1195,89 @@
  return 
-list
+groups.stream().map((g) -%3E new Object%5B%5D %7Bg%7D).collect(Collectors.toList())
 .iterato

read data from xml file (groups)