### Question:
ImageReference { public static ImageReference parse(String reference) throws InvalidImageReferenceException { if (reference.equals("scratch")) { return ImageReference.scratch(); } Matcher matcher = REFERENCE_PATTERN.matcher(reference); if (!matcher.find() || matcher.groupCount() < 4) { throw new InvalidImageReferenceException(reference); } String registry = matcher.group(1); String repository = matcher.group(2); String tag = matcher.group(3); String digest = matcher.group(4); if (Strings.isNullOrEmpty(registry)) { registry = DOCKER_HUB_REGISTRY; } if (Strings.isNullOrEmpty(repository)) { throw new InvalidImageReferenceException(reference); } if (!registry.contains(".") && !registry.contains(":") && !"localhost".equals(registry)) { repository = registry + "/" + repository; registry = DOCKER_HUB_REGISTRY; } if (DOCKER_HUB_REGISTRY.equals(registry) && repository.indexOf('/') < 0) { repository = LIBRARY_REPOSITORY_PREFIX + repository; } if (Strings.isNullOrEmpty(tag) && Strings.isNullOrEmpty(digest)) { tag = DEFAULT_TAG; } if (Strings.isNullOrEmpty(tag)) { tag = null; } if (Strings.isNullOrEmpty(digest)) { digest = null; } return new ImageReference(registry, repository, tag, digest); } private  ImageReference(
      String registry, String repository, @Nullable String tag, @Nullable String digest); static ImageReference parse(String reference); static ImageReference of(
      @Nullable String registry, String repository, @Nullable String qualifier); static ImageReference of(
      @Nullable String registry, String repository, @Nullable String tag, @Nullable String digest); static ImageReference scratch(); static boolean isValidRegistry(String registry); static boolean isValidRepository(String repository); static boolean isValidTag(String tag); static boolean isValidDigest(String digest); static boolean isDefaultTag(@Nullable String tag); String getRegistry(); String getRepository(); Optional<String> getTag(); Optional<String> getDigest(); String getQualifier(); boolean usesDefaultTag(); boolean isScratch(); ImageReference withQualifier(String newQualifier); @Override String toString(); String toStringWithQualifier(); @Override boolean equals(Object other); @Override int hashCode();  }### Answer:
@Test public void testParse_invalid() { for (String badImageReference : badImageReferences) { try { ImageReference.parse(badImageReference); Assert.fail(badImageReference + " should not be a valid image reference"); } catch (InvalidImageReferenceException ex) { MatcherAssert.assertThat(ex.getMessage(), CoreMatchers.containsString(badImageReference)); } } }