package com.example.tests;

import java.util.Collections;
import java.util.List;
import static org.testng.Assert.assertEquals;

import org.testng.annotations.Test;

public class GroupCreationTests extends TestBase {
	
	@Test
	public void testNonEmptyGroupCreation() throws Exception {
		app.getNavigationHelper().openMainPage();
		app.getNavigationHelper().gotoGroupsPage();

		// save old state
		List<GroupData> initialGroups = app.getGroupHelper().getGroups();

		// actions
		GroupData group = new GroupData();
		group.name = "test-group-4";
		group.header = "HEADER\ntest-group-4";
		group.footer = "FOOTER\ntest-group-4";
		app.getGroupHelper().initGroupCreation();
		app.getGroupHelper().fillGroupForm(group);
		app.getGroupHelper().submitGroupForm();
		app.getGroupHelper().returnToGroupsPage();

		// get new state
		List<GroupData> newGroups = app.getGroupHelper().getGroups();

		// compare states
		initialGroups.add(group);
		Collections.sort(initialGroups);
		assertEquals(newGroups, initialGroups);
	}

	@Test
	public void testEmptyGroupCreation() throws Exception {
		app.getNavigationHelper().openMainPage();
		app.getNavigationHelper().gotoGroupsPage();

		// save initial groups
		List<GroupData> initialGroups = app.getGroupHelper().getGroups();

		// actions
		GroupData group = new GroupData("", "", "");
		app.getGroupHelper().initGroupCreation();
		app.getGroupHelper().fillGroupForm(group);
		app.getGroupHelper().submitGroupForm();
		app.getGroupHelper().returnToGroupsPage();

		// save new groups
		List<GroupData> newGroups = app.getGroupHelper().getGroups();

		// compare states
		initialGroups.add(group);
		Collections.sort(initialGroups);
		assertEquals(newGroups, initialGroups);
	}
}

@@ -17,24 +17,52 @@
 ple.tests;%0A%0A
+import java.util.ArrayList;%0A
 import java.
@@ -96,21 +96,74 @@
 va.util.
-List;
+Iterator;%0Aimport java.util.List;%0Aimport java.util.Random;%0A
 %0Aimport 
@@ -198,24 +198,68 @@
 ertEquals;%0A%0A
+import org.testng.annotations.DataProvider;%0A
 import org.t
@@ -338,270 +338,165 @@
 e %7B%0A
-%09
 %0A%09@
-Test%0A%09public void testNonEmptyGroupCreation() throws Exception %7B%0A%09%09app.getNavigationHelper().openMainPage();%0A%09%09app.getNavigationHelper().gotoGroupsPage();%0A%0A%09%09// save old state%0A%09%09List%3CGroupData%3E initialGroups = app.getGroupHelper().getGroups
+DataProvider%0A%09public Iterator%3CObject%5B%5D%3E randomValidGroupGenerator() %7B%0A%09%09List%3CObject%5B%5D%3E list = new ArrayList%3CObject%5B%5D%3E
 ();%0A
-%0A
 %09%09
-// actions%0A
+for (int i = 0; i %3C 5; i++) %7B%0A%09
 %09%09Gr
@@ -526,24 +526,25 @@
 upData();%0A%09%09
+%09
 group.name =
@@ -548,24 +548,33 @@
 e = 
-%22test-group-4%22
+generateRandomString()
 ;%0A
+%09
 %09%09gr
@@ -590,32 +590,33 @@
 r = 
-%22HEADER%5Cntest-group-4%22
+generateRandomString()
 ;%0A
+%09
 %09%09gr
@@ -632,428 +632,319 @@
 r = 
-%22FOOTER%5Cntest-group-4%22;%0A%09%09app.getGroupHelper().initGroupCreation();%0A%09%09app.getGroupHelper().fillGroupForm(
+generateRandomString();%0A%09%09%09list.add(new Object%5B%5D %7B 
 group
+ %7D
 );%0A%09%09
-app.getGroupHelper().submitGroupF
+%7D%0A%09%09return list.iterat
 or
-m
 ();%0A%09
-%09app.getGroupHelper().returnToGroupsPage();%0A%0A%09%09// get new state%0A%09%09List%3CGroupData%3E newGroups = app.getGroupHelper().getGroups()
+%7D%0A%0A%09public String generateRandomString() %7B%0A%09%09Random rnd = new Random();%0A%09%09if (rnd.nextInt(3) == 0) %7B%0A%09%09%09return %22%22
 ;%0A
-%0A
 %09%09
-// compare states%0A%09%09initialGroups.add(group);%0A%09%09Collections.sort(initialGroups);%0A%09%09assertEquals(newGroups, initialGroups);%0A%09%7D%0A%0A%09@Test
+%7D else %7B%0A%09%09%09return %22test %22 + rnd.nextInt();%0A%09%09%7D%0A%09%7D%0A%0A%09@Test(dataProvider = %22randomValidGroupGenerator%22)
 %0A%09pu
@@ -961,13 +961,13 @@
 test
-Empty
+Valid
 Grou
@@ -976,16 +976,31 @@
 reation(
+GroupData group
 ) throws
@@ -1117,22 +1117,17 @@
 ave 
-initial groups
+old state
 %0A%09%09L
@@ -1209,55 +1209,8 @@
 ons%0A
-%09%09GroupData group = new GroupData(%22%22, %22%22, %22%22);%0A
 %09%09ap
@@ -1391,23 +1391,21 @@
 %09// 
-save
+get
  new 
-groups
+state
 %0A%09%09L

test parametrization. add DataProvider