@Test
public void testCachedInitialization() throws IOException, URISyntaxException {

  Configuration conf = new Configuration();
  DummyFs fs = spy(new DummyFs());
  Token<TokenIdentifier> token = new Token<TokenIdentifier>(new byte[0],
      new byte[0], DummyFs.TOKEN_KIND, new Text("127.0.0.1:1234"));
  doReturn(token).when(fs).getDelegationToken(anyString());
  doReturn(token).when(fs).getRenewToken();
  fs.emulateSecurityEnabled = true;
  fs.initialize(new URI("dummyfs://127.0.0.1:1234"), conf);
  fs.tokenAspect.ensureTokenInitialized();
  verify(fs, times(1)).getDelegationToken(null);
  verify(fs, times(1)).setDelegationToken(token);
  // For the second iteration, the token should be cached.
  fs.tokenAspect.ensureTokenInitialized();
  verify(fs, times(1)).getDelegationToken(null);
  verify(fs, times(1)).setDelegationToken(token);
}