@Test public void group_order() { Map<Integer, Group> results = BASIC_RESULTS .transform(groupBy(postId).as(postName, set(commentId))); assertEquals(4, results.size()); }
@Test(expected = ClassCastException.class) public void classCastException() { List<Group> results = BASIC_RESULTS.transform( groupBy(postId).list(postName, set(commentId), list(commentText))); assertEquals(4, results.size()); Group group = results.get(1); group.getList(commentId); }
@Test public void group_order() { CloseableIterator<Group> resultsIt = BASIC_RESULTS .transform(groupBy(postId).iterate(postName, set(commentId))); List<Group> results = IteratorAdapter.asList(resultsIt); assertEquals(4, results.size()); }
@Test(expected = NoSuchElementException.class) public void noSuchElementException() { Map<Integer, Group> results = BASIC_RESULTS.transform( groupBy(postId).as(postName, set(commentId), list(commentText))); Group group = results.get(1); group.getSet(qComment); }
@Test(expected = NoSuchElementException.class) public void noSuchElementException() { CloseableIterator<Group> resultsIt = BASIC_RESULTS.transform( groupBy(postId).iterate(postName, set(commentId), list(commentText))); List<Group> results = IteratorAdapter.asList(resultsIt); assertEquals(4, results.size()); Group group = results.get(1); group.getSet(qComment); }
@Test(expected = ClassCastException.class) public void classCastException() { CloseableIterator<Group> resultsIt = BASIC_RESULTS.transform( groupBy(postId).iterate(postName, set(commentId), list(commentText))); List<Group> results = IteratorAdapter.asList(resultsIt); assertEquals(4, results.size()); Group group = results.get(1); group.getList(commentId); }
@Test public void array_access() { List<Group> results = BASIC_RESULTS.transform( groupBy(postId).list(postName, set(commentId), list(commentText))); assertEquals(4, results.size()); Group group = results.get(1); Object[] array = group.toArray(); assertEquals(toInt(1), array[0]); assertEquals("post 1", array[1]); assertEquals(toSet(1, 2, 3), array[2]); assertEquals(Arrays.asList("comment 1", "comment 2", "comment 3"), array[3]); }
@Test public void array_access() { Map<Integer, Group> results = BASIC_RESULTS.transform( groupBy(postId).as(postName, set(commentId), list(commentText))); Group group = results.get(1); Object[] array = group.toArray(); assertEquals(toInt(1), array[0]); assertEquals("post 1", array[1]); assertEquals(toSet(1, 2, 3), array[2]); assertEquals(Arrays.asList("comment 1", "comment 2", "comment 3"), array[3]); }
@Test public void first_set_and_list() { List<Group> results = BASIC_RESULTS.transform( groupBy(postId).list(postName, set(commentId), list(commentText))); assertEquals(4, results.size()); Group group = results.get(1); assertEquals(toInt(1), group.getOne(postId)); assertEquals("post 1", group.getOne(postName)); assertEquals(toSet(1, 2, 3), group.getSet(commentId)); assertEquals(Arrays.asList("comment 1", "comment 2", "comment 3"), group.getList(commentText)); }
@Test public void group_by_null() { CloseableIterator<Group> resultsIt = BASIC_RESULTS.transform( groupBy(postId).iterate(postName, set(commentId), list(commentText))); List<Group> results = IteratorAdapter.asList(resultsIt); assertEquals(4, results.size()); Group group = results.get(0); assertNull(group.getOne(postId)); assertEquals("null post", group.getOne(postName)); assertEquals(toSet(7, 8), group.getSet(commentId)); assertEquals(Arrays.asList("comment 7", "comment 8"), group.getList(commentText)); }
@Test public void first_set_and_list() { CloseableIterator<Group> resultsIt = BASIC_RESULTS.transform( groupBy(postId).iterate(postName, set(commentId), list(commentText))); List<Group> results = IteratorAdapter.asList(resultsIt); assertEquals(4, results.size()); Group group = results.get(1); assertEquals(toInt(1), group.getOne(postId)); assertEquals("post 1", group.getOne(postName)); assertEquals(toSet(1, 2, 3), group.getSet(commentId)); assertEquals(Arrays.asList("comment 1", "comment 2", "comment 3"), group.getList(commentText)); }
@Test public void oneToOneToMany_projection() { Map<String, User> results = USERS_W_LATEST_POST_AND_COMMENTS.transform( groupBy(userName).as(Projections.constructor(User.class, userName, Projections.constructor(Post.class, postId, postName, set(qComment))))); assertEquals(2, results.size()); User user = results.get("Jane"); Post post = user.getLatestPost(); assertEquals(toInt(2), post.getId()); assertEquals("post 2", post.getName()); assertEquals(toSet(comment(4), comment(5)), post.getComments()); }
@Test public void transform_results() { List<Post> results = POST_W_COMMENTS.transform( groupBy(postId).list(Projections.constructor(Post.class, postId, postName, set(qComment)))); assertEquals(4, results.size()); Post post = results.get(1); assertNotNull(post); assertEquals(toInt(1), post.getId()); assertEquals("post 1", post.getName()); assertEquals(toSet(comment(1), comment(2), comment(3)), post.getComments()); }
@Test public void oneToOneToMany_projection() { List<User> results = USERS_W_LATEST_POST_AND_COMMENTS.transform( groupBy(userName).list(Projections.constructor(User.class, userName, Projections.constructor(Post.class, postId, postName, set(qComment))))); assertEquals(2, results.size()); User user = results.get(0); Post post = user.getLatestPost(); assertEquals(toInt(2), post.getId()); assertEquals("post 2", post.getName()); assertEquals(toSet(comment(4), comment(5)), post.getComments()); }
@Test public void oneToOneToMany_projection_as_bean_and_constructor() { Map<String, User> results = USERS_W_LATEST_POST_AND_COMMENTS.transform( groupBy(userName).as(Projections.bean(User.class, userName, Projections.constructor(Post.class, postId, postName, set(qComment)).as("latestPost")))); assertEquals(2, results.size()); User user = results.get("Jane"); Post post = user.getLatestPost(); assertEquals(toInt(2), post.getId()); assertEquals("post 2", post.getName()); assertEquals(toSet(comment(4), comment(5)), post.getComments()); }
@Test public void transform_results() { CloseableIterator<Post> resultsIt = POST_W_COMMENTS.transform( groupBy(postId).iterate(Projections.constructor(Post.class, postId, postName, set(qComment)))); List<Post> results = IteratorAdapter.asList(resultsIt); assertEquals(4, results.size()); Post post = results.get(1); assertNotNull(post); assertEquals(toInt(1), post.getId()); assertEquals("post 1", post.getName()); assertEquals(toSet(comment(1), comment(2), comment(3)), post.getComments()); }
@Test public void transform_as_bean() { List<Post> results = POST_W_COMMENTS.transform( groupBy(postId).list(Projections.bean(Post.class, postId, postName, set(qComment).as("comments")))); assertEquals(4, results.size()); Post post = results.get(1); assertNotNull(post); assertEquals(toInt(1), post.getId()); assertEquals("post 1", post.getName()); assertEquals(toSet(comment(1), comment(2), comment(3)), post.getComments()); }
@Test public void oneToOneToMany_projection_as_bean_and_constructor() { List<User> results = USERS_W_LATEST_POST_AND_COMMENTS.transform( groupBy(userName).list(Projections.bean(User.class, userName, Projections.constructor(Post.class, postId, postName, set(qComment)).as("latestPost")))); assertEquals(2, results.size()); User user = results.get(0); Post post = user.getLatestPost(); assertEquals(toInt(2), post.getId()); assertEquals("post 2", post.getName()); assertEquals(toSet(comment(4), comment(5)), post.getComments()); }
@Test public void oneToOneToMany_projection_as_bean() { List<User> results = USERS_W_LATEST_POST_AND_COMMENTS.transform( groupBy(userName).list(Projections.bean(User.class, userName, Projections.bean(Post.class, postId, postName, set(qComment).as("comments")).as("latestPost")))); assertEquals(2, results.size()); User user = results.get(0); Post post = user.getLatestPost(); assertEquals(toInt(2), post.getId()); assertEquals("post 2", post.getName()); assertEquals(toSet(comment(4), comment(5)), post.getComments()); }
@Test public void transform_results() { Map<Integer, Post> results = POST_W_COMMENTS.transform( groupBy(postId).as(Projections.constructor(Post.class, postId, postName, set(qComment)))); Post post = results.get(1); assertNotNull(post); assertEquals(toInt(1), post.getId()); assertEquals("post 1", post.getName()); assertEquals(toSet(comment(1), comment(2), comment(3)), post.getComments()); }