From a62dcb73ef73b0743a3d101bb9d6f90ed59bbbc1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timo=20Westk=C3=A4mper?= Date: Thu, 12 Dec 2013 20:54:15 +0200 Subject: [PATCH] Add test --- .../query/collections/GroupBy4Test.java | 51 +++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 querydsl-collections/src/test/java/com/mysema/query/collections/GroupBy4Test.java diff --git a/querydsl-collections/src/test/java/com/mysema/query/collections/GroupBy4Test.java b/querydsl-collections/src/test/java/com/mysema/query/collections/GroupBy4Test.java new file mode 100644 index 000000000..2b7cb9861 --- /dev/null +++ b/querydsl-collections/src/test/java/com/mysema/query/collections/GroupBy4Test.java @@ -0,0 +1,51 @@ +package com.mysema.query.collections; + +import static com.mysema.query.group.GroupBy.groupBy; +import static com.mysema.query.group.GroupBy.map; +import static org.junit.Assert.assertEquals; + +import java.util.List; +import java.util.Map; + +import org.junit.Test; + +import com.google.common.collect.ImmutableSet; +import com.google.common.collect.Lists; +import com.mysema.query.annotations.QueryEntity; + + +public class GroupBy4Test { + + @QueryEntity + public static class Table { + String col1, col2, col3; + + public Table(String c1, String c2, String c3) { + col1 = c1; + col2 = c2; + col3 = c3; + } + } + + @Test + public void test() { + List data = Lists.newArrayList(); + data.add(new Table("1", "abc", "111")); + data.add(new Table("1", "pqr", "222")); + data.add(new Table("2", "abc", "333")); + data.add(new Table("2", "pqr", "444")); + data.add(new Table("3", "abc", "555")); + data.add(new Table("3", "pqr", "666")); + + QGroupBy4Test_Table table = QGroupBy4Test_Table.table; + Map> grouped = CollQueryFactory + .from(table, data) + .transform(groupBy(table.col1).as(map(table.col2, table.col3))); + + assertEquals(3, grouped.size()); + assertEquals(2, grouped.get("1").size()); + assertEquals(ImmutableSet.of("abc", "pqr"), grouped.get("1").keySet()); + + } + +}