@Test
  public void testGetQueryCached() throws Exception {
    final PermissionsFilterCache cache = mockController.getMock(PermissionsFilterCache.class);
    final BooleanQuery cachedQuery = new BooleanQuery();

    org.easymock.EasyMock.expect(cache.getQuery(theUser)).andReturn(cachedQuery);

    replay();

    final PermissionQueryFactory permissionQueryFactory =
        new PermissionQueryFactory() {
          public Query getQuery(com.atlassian.crowd.embedded.api.User searcher, int permissionId) {
            fail("Should not be called as query was cached");
            return null;
          }
        };

    final PermissionsFilterGeneratorImpl generator =
        new PermissionsFilterGeneratorImpl(permissionQueryFactory) {
          @Override
          PermissionsFilterCache getCache() {
            return cache;
          }
        };

    final Query result = generator.getQuery(theUser);

    assertSame(cachedQuery, result);
  }
  @Test
  public void testGetQueryNoCache() throws Exception {
    final PermissionsFilterCache cache = mockController.getMock(PermissionsFilterCache.class);
    final BooleanQuery generatedQuery = new BooleanQuery();

    org.easymock.EasyMock.expect(cache.getQuery(theUser)).andReturn(null);

    cache.storeQuery(generatedQuery, theUser);
    org.easymock.EasyMock.expectLastCall();

    replay();
    final PermissionQueryFactory permissionQueryFactory =
        new PermissionQueryFactory() {
          public Query getQuery(com.atlassian.crowd.embedded.api.User searcher, int permissionId) {
            assertSame(theUser, searcher);
            assertEquals(Permissions.BROWSE, permissionId);
            return generatedQuery;
          }
        };

    final PermissionsFilterGeneratorImpl generator =
        new PermissionsFilterGeneratorImpl(permissionQueryFactory) {
          @Override
          PermissionsFilterCache getCache() {
            return cache;
          }
        };

    final Query result = generator.getQuery(theUser);

    assertSame(generatedQuery, result);
  }