package ru.stqua.pft.addressbook.tests;

import org.testng.Assert;
import org.testng.annotations.Test;
import ru.stqua.pft.addressbook.model.GroupData;

import java.util.HashSet;
import java.util.List;

public class GroupCreationTests extends TestBase{

  @Test
  public void testGroupCreation() {
    app.getNavigationHelper().gotoGroupPage();
    List<GroupData> before = app.getGroupHelper().getGroupList();
    GroupData group = new GroupData("test1", null, null);
    app.getGroupHelper().createGroup(group);
    List<GroupData> after = app.getGroupHelper().getGroupList();

    Assert.assertEquals(after.size(), before.size() + 1);

    int max = 0;
    for (GroupData g : after){
      if (g.getId() > max){
        max = g.getId();
      }
    }
    group.setId(max);
    before.add(group);
    Assert.assertEquals(new HashSet<Object>(before), new HashSet<Object>(after));
  }

}

@@ -445,17 +445,17 @@
 ta(%22test
-1
+2
 %22, null,
@@ -640,138 +640,105 @@
     
-int max = 0;%0A    for (GroupData g : after)%7B%0A      if (g.getId() %3E max)%7B%0A        max = g.getId();%0A      %7D%0A    %7D%0A    group.s
+group.setId(after.stream().max((o1, o2) -%3E Integer.compare(o1.getId(), o2.getId())).get().g
 etId(
-max
+)
 );%0A 

Add Example 9 Lesson 4