@Test(timeout = 500)
  public void testException() throws Exception {
    PrintStream oldErrPrintStream = System.err;
    ByteArrayOutputStream dataErr = new ByteArrayOutputStream();
    System.setErr(new PrintStream(dataErr));
    try {
      when(admin.refreshQueues(any(RefreshQueuesRequest.class)))
          .thenThrow(new IOException("test exception"));
      String[] args = {"-refreshQueues"};

      assertEquals(-1, rmAdminCLI.run(args));
      verify(admin).refreshQueues(any(RefreshQueuesRequest.class));
      assertTrue(dataErr.toString().contains("refreshQueues: test exception"));
    } finally {
      System.setErr(oldErrPrintStream);
    }
  }
 @Test(timeout = 500)
 public void testGetGroups() throws Exception {
   when(admin.getGroupsForUser(eq("admin"))).thenReturn(new String[] {"group1", "group2"});
   PrintStream origOut = System.out;
   PrintStream out = mock(PrintStream.class);
   System.setOut(out);
   try {
     String[] args = {"-getGroups", "admin"};
     assertEquals(0, rmAdminCLI.run(args));
     verify(admin).getGroupsForUser(eq("admin"));
     verify(out)
         .println(
             argThat(
                 new ArgumentMatcher<StringBuilder>() {
                   @Override
                   public boolean matches(Object argument) {
                     return ("" + argument).equals("admin : group1 group2");
                   }
                 }));
   } finally {
     System.setOut(origOut);
   }
 }