@@ -0,0 +1,3392 @@
+// Copyright (C) 2019 The Android Open Source Project%0A//%0A// Licensed under the Apache License, Version 2.0 (the %22License%22);%0A// you may not use this file except in compliance with the License.%0A// You may obtain a copy of the License at%0A//%0A// http://www.apache.org/licenses/LICENSE-2.0%0A//%0A// Unless required by applicable law or agreed to in writing, software%0A// distributed under the License is distributed on an %22AS IS%22 BASIS,%0A// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.%0A// See the License for the specific language governing permissions and%0A// limitations under the License.%0A%0Apackage com.google.gerrit.server.testing;%0A%0Aimport static com.google.common.truth.Truth.assertAbout;%0Aimport static java.util.concurrent.TimeUnit.SECONDS;%0A%0Aimport com.google.common.truth.FailureMetadata;%0Aimport com.google.common.truth.Subject;%0Aimport com.google.common.truth.Truth;%0Aimport java.sql.Timestamp;%0Aimport org.eclipse.jgit.lib.ObjectId;%0Aimport org.eclipse.jgit.revwalk.RevCommit;%0A%0A/** Subject over JGit %7B@link RevCommit%7Ds. */%0Apublic class CommitSubject extends Subject%3CCommitSubject, RevCommit%3E %7B%0A%0A  /**%0A   * Constructs a new subject.%0A   *%0A   * @param commit the commit.%0A   * @return a new subject over the commit.%0A   */%0A  public static CommitSubject assertThat(RevCommit commit) %7B%0A    return assertAbout(CommitSubject::new).that(commit);%0A  %7D%0A%0A  /**%0A   * Performs some common assertions over a single commit.%0A   *%0A   * @param commit the commit.%0A   * @param expectedCommitMessage exact expected commit message.%0A   * @param expectedCommitTimestamp expected commit timestamp, to the tolerance specified in %7B@link%0A   *     #hasCommitTimestamp(Timestamp)%7D.%0A   * @param expectedSha1 expected commit SHA-1.%0A   */%0A  public static void assertCommit(%0A      RevCommit commit,%0A      String expectedCommitMessage,%0A      Timestamp expectedCommitTimestamp,%0A      ObjectId expectedSha1) %7B%0A    CommitSubject commitSubject = assertThat(commit);%0A    commitSubject.hasCommitMessage(expectedCommitMessage);%0A    commitSubject.hasCommitTimestamp(expectedCommitTimestamp);%0A    commitSubject.hasSha1(expectedSha1);%0A  %7D%0A%0A  private CommitSubject(FailureMetadata metadata, RevCommit actual) %7B%0A    super(metadata, actual);%0A  %7D%0A%0A  /**%0A   * Asserts that the commit has the given commit message.%0A   *%0A   * @param expectedCommitMessage exact expected commit message.%0A   */%0A  public void hasCommitMessage(String expectedCommitMessage) %7B%0A    isNotNull();%0A    RevCommit commit = actual();%0A    Truth.assertThat(commit.getFullMessage())%0A        .named(%22commit message%22)%0A        .isEqualTo(expectedCommitMessage);%0A  %7D%0A%0A  /**%0A   * Asserts that the commit has the given commit message, up to skew of at most 1 second.%0A   *%0A   * @param expectedCommitTimestamp expected commit timestamp.%0A   */%0A  public void hasCommitTimestamp(Timestamp expectedCommitTimestamp) %7B%0A    isNotNull();%0A    RevCommit commit = actual();%0A    long timestampDiffMs =%0A        Math.abs(commit.getCommitTime() * 1000L - expectedCommitTimestamp.getTime());%0A    Truth.assertThat(timestampDiffMs).named(%22commit timestamp diff%22).isAtMost(SECONDS.toMillis(1));%0A  %7D%0A%0A  /**%0A   * Asserts that the commit has the given SHA-1.%0A   *%0A   * @param expectedSha1 expected commit SHA-1.%0A   */%0A  public void hasSha1(ObjectId expectedSha1) %7B%0A    isNotNull();%0A    RevCommit commit = actual();%0A    Truth.assertThat(commit).named(%22SHA1%22).isEqualTo(expectedSha1);%0A  %7D%0A%7D%0A

Add Truth subject for JGit RevCommits