@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);
  }
  @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);
  }
  @Before
  public void init() {
    PullContext pullContext = createMock(PullContext.class);

    expect(pullContext.pull("pull1")).andReturn(111).anyTimes();
    expect(pullContext.pull("pull2")).andReturn(222).anyTimes();

    Set<String> names = createHashSet(Arrays.asList("pull1", "pull2"));
    expect(pullContext.getToolNames()).andReturn(names).anyTimes();

    expect(pullContext.pull(org.easymock.EasyMock.<String>anyObject())).andReturn(null).anyTimes();

    replay(pullContext);

    parent = new PullableMappedContext(pullContext);
    parent.put("parent", 333);

    context = new MappedContext(parent);
    context.put("child", 444);
  }