/**
 *  A class to test the creation of a new group
 */

package ru.stqa.pft.addressbook.tests;

import org.testng.Assert;
import org.testng.annotations.BeforeMethod;
import ru.stqa.pft.addressbook.data.GroupData;

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

import java.util.Set;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.core.IsEqual.equalTo;

public class GroupCreationTests extends BaseTests {
    @BeforeMethod
    public void ensurePrecondition() {
        app.getNavigationHelper().gotoGroupPage();
    }

    @Test
    // Base test creation group
    public static void testGroupCreationVer1() {
        Set<GroupData> beforeGroupSet = app.getGroupHelper().getGroupSet();

        GroupData group = new GroupData();

        app.getGroupHelper().initGroupCreation();
        app.getGroupHelper().fillGroupForm(group);
        app.getGroupHelper().submitModification();

        app.getNavigationHelper().returnToGroupPage();

        Set<GroupData> afterGroupSet = app.getGroupHelper().getGroupSet();

        // Check on the number of elements
        Assert.assertEquals(afterGroupSet.size(), beforeGroupSet.size() + 1);

        // Find the maximum Id and assign the created element
        for (GroupData g : afterGroupSet) {
            if (g.getGroupId() > group.getGroupId()) {
                group.setGroupId(g.getGroupId());
            }
        }
        //group.setGroupId(afterGroupSet.stream().mapToInt((g) -> g.getGroupId()).max().getAsInt());

        // Attaching a created element
        beforeGroupSet.add(group);

        // Check elements for identity verification
        Assert.assertEquals(beforeGroupSet, afterGroupSet);
    }

    @Test
    // Test creation group fluent implementation
    public static void testGroupCreationVer2() {
        Groups beforeGroupSet = app.getGroupHelper().all();

        GroupData group = new GroupData();

        app.getGroupHelper().initGroupCreation();
        app.getGroupHelper().fillGroupForm(group);
        app.getGroupHelper().submitModification();

        app.getNavigationHelper().returnToGroupPage();

        Groups afterGroupSet = app.getGroupHelper().all();

        // Check on the number of elements
        assertThat(afterGroupSet.size(), equalTo(beforeGroupSet.size() + 1));

        // Check elements for identity verification
        assertThat(afterGroupSet, equalTo(beforeGroupSet.withAdded(group.setGroupId(afterGroupSet.stream().mapToInt((g) -> g.getGroupId()).max().getAsInt()))));
    }
}

@@ -2633,12 +2633,835 @@
 %0D%0A    %7D%0D
+%0A%0D%0A    @Test%0D%0A    // Test creation group with the unacceptable title%0D%0A    public static void testBadGroupCreationVer1() %7B%0D%0A        Set%3CGroupData%3E beforeGroupSet = app.getGroupHelper().getGroupSet();%0D%0A%0D%0A        GroupData group = new GroupData().setGroupName(%22BadName'%22);%0D%0A%0D%0A        app.getGroupHelper().initGroupCreation();%0D%0A        app.getGroupHelper().fillGroupForm(group);%0D%0A        app.getGroupHelper().submitModification();%0D%0A%0D%0A        app.getNavigationHelper().returnToGroupPage();%0D%0A%0D%0A        Set%3CGroupData%3E afterGroupSet = app.getGroupHelper().getGroupSet();%0D%0A%0D%0A        // Check on the number of elements%0D%0A        Assert.assertEquals(app.getGroupHelper().getGroupCount(), beforeGroupSet.size());%0D%0A%0D%0A        // Check elements for identity verification%0D%0A        Assert.assertEquals(beforeGroupSet, afterGroupSet);%0D%0A    %7D%0D
 %0A%7D%0D%0A

Create method testBadGroupCreation