PaginatedSearchQueryBuilder { public String queryForMatchingChildrenFirstPage() throws JSONException { StringBuilder queryBuilder = buildQuery(); return queryBuilder.append(") LIMIT 30").toString(); } PaginatedSearchQueryBuilder(RapidFtrApplication applicationContext, String searchKey); String queryForMatchingChildrenFirstPage(); String queryForMatchingChildrenBetweenPages(int fromPageNumber, int toPageNumber);  }
@Test public void shouldReturnFirstThirtyMatchesForCurrentUserGivenUnverifiedUser() throws JSONException { doReturn(false).when(user).isVerified(); queryBuilder = new PaginatedSearchQueryBuilder(applicationContext, "john"); String actualQuery = queryBuilder.queryForMatchingChildrenFirstPage(); String expectQuery = "SELECT child_json, synced " + "FROM children WHERE ( child_owner = 'user1' AND child_json LIKE '%john%' OR id LIKE '%john%') LIMIT 30"; assertEquals(expectQuery, actualQuery); }
@Test public void shouldReturnQueryWithLimitForFirstThirtyMatchesGivenVerifiedUser() throws JSONException { doReturn(true).when(user).isVerified(); PaginatedSearchQueryBuilder queryBuilder = new PaginatedSearchQueryBuilder(applicationContext, "john"); String actualQuery = queryBuilder.queryForMatchingChildrenFirstPage(); String expectQuery = "SELECT child_json, synced " + "FROM children WHERE (child_json LIKE '%john%' OR id LIKE '%john%') LIMIT 30"; assertEquals(expectQuery, actualQuery); }
@Test public void shouldReturnQueryForFirstThirtyMatchesWithAllTwoSubQueries() throws JSONException { doReturn(true).when(user).isVerified(); PaginatedSearchQueryBuilder queryBuilder = new PaginatedSearchQueryBuilder(applicationContext, "john doe"); String actualQuery = queryBuilder.queryForMatchingChildrenFirstPage(); String expectQuery = "SELECT child_json, synced " + "FROM children WHERE (child_json LIKE '%john%' OR id LIKE '%john%' " + "OR child_json LIKE '%doe%' OR id LIKE '%doe%') LIMIT 30"; assertEquals(expectQuery, actualQuery); }
@Test public void shouldReturnQueryForFirstThirtyMatchesWithMoreThanTwoSubQueries() throws JSONException { doReturn(true).when(user).isVerified(); PaginatedSearchQueryBuilder queryBuilder = new PaginatedSearchQueryBuilder(applicationContext, "john doe foo"); String actualQuery = queryBuilder.queryForMatchingChildrenFirstPage(); String expectQuery = "SELECT child_json, synced " + "FROM children WHERE (child_json LIKE '%john%' OR id LIKE '%john%' " + "OR child_json LIKE '%doe%' OR id LIKE '%doe%' " + "OR child_json LIKE '%foo%' OR id LIKE '%foo%') LIMIT 30"; assertEquals(expectQuery, actualQuery); }