### Question:
RegistryClient { private boolean doBearerAuth(boolean readOnlyBearerAuth) throws IOException, RegistryException { String registry = registryEndpointRequestProperties.getServerUrl(); String repository = registryEndpointRequestProperties.getImageName(); String image = registry + "/" + repository; eventHandlers.dispatch(LogEvent.debug("attempting bearer auth for " + image + "...")); Optional<RegistryAuthenticator> authenticator = callRegistryEndpoint( new AuthenticationMethodRetriever( registryEndpointRequestProperties, getUserAgent(), httpClient)); if (!authenticator.isPresent()) { eventHandlers.dispatch(LogEvent.debug("server requires basic auth for " + image)); return false; } doBearerAuth(readOnlyBearerAuth, authenticator.get()); return true; } private  RegistryClient(
      EventHandlers eventHandlers,
      @Nullable Credential credential,
      RegistryEndpointRequestProperties registryEndpointRequestProperties,
      @Nullable String userAgent,
      FailoverHttpClient httpClient); static Factory factory(
      EventHandlers eventHandlers,
      String serverUrl,
      String imageName,
      FailoverHttpClient httpClient); static Factory factory(
      EventHandlers eventHandlers,
      String serverUrl,
      String imageName,
      String sourceImageName,
      FailoverHttpClient httpClient); void configureBasicAuth(); boolean doPullBearerAuth(); boolean doPushBearerAuth(); void authPullByWwwAuthenticate(String wwwAuthenticate); Optional<ManifestAndDigest<ManifestTemplate>> checkManifest(String imageQualifier); ManifestAndDigest<T> pullManifest(
      String imageQualifier, Class<T> manifestTemplateClass); ManifestAndDigest<ManifestTemplate> pullManifest(String imageQualifier); DescriptorDigest pushManifest(ManifestTemplate manifestTemplate, String imageTag); Optional<BlobDescriptor> checkBlob(DescriptorDigest blobDigest); Blob pullBlob(
      DescriptorDigest blobDigest,
      Consumer<Long> blobSizeListener,
      Consumer<Long> writtenByteCountListener); boolean pushBlob(
      DescriptorDigest blobDigest,
      Blob blob,
      @Nullable String sourceRepository,
      Consumer<Long> writtenByteCountListener);  }### Answer:
@Test public void testDoBearerAuth() throws IOException, InterruptedException, GeneralSecurityException, URISyntaxException, RegistryException { setUpAuthServerAndRegistry(1, "HTTP/1.1 200 OK\nContent-Length: 1234\n\n"); RegistryClient registryClient = createRegistryClient(null); Assert.assertTrue(registryClient.doPushBearerAuth()); Optional<BlobDescriptor> digestAndSize = registryClient.checkBlob(digest); Assert.assertEquals(1234, digestAndSize.get().getSize()); Mockito.verify(eventHandlers).dispatch(logContains("attempting bearer auth")); Mockito.verify(eventHandlers).dispatch(logContains("bearer auth succeeded")); }