package study.hard.lambdaj;

import static ch.lambdaj.Lambda.*;
import static org.hamcrest.Matchers.*;

import java.util.List;

import org.junit.Before;
import org.junit.Test;

import study.hard.commons.User;

import com.google.common.collect.Lists;

/**
 * @author SeomGi, Han(iandmyhand@gmail.com)
 */
public class LambdajTester {

	private List<User> userList;

	@Before
	public void setUp() {
		userList = Lists.newArrayList();

		// Add the 10 users.
		for (int i = 1; i <= 10; i++) {
			User user = new User("Tester" + (i % 2), 20 + (i % 3));
			userList.add(user);
		}

		println("Sample list:", userList);
	}

	@Test
	public void testSelectWithOneCondition() {
		String name = "Tester1";
		List<User> selectedList = select
			(
				userList,
				having(
					on(User.class).getName(),
					equalTo(name)
				)
			);

		println("test to select with one condition:", selectedList);
	}

	@Test
	public void testOrderingComparison() {
		String name = "Tester1";
		List<User> selectedList = select(
			userList,
			allOf(
				having(
					on(User.class).getName(),
					equalTo(name)),
				having(
					on(User.class).getAge(),
					allOf(
						greaterThanOrEqualTo(21),
						lessThanOrEqualTo(23)
					)
				)
			)
			);

		println("Test ordering comparison:", selectedList);
	}

	private void println(String title, List<User> userList) {
		System.out.println("==================================================");
		System.out.println(title);
		System.out.println("--------------------------------------------------");
		System.out.println("User list: " + userList);
		System.out.println("==================================================");
	}
}

@@ -119,16 +119,38 @@
 il.List;
+%0Aimport java.util.Set;
 %0A%0Aimport
@@ -223,16 +223,47 @@
 ns.User;
+%0Aimport ch.lambdaj.group.Group;
 %0A%0Aimport
@@ -1046,18 +1046,23 @@
 = select
+%0A%09%09%09
 (%0A
+%09
 %09%09%09userL
@@ -1066,16 +1066,17 @@
 erList,%0A
+%09
 %09%09%09allOf
@@ -1077,32 +1077,33 @@
 %09allOf(%0A%09%09%09%09
+%09
 having(%0A
 %09%09%09%09%09on(User
@@ -1082,32 +1082,33 @@
 f(%0A%09%09%09%09%09having(%0A
+%09
 %09%09%09%09%09on(User.cla
@@ -1114,32 +1114,33 @@
 ass).getName(),%0A
+%09
 %09%09%09%09%09equalTo(nam
@@ -1144,32 +1144,33 @@
 name)),%0A%09%09%09%09
+%09
 having(%0A
 %09%09%09%09%09on(User
@@ -1149,32 +1149,33 @@
 ),%0A%09%09%09%09%09having(%0A
+%09
 %09%09%09%09%09on(User.cla
@@ -1189,31 +1189,33 @@
 Age(),%0A%09%09%09%09%09
+%09
 allOf(%0A
+%09
 %09%09%09%09%09%09greate
@@ -1240,16 +1240,17 @@
 ,%0A%09%09%09%09%09%09
+%09
 lessThan
@@ -1263,16 +1263,24 @@
 lTo(23)%0A
+%09%09%09%09%09%09)%0A
 %09%09%09%09%09)%0A%09
@@ -1284,21 +1284,16 @@
 )%0A%09%09%09%09)%0A
-%09%09%09)%0A
 %09%09%09);%0A%0A%09
@@ -1354,61 +1354,538 @@
 %7D%0A%0A%09
-private void println(String title, List%3C
+@Test%0A%09public void testGrouping() %7B%0A%09%09Group%3CUser%3E groupAgeOfUser = group%0A%09%09%09(%0A%09%09%09%09userList,%0A%09%09%09%09by(on(User.class).getAge())%0A%09%09%09);%0A%09%09Set%3CString%3E groupAgeKeys = groupAgeOfUser.keySet();%0A%0A%09%09println(%22group keys:%22, groupAgeKeys);%0A%0A%09%09for (String ageKey : groupAgeKeys) %7B%0A%09%09%09println(%22age key:%22, ageKey);%0A%09%09%09println(%22size of group by age key%5B%22 + ageKey + %22%5D:%22, groupAgeOfUser.find(ageKey).size());%0A%09%09%09for (
 User
-%3E
  user
-Lis
+ : groupAgeOfUser.find(ageKey)) %7B%0A%09%09%09%09println(%22user:%22, user);%0A%09%09%09%7D%0A%09%09%7D%0A%09%7D%0A%0A%09private void println(String title, Object objec
 t) %7B
@@ -2092,30 +2092,25 @@
 ln(%22
-User list: %22 + userLis
+result: %22 + objec
 t);%0A

Add Lambdaj's grouping test code.