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

        Groups groupsAfter = app.group().all();
        assertThat(groupsAfter.size(), equalTo(groupsBefore.size() + 1));

        group.withId(groupsAfter.stream().mapToInt((g) -> g.getId()).max().getAsInt());
        assertThat(groupsAfter, equalTo(groupsBefore.withAdded(group)));
    }

}

@@ -400,25 +400,24 @@
 roupPage();%0A
-%0A
         Grou
@@ -611,17 +611,16 @@
 ertions%0A
-%0A
         
@@ -818,24 +818,24 @@
 etAsInt());%0A
-
         asse
@@ -902,10 +902,488 @@
 %0A    %7D%0A%0A
+    @Test%0A    public void testBadGroupCreation() %7B%0A        app.navigateTo().groupPage();%0A        Groups groupsBefore = app.group().all();%0A%0A        GroupData group = new GroupData()%0A                .withName(%22test'%22 + rnd.getInt(0, 1000));%0A        app.group().create(group);%0A%0A        // assertions%0A        Groups groupsAfter = app.group().all();%0A        assertThat(groupsAfter.size(), equalTo(groupsBefore.size()));%0A        assertThat(groupsAfter, equalTo(groupsBefore));%0A    %7D%0A%0A
 %7D%0A

add test testBadGroupCreation()