package ru.stqa.pft.addressbook.tests;

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

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

public class GroupCreationTests extends TestBase {

    @Test
    public void testGroupCreation() {
        app.getNavigationHelper().goToGroupsPage();
        List<GroupData> before = app.getGroupHelper().getGroupList();
        app.getGroupHelper().initGroupCreation();
        GroupData group = new GroupData();
            group.setName("my group");
            group.setHeader("my header");
            group.setFooter("my footer");
        app.getGroupHelper().fillGroupForm(group);
        app.getGroupHelper().submitGroupCreation();
        app.getGroupHelper().returnToGroupsPage();
        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();
            }
        }

        Comparator<? super GroupData> byId = new Comparator<GroupData>() {
            @Override
            public int compare(GroupData o1, GroupData o2) {
                return Integer.compare(o1.getId(), o2.getId());
            }
        };
        
        int max2 = after.stream().max(byId).get().getId();
        group.setId(max);
        before.add(group);


        Assert.assertEquals(new HashSet<Object>(before), new HashSet<Object>(after));

        app.getSessionHelper().logout();
    }

}

@@ -148,37 +148,8 @@
 a;%0A%0A
-import java.util.Comparator;%0A
 impo
@@ -170,16 +170,16 @@
 ashSet;%0A
+
 import j
@@ -509,36 +509,32 @@
 Data();%0A        
-    
 group.setName(%22m
@@ -544,36 +544,32 @@
 roup%22);%0A        
-  
-  
 group.setHeader(
@@ -578,28 +578,24 @@
 y header%22);%0A
-    
         grou
@@ -918,484 +918,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%0A        Comparator%3C? super GroupData%3E byId = new Comparator%3CGroupData%3E() %7B%0A            @Override%0A            public int compare(GroupData o1, GroupData o2) %7B%0A                return Integer.compare(o1.getId(), o2.getId());%0A            %7D%0A        %7D;%0A        %0A        int max2 = after.stream().max(byId).get().getId();%0A        group.setId(max
+group.setId(after.stream().max((o1, o2) -%3E Integer.compare(o1.getId(), o2.getId())).get().getId()
 );%0A 

change calculation method to lambda