@Test
  public void testAutomaticTokenRefresh()
      throws IOException, InterruptedException, GeneralSecurityException, URISyntaxException,
          RegistryException {
    setUpAuthServerAndRegistry(3, "HTTP/1.1 200 OK\nContent-Length: 5678\n\n");

    RegistryClient registryClient = createRegistryClient(null);
    Assert.assertTrue(registryClient.doPushBearerAuth());

    Optional<BlobDescriptor> digestAndSize = registryClient.checkBlob(digest);
    Assert.assertEquals(5678, digestAndSize.get().getSize());

    // Verify authServer returned bearer token three times (i.e., refreshed twice)
    Assert.assertEquals(3, authServer.getTotalResponsesServed());
    Assert.assertEquals(4, registry.getTotalResponsesServed());

    Mockito.verify(eventHandlers).dispatch(logContains("attempting bearer auth"));
    Mockito.verify(eventHandlers).dispatch(logContains("bearer auth succeeded"));
    Mockito.verify(eventHandlers, Mockito.times(2))
        .dispatch(logContains("refreshing bearer auth token"));
  }
Tests for {@link RegistryClient}. More comprehensive tests can be found in the integration tests.
jib-core/src/test/java/com/google/cloud/tools/jib/registry/RegistryClientTest.java