PieroneImage { public static Optional<PieroneImage> tryParse(final String source) { return Optional.ofNullable(source) .map(DOCKER_SOURCE_PATTERN::matcher) .filter(Matcher::matches) .map(matcher -> new PieroneImage(matcher.group(1), matcher.group(2), matcher.group(3), matcher.group(4))); } PieroneImage(final String repository, final String team, final String artifact, final String tag); static Optional<PieroneImage> tryParse(final String source); String getTag(); String getArtifact(); String getTeam(); String getRepository(); @Override String toString();  }
@Test public void testTryParse() throws Exception { final Optional<PieroneImage> result = PieroneImage.tryParse(get(REPOSITORY, TEAM, ARTIFACT).toString()+":"+TAG); assertThat(result).isPresent(); assertThat(result.get().getRepository()).isEqualTo(REPOSITORY); assertThat(result.get().getTeam()).isEqualTo(TEAM); assertThat(result.get().getArtifact()).isEqualTo(ARTIFACT); assertThat(result.get().getTag()).isEqualTo(TAG); assertThat(pieroneImage.toString()).isEqualTo(result.get().toString()); }