### Question:
QueryCacheBean { @RolesAllowed({"Administrator", "JBossAdministrator"}) @JmxManaged public String cancelUserQuery(String id) throws Exception { AbstractRunningQuery arq = cache.get(id); if (arq != null) { try { @SuppressWarnings("unused") VoidResponse response = query.cancel(id); return "Success."; } catch (Exception e) { return "Failed, check log."; } } else { return "No such query: " + id; } }  @RolesAllowed({"Administrator", "JBossAdministrator"}) @JmxManaged String listRunningQueries(); @GET @Path("/listRunningQueries") @Produces({"application/xml", "text/xml", "application/json", "text/yaml", "text/x-yaml", "application/x-yaml", "text/html"}) @GZIP @RolesAllowed({"Administrator", "JBossAdministrator"}) RunningQueries getRunningQueries(); @RolesAllowed({"Administrator", "JBossAdministrator"}) @JmxManaged String cancelUserQuery(String id);  }### Answer:
@Test public void testCancelUserQuery_CacheReturnsNonRunningQuery() throws Exception { UUID queryId = UUID.randomUUID(); expect(this.altCache.get(queryId.toString())).andReturn(PowerMock.createMock(RunningQuery.class)); PowerMock.replayAll(); QueryCacheBean subject = new QueryCacheBean(); setInternalState(subject, QueryCache.class, altCache); String result1 = subject.cancelUserQuery(queryId.toString()); PowerMock.verifyAll(); assertNotNull("List of running queries should not be null", result1); }
@Test public void testCancelUserQuery_HappyPath() throws Exception { UUID queryId = UUID.randomUUID(); expect(this.altCache.get(queryId.toString())).andReturn(this.query); PowerMock.replayAll(); QueryCacheBean subject = new QueryCacheBean(); setInternalState(subject, QueryCache.class, altCache); String result1 = subject.cancelUserQuery(queryId.toString()); PowerMock.verifyAll(); assertNotNull("List of running queries should not be null", result1); }