BuildImageQueryParameters { public String toQueryParameterString() { Optional<StringBuilder> queryBuilder = Optional.of(new StringBuilder("&")) .flatMap(qb -> Optional.ofNullable(dockerFile.map(df -> qb.append("dockerfile=").append(df).append("&")).orElse(qb))) .flatMap(qb -> Optional.ofNullable(remote.map(r -> qb.append("remote=").append(r).append("&")).orElse(qb))); return queryBuilder .filter(qb -> qb.toString().endsWith("&")) .map(StringBuilder::toString) .map(qb -> qb.substring(0, qb.lastIndexOf("&"))) .orElse(""); } private  BuildImageQueryParameters();  BuildImageQueryParameters(String dockerFile);  BuildImageQueryParameters(String dockerFile, String remote); static BuildImageQueryParameters withRemoteDockerfile(final String remote); String toQueryParameterString(); static BuildImageQueryParameters withDefaultValues();  }
@Test public void shouldBuildQueryParameterWithBothQueryParameters() throws Exception { BuildImageQueryParameters queryParameters = new BuildImageQueryParameters("test/dockerfile", "http: assertThat(queryParameters.toQueryParameterString(), equalTo("&dockerfile=test/dockerfile&remote=http: }
@Test public void shouldBuildQueryParameterWithDockerfileOption() throws Exception { BuildImageQueryParameters queryParameters = new BuildImageQueryParameters("abc/abc"); assertThat(queryParameters.toQueryParameterString(), equalTo("&dockerfile=abc/abc")); }