package ru.stqa.pft.addressbook.tests;

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

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

public class GroupCreationTests extends TestBase {

    @Test
    public void testGroupCreation() {
        app.navigateTo().groupPage();
        Groups groupsBefore = app.group().all();

        GroupData group = new GroupData()
                .withName("test" + rnd.getInt(0, 1000));
        app.group().create(group);

        // assertions
        assertThat(app.group().getGroupCount(), equalTo(groupsBefore.size() + 1));
        Groups groupsAfter = app.group().all();
        group.withId(groupsAfter.stream().mapToInt((g) -> g.getId()).max().getAsInt());
        assertThat(groupsAfter, equalTo(groupsBefore.withAdded(group)));
    }

    @Test
    public void testBadGroupCreation() {
        app.navigateTo().groupPage();
        Groups groupsBefore = app.group().all();

        GroupData group = new GroupData()
                .withName("test'" + rnd.getInt(0, 1000));
        app.group().create(group);

        // assertions
        assertThat(app.group().getGroupCount(), equalTo(groupsBefore.size()));
        Groups groupsAfter = app.group().all();
        assertThat(groupsAfter, equalTo(groupsBefore));
    }

}

@@ -29,24 +29,68 @@
 ook.tests;%0A%0A
+import org.testng.annotations.DataProvider;%0A
 import org.t
@@ -203,24 +203,129 @@
 el.Groups;%0A%0A
+import java.util.ArrayList;%0Aimport java.util.Iterator;%0Aimport java.util.List;%0Aimport java.util.Objects;%0A%0A
 import stati
@@ -476,147 +476,429 @@
    @
-Test%0A    public void testGroupCreation() %7B%0A        app.navigateTo().groupPage();%0A        Groups groupsBefore = app.group().all(
+DataProvider%0A    public Iterator%3CObject%5B%5D%3E validGroups() %7B%0A        List%3CObject%5B%5D%3E list = new ArrayList%3CObject%5B%5D%3E();%0A        list.add(new Object%5B%5D %7Bnew GroupData().withName(%22t1%22).withHeader(%22h1%22).withFooter(%22f1%22)%7D);%0A        list.add(new Object%5B%5D %7Bnew GroupData().withName(%22t2%22).withHeader(%22h1%22).withFooter(%22f1%22)%7D);%0A        list.add(new Object%5B%5D %7Bnew GroupData().withName(%22t3%22).withHeader(%22h1%22).withFooter(%22f1%22)%7D
 );%0A
-%0A
         
 Grou
@@ -897,99 +897,220 @@
     
-GroupData group = new GroupData()%0A                .withName(%22test%22 + rnd.getInt(0, 1000)
+return list.iterator();%0A    %7D%0A%0A    @Test(dataProvider = %22validGroups%22)%0A    public void testGroupCreation(GroupData group) %7B%0A        app.navigateTo().groupPage();%0A        Groups groupsBefore = app.group().all(
 );%0A
+%0A
     

use dataProvider to in GroupCreationTests