private static String buildAndRunComplex(
      String imageReference, String username, String password, LocalRegistry targetRegistry)
      throws IOException, InterruptedException {
    Path baseCache = simpleTestProject.getProjectRoot().resolve("build/jib-base-cache");
    BuildResult buildResult =
        simpleTestProject.build(
            "clean",
            "jib",
            "-Djib.baseImageCache=" + baseCache,
            "-Djib.console=plain",
            "-D_TARGET_IMAGE=" + imageReference,
            "-D_TARGET_USERNAME=" + username,
            "-D_TARGET_PASSWORD=" + password,
            "-DsendCredentialsOverHttp=true",
            "-b=complex-build.gradle");

    JibRunHelper.assertBuildSuccess(buildResult, "jib", "Built and pushed image as ");
    assertThat(buildResult.getOutput()).contains(imageReference);

    targetRegistry.pull(imageReference);
    assertDockerInspect(imageReference);
    String history = new Command("docker", "history", imageReference).run();
    assertThat(history).contains("jib-gradle-plugin");

    String output = new Command("docker", "run", "--rm", imageReference).run();
    assertThat(ImmutableList.copyOf(output.split("\n")))
        .containsExactly(
            "Hello, world. An argument.",
            "1970-01-01T00:00:01Z",
            "rwxr-xr-x",
            "rwxrwxrwx",
            "foo",
            "cat",
            "1970-01-01T00:00:01Z",
            "1970-01-01T00:00:01Z",
            "-Xms512m",
            "-Xdebug",
            "envvalue1",
            "envvalue2");
    return output;
  }
Asserts that the test project has the required exposed ports, labels and volumes.

@param imageReference the image to test
@throws IOException if the {@code docker inspect} command fails to run
@throws InterruptedException if the {@code docker inspect} command is interrupted
jib-gradle-plugin/src/integration-test/java/com/google/cloud/tools/jib/gradle/SingleProjectIntegrationTest.java