@Test
  public void testNext() {
    boolean expected = true;
    EasyMock.expect(peekIterator.hasNext()).andReturn(expected).times(4);
    String defaultString = "S1";
    String resString = "S2";
    EasyMock.expect(peekIterator.next()).andReturn(defaultString);
    EasyMock.expect(binaryFn.apply(EasyMock.eq(defaultString), EasyMock.isNull()))
        .andReturn(resString);
    EasyMock.expect(peekIterator.next()).andReturn(defaultString);
    EasyMock.expect(comparator.compare(EasyMock.eq(resString), EasyMock.eq(defaultString)))
        .andReturn(0);
    EasyMock.expect(peekIterator.next()).andReturn(defaultString);
    EasyMock.expect(binaryFn.apply(EasyMock.eq(resString), EasyMock.eq(defaultString)))
        .andReturn(resString);
    EasyMock.expect(comparator.compare(EasyMock.eq(resString), EasyMock.eq(defaultString)))
        .andReturn(1);

    EasyMock.replay(peekIterator);
    EasyMock.replay(binaryFn);
    EasyMock.replay(comparator);

    String actual = testingIterator.next();
    Assert.assertEquals(resString, actual);

    EasyMock.verify(peekIterator);
    EasyMock.verify(comparator);
    EasyMock.verify(binaryFn);
  }
  public void testAcquireToken_Username_Password() throws Exception {
    ctx =
        PowerMock.createPartialMock(
            AuthenticationContext.class,
            new String[] {"acquireTokenCommon"},
            TestConfiguration.AAD_TENANT_ENDPOINT,
            true,
            service);
    PowerMock.expectPrivate(
            ctx,
            "acquireTokenCommon",
            EasyMock.isA(AdalAuthorizatonGrant.class),
            EasyMock.isA(ClientAuthentication.class),
            EasyMock.isA(ClientDataHttpHeaders.class))
        .andReturn(
            new AuthenticationResult(
                "bearer", "accessToken", "refreshToken", new Date().getTime(), null, null, false));

    UserDiscoveryResponse response = EasyMock.createMock(UserDiscoveryResponse.class);
    EasyMock.expect(response.isAccountFederated()).andReturn(false);

    PowerMock.mockStatic(UserDiscoveryRequest.class);
    EasyMock.expect(
            UserDiscoveryRequest.execute(
                EasyMock.isA(String.class),
                EasyMock.isNull(Proxy.class),
                EasyMock.isNull(SSLSocketFactory.class)))
        .andReturn(response);

    PowerMock.replay(ctx, response, UserDiscoveryRequest.class);
    Future<AuthenticationResult> result =
        ctx.acquireToken("resource", "clientId", "username", "password", null);

    AuthenticationResult ar = result.get();
    Assert.assertNotNull(ar);
    PowerMock.verifyAll();
    PowerMock.resetAll(ctx);
  }
 /**
  * Expects null.
  *
  * @return <code>null</code>.
  */
 protected final <T> T isNull() {
   return EasyMock.<T>isNull();
 }
 private AsyncMonitor optionalMonitor() {
   return or(isA(AsyncMonitor.class), EasyMock.<AsyncMonitor>isNull());
 }