Repository: GoogleContainerTools/jib
File: jib-plugins-common/src/test/java/com/google/cloud/tools/jib/plugins/common/UpdateCheckerTest.java (Java)

Code before:
    testWebServer = new TestWebServer(false, Collections.singletonList(response), 1);
    configDir = temporaryFolder.getRoot().toPath();
  }

  @After
  public void tearDown() throws IOException {
    testWebServer.close();
  }

  @Test
  public void testPerformUpdateCheck_newVersionFound() throws IOException {
    Instant before = Instant.now();
    setupLastUpdateCheck();
    Optional<String> message =
        UpdateChecker.performUpdateCheck(
            configDir, "1.0.2", testWebServer.getEndpoint(), "tool name", ignored -> {});

    assertThat(testWebServer.getInputRead()).contains("User-Agent: jib 1.0.2 tool name");
    assertThat(message)
        .hasValue(
            "A new version of Jib (2.0.0) is available (currently using 1.0.2). Update your build "
                + "configuration to use the latest features and fixes!");
    String modifiedTime =
        new String(
            Files.readAllBytes(configDir.resolve("lastUpdateCheck")), StandardCharsets.UTF_8);
    assertThat(Instant.parse(modifiedTime).isAfter(before)).isTrue();
  }

  @Test
  public void testPerformUpdateCheck_newJsonField()
      throws IOException, InterruptedException, GeneralSecurityException, URISyntaxException {
    String response =
        "HTTP/1.1 200 OK\nContent-Length:43\n\n{\"latest\":\"2.0.0\",\"unknownField\":\"unknown\"}";
    try (TestWebServer server = new TestWebServer(false, Collections.singletonList(response), 1)) {
      setupLastUpdateCheck();
      Optional<String> message =
          UpdateChecker.performUpdateCheck(
              configDir, "1.0.2", server.getEndpoint(), "tool name", ignored -> {});
      assertThat(message)
          .hasValue(
              "A new version of Jib (2.0.0) is available (currently using 1.0.2). Update your build "
                  + "configuration to use the latest features and fixes!");
    }
  }

  @Test
  public void testPerformUpdateCheck_onLatest() throws IOException {
    Instant before = Instant.now();
    setupLastUpdateCheck();
    Optional<String> message =
        UpdateChecker.performUpdateCheck(

Review comment (suggestion):
Truth has `assertThat(Instant)`, so you can probably do like `assertThat(modifiedTime).isAfter(before)` or something like that.

Code after:
    testWebServer = new TestWebServer(false, Collections.singletonList(response), 1);
    configDir = temporaryFolder.getRoot().toPath();
  }

  @After
  public void tearDown() throws IOException {
    testWebServer.close();
  }

  @Test
  public void testPerformUpdateCheck_newVersionFound() throws IOException {
    Instant before = Instant.now();
    setupLastUpdateCheck();
    Optional<String> message =
        UpdateChecker.performUpdateCheck(
            configDir, "1.0.2", testWebServer.getEndpoint(), "tool name", ignored -> {});

    assertThat(testWebServer.getInputRead()).contains("User-Agent: jib 1.0.2 tool name");
    assertThat(message)
        .hasValue(
            "A new version of Jib (2.0.0) is available (currently using 1.0.2). Update your build "
                + "configuration to use the latest features and fixes!");
    String modifiedTime =
        new String(
            Files.readAllBytes(configDir.resolve("lastUpdateCheck")), StandardCharsets.UTF_8);
    assertThat(Instant.parse(modifiedTime)).isGreaterThan(before);
  }

  @Test
  public void testPerformUpdateCheck_newJsonField()
      throws IOException, InterruptedException, GeneralSecurityException, URISyntaxException {
    String response =
        "HTTP/1.1 200 OK\nContent-Length:43\n\n{\"latest\":\"2.0.0\",\"unknownField\":\"unknown\"}";
    try (TestWebServer server = new TestWebServer(false, Collections.singletonList(response), 1)) {
      setupLastUpdateCheck();
      Optional<String> message =
          UpdateChecker.performUpdateCheck(
              configDir, "1.0.2", server.getEndpoint(), "tool name", ignored -> {});
      assertThat(message)
          .hasValue(
              "A new version of Jib (2.0.0) is available (currently using 1.0.2). Update your build "
                  + "configuration to use the latest features and fixes!");
    }
  }

  @Test
  public void testPerformUpdateCheck_onLatest() throws IOException {
    Instant before = Instant.now();
    setupLastUpdateCheck();
    Optional<String> message =
        UpdateChecker.performUpdateCheck(