Upgrade Truth to 0.36 and adapt to deprecations

Version 0.36 deprecates SubjectFactory [1] in favor of Subject.Factory
which takes FailureMetadata instead of FailureStrategy, and renames the
getSubject method to createSubject.

[1] https://google.github.io/truth/api/0.36/com/google/common/truth/SubjectFactory.html

Change-Id: Ic8c767b3da9e936e77639856d9f02af5c9059fdd
This commit is contained in:
David Pursehouse
2017-10-13 19:27:08 +09:00
parent 7426be10d9
commit 8ad8e5c646
18 changed files with 76 additions and 230 deletions

View File

@@ -709,18 +709,18 @@ maven_jar(
sha1 = "4785a3c21320980282f9f33d0d1264a69040538f", sha1 = "4785a3c21320980282f9f33d0d1264a69040538f",
) )
TRUTH_VERS = "0.35" TRUTH_VERS = "0.36"
maven_jar( maven_jar(
name = "truth", name = "truth",
artifact = "com.google.truth:truth:" + TRUTH_VERS, artifact = "com.google.truth:truth:" + TRUTH_VERS,
sha1 = "c08a7fde45e058323bcfa3f510d4fe1e2b028f37", sha1 = "7485219d2c1d341097a19382c02bde07e69ff5d2",
) )
maven_jar( maven_jar(
name = "truth-java8-extension", name = "truth-java8-extension",
artifact = "com.google.truth.extensions:truth-java8-extension:" + TRUTH_VERS, artifact = "com.google.truth.extensions:truth-java8-extension:" + TRUTH_VERS,
sha1 = "5457fdf91b1e954b070ad7f2db9bea5505da4bca", sha1 = "dcc60988c8f9a051840766ef192a2ef41e7992f1",
) )
# When bumping the easymock version number, make sure to also move powermock to a compatible version # When bumping the easymock version number, make sure to also move powermock to a compatible version

View File

@@ -21,9 +21,8 @@ import static com.google.gerrit.extensions.api.changes.RecipientType.TO;
import com.google.common.base.Joiner; import com.google.common.base.Joiner;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import com.google.common.truth.FailureStrategy; import com.google.common.truth.FailureMetadata;
import com.google.common.truth.Subject; import com.google.common.truth.Subject;
import com.google.common.truth.SubjectFactory;
import com.google.common.truth.Truth; import com.google.common.truth.Truth;
import com.google.gerrit.common.Nullable; import com.google.gerrit.common.Nullable;
import com.google.gerrit.extensions.api.changes.RecipientType; import com.google.gerrit.extensions.api.changes.RecipientType;
@@ -62,18 +61,8 @@ public abstract class AbstractNotificationTest extends AbstractDaemonTest {
gApi.projects().name(project.get()).config(conf); gApi.projects().name(project.get()).config(conf);
} }
private static final SubjectFactory<FakeEmailSenderSubject, FakeEmailSender>
FAKE_EMAIL_SENDER_SUBJECT_FACTORY =
new SubjectFactory<FakeEmailSenderSubject, FakeEmailSender>() {
@Override
public FakeEmailSenderSubject getSubject(
FailureStrategy failureStrategy, FakeEmailSender target) {
return new FakeEmailSenderSubject(failureStrategy, target);
}
};
protected static FakeEmailSenderSubject assertThat(FakeEmailSender sender) { protected static FakeEmailSenderSubject assertThat(FakeEmailSender sender) {
return assertAbout(FAKE_EMAIL_SENDER_SUBJECT_FACTORY).that(sender); return assertAbout(FakeEmailSenderSubject::new).that(sender);
} }
protected void setEmailStrategy(TestAccount account, EmailStrategy strategy) throws Exception { protected void setEmailStrategy(TestAccount account, EmailStrategy strategy) throws Exception {
@@ -98,8 +87,8 @@ public abstract class AbstractNotificationTest extends AbstractDaemonTest {
private Map<RecipientType, List<String>> recipients = new HashMap<>(); private Map<RecipientType, List<String>> recipients = new HashMap<>();
private Set<String> accountedFor = new HashSet<>(); private Set<String> accountedFor = new HashSet<>();
FakeEmailSenderSubject(FailureStrategy failureStrategy, FakeEmailSender target) { FakeEmailSenderSubject(FailureMetadata failureMetadata, FakeEmailSender target) {
super(failureStrategy, target); super(failureMetadata, target);
} }
public FakeEmailSenderSubject notSent() { public FakeEmailSenderSubject notSent() {

View File

@@ -17,10 +17,9 @@ package com.google.gerrit.server.edit.tree;
import static com.google.common.truth.Truth.assertAbout; import static com.google.common.truth.Truth.assertAbout;
import com.google.common.io.CharStreams; import com.google.common.io.CharStreams;
import com.google.common.truth.FailureStrategy; import com.google.common.truth.FailureMetadata;
import com.google.common.truth.StringSubject; import com.google.common.truth.StringSubject;
import com.google.common.truth.Subject; import com.google.common.truth.Subject;
import com.google.common.truth.SubjectFactory;
import com.google.common.truth.Truth; import com.google.common.truth.Truth;
import com.google.gerrit.extensions.restapi.RawInput; import com.google.gerrit.extensions.restapi.RawInput;
import java.io.IOException; import java.io.IOException;
@@ -30,26 +29,14 @@ import java.nio.charset.StandardCharsets;
public class ChangeFileContentModificationSubject public class ChangeFileContentModificationSubject
extends Subject<ChangeFileContentModificationSubject, ChangeFileContentModification> { extends Subject<ChangeFileContentModificationSubject, ChangeFileContentModification> {
private static final SubjectFactory<
ChangeFileContentModificationSubject, ChangeFileContentModification>
MODIFICATION_SUBJECT_FACTORY =
new SubjectFactory<
ChangeFileContentModificationSubject, ChangeFileContentModification>() {
@Override
public ChangeFileContentModificationSubject getSubject(
FailureStrategy failureStrategy, ChangeFileContentModification modification) {
return new ChangeFileContentModificationSubject(failureStrategy, modification);
}
};
public static ChangeFileContentModificationSubject assertThat( public static ChangeFileContentModificationSubject assertThat(
ChangeFileContentModification modification) { ChangeFileContentModification modification) {
return assertAbout(MODIFICATION_SUBJECT_FACTORY).that(modification); return assertAbout(ChangeFileContentModificationSubject::new).that(modification);
} }
private ChangeFileContentModificationSubject( private ChangeFileContentModificationSubject(
FailureStrategy failureStrategy, ChangeFileContentModification modification) { FailureMetadata failureMetadata, ChangeFileContentModification modification) {
super(failureStrategy, modification); super(failureMetadata, modification);
} }
public StringSubject filePath() { public StringSubject filePath() {

View File

@@ -16,26 +16,15 @@ package com.google.gerrit.server.edit.tree;
import static com.google.common.truth.Truth.assertAbout; import static com.google.common.truth.Truth.assertAbout;
import com.google.common.truth.FailureStrategy; import com.google.common.truth.FailureMetadata;
import com.google.common.truth.Subject; import com.google.common.truth.Subject;
import com.google.common.truth.SubjectFactory;
import com.google.gerrit.truth.ListSubject; import com.google.gerrit.truth.ListSubject;
import java.util.List; import java.util.List;
public class TreeModificationSubject extends Subject<TreeModificationSubject, TreeModification> { public class TreeModificationSubject extends Subject<TreeModificationSubject, TreeModification> {
private static final SubjectFactory<TreeModificationSubject, TreeModification>
TREE_MODIFICATION_SUBJECT_FACTORY =
new SubjectFactory<TreeModificationSubject, TreeModification>() {
@Override
public TreeModificationSubject getSubject(
FailureStrategy failureStrategy, TreeModification treeModification) {
return new TreeModificationSubject(failureStrategy, treeModification);
}
};
public static TreeModificationSubject assertThat(TreeModification treeModification) { public static TreeModificationSubject assertThat(TreeModification treeModification) {
return assertAbout(TREE_MODIFICATION_SUBJECT_FACTORY).that(treeModification); return assertAbout(TreeModificationSubject::new).that(treeModification);
} }
public static ListSubject<TreeModificationSubject, TreeModification> assertThatList( public static ListSubject<TreeModificationSubject, TreeModification> assertThatList(
@@ -45,8 +34,8 @@ public class TreeModificationSubject extends Subject<TreeModificationSubject, Tr
} }
private TreeModificationSubject( private TreeModificationSubject(
FailureStrategy failureStrategy, TreeModification treeModification) { FailureMetadata failureMetadata, TreeModification treeModification) {
super(failureStrategy, treeModification); super(failureMetadata, treeModification);
} }
public ChangeFileContentModificationSubject asChangeFileContentModification() { public ChangeFileContentModificationSubject asChangeFileContentModification() {

View File

@@ -16,28 +16,19 @@ package com.google.gerrit.extensions.client;
import static com.google.common.truth.Truth.assertAbout; import static com.google.common.truth.Truth.assertAbout;
import com.google.common.truth.FailureStrategy; import com.google.common.truth.FailureMetadata;
import com.google.common.truth.IntegerSubject; import com.google.common.truth.IntegerSubject;
import com.google.common.truth.Subject; import com.google.common.truth.Subject;
import com.google.common.truth.SubjectFactory;
import com.google.common.truth.Truth; import com.google.common.truth.Truth;
public class RangeSubject extends Subject<RangeSubject, Comment.Range> { public class RangeSubject extends Subject<RangeSubject, Comment.Range> {
private static final SubjectFactory<RangeSubject, Comment.Range> RANGE_SUBJECT_FACTORY =
new SubjectFactory<RangeSubject, Comment.Range>() {
@Override
public RangeSubject getSubject(FailureStrategy failureStrategy, Comment.Range range) {
return new RangeSubject(failureStrategy, range);
}
};
public static RangeSubject assertThat(Comment.Range range) { public static RangeSubject assertThat(Comment.Range range) {
return assertAbout(RANGE_SUBJECT_FACTORY).that(range); return assertAbout(RangeSubject::new).that(range);
} }
private RangeSubject(FailureStrategy failureStrategy, Comment.Range range) { private RangeSubject(FailureMetadata failureMetadata, Comment.Range range) {
super(failureStrategy, range); super(failureMetadata, range);
} }
public IntegerSubject startLine() { public IntegerSubject startLine() {

View File

@@ -16,30 +16,20 @@ package com.google.gerrit.extensions.common;
import static com.google.common.truth.Truth.assertAbout; import static com.google.common.truth.Truth.assertAbout;
import com.google.common.truth.FailureStrategy; import com.google.common.truth.FailureMetadata;
import com.google.common.truth.StringSubject; import com.google.common.truth.StringSubject;
import com.google.common.truth.Subject; import com.google.common.truth.Subject;
import com.google.common.truth.SubjectFactory;
import com.google.common.truth.Truth; import com.google.common.truth.Truth;
import com.google.gerrit.truth.ListSubject; import com.google.gerrit.truth.ListSubject;
public class CommitInfoSubject extends Subject<CommitInfoSubject, CommitInfo> { public class CommitInfoSubject extends Subject<CommitInfoSubject, CommitInfo> {
private static final SubjectFactory<CommitInfoSubject, CommitInfo> COMMIT_INFO_SUBJECT_FACTORY =
new SubjectFactory<CommitInfoSubject, CommitInfo>() {
@Override
public CommitInfoSubject getSubject(
FailureStrategy failureStrategy, CommitInfo commitInfo) {
return new CommitInfoSubject(failureStrategy, commitInfo);
}
};
public static CommitInfoSubject assertThat(CommitInfo commitInfo) { public static CommitInfoSubject assertThat(CommitInfo commitInfo) {
return assertAbout(COMMIT_INFO_SUBJECT_FACTORY).that(commitInfo); return assertAbout(CommitInfoSubject::new).that(commitInfo);
} }
private CommitInfoSubject(FailureStrategy failureStrategy, CommitInfo commitInfo) { private CommitInfoSubject(FailureMetadata failureMetadata, CommitInfo commitInfo) {
super(failureStrategy, commitInfo); super(failureMetadata, commitInfo);
} }
public StringSubject commit() { public StringSubject commit() {

View File

@@ -16,31 +16,21 @@ package com.google.gerrit.extensions.common;
import static com.google.common.truth.Truth.assertAbout; import static com.google.common.truth.Truth.assertAbout;
import com.google.common.truth.FailureStrategy; import com.google.common.truth.FailureMetadata;
import com.google.common.truth.StringSubject; import com.google.common.truth.StringSubject;
import com.google.common.truth.Subject; import com.google.common.truth.Subject;
import com.google.common.truth.SubjectFactory;
import com.google.common.truth.Truth; import com.google.common.truth.Truth;
import com.google.gerrit.extensions.common.DiffInfo.ContentEntry; import com.google.gerrit.extensions.common.DiffInfo.ContentEntry;
import com.google.gerrit.truth.ListSubject; import com.google.gerrit.truth.ListSubject;
public class ContentEntrySubject extends Subject<ContentEntrySubject, ContentEntry> { public class ContentEntrySubject extends Subject<ContentEntrySubject, ContentEntry> {
private static final SubjectFactory<ContentEntrySubject, ContentEntry> DIFF_INFO_SUBJECT_FACTORY =
new SubjectFactory<ContentEntrySubject, ContentEntry>() {
@Override
public ContentEntrySubject getSubject(
FailureStrategy failureStrategy, ContentEntry contentEntry) {
return new ContentEntrySubject(failureStrategy, contentEntry);
}
};
public static ContentEntrySubject assertThat(ContentEntry contentEntry) { public static ContentEntrySubject assertThat(ContentEntry contentEntry) {
return assertAbout(DIFF_INFO_SUBJECT_FACTORY).that(contentEntry); return assertAbout(ContentEntrySubject::new).that(contentEntry);
} }
private ContentEntrySubject(FailureStrategy failureStrategy, ContentEntry contentEntry) { private ContentEntrySubject(FailureMetadata failureMetadata, ContentEntry contentEntry) {
super(failureStrategy, contentEntry); super(failureMetadata, contentEntry);
} }
public void isDueToRebase() { public void isDueToRebase() {

View File

@@ -17,29 +17,20 @@ package com.google.gerrit.extensions.common;
import static com.google.common.truth.Truth.assertAbout; import static com.google.common.truth.Truth.assertAbout;
import com.google.common.truth.ComparableSubject; import com.google.common.truth.ComparableSubject;
import com.google.common.truth.FailureStrategy; import com.google.common.truth.FailureMetadata;
import com.google.common.truth.Subject; import com.google.common.truth.Subject;
import com.google.common.truth.SubjectFactory;
import com.google.common.truth.Truth; import com.google.common.truth.Truth;
import com.google.gerrit.extensions.common.DiffInfo.ContentEntry; import com.google.gerrit.extensions.common.DiffInfo.ContentEntry;
import com.google.gerrit.truth.ListSubject; import com.google.gerrit.truth.ListSubject;
public class DiffInfoSubject extends Subject<DiffInfoSubject, DiffInfo> { public class DiffInfoSubject extends Subject<DiffInfoSubject, DiffInfo> {
private static final SubjectFactory<DiffInfoSubject, DiffInfo> DIFF_INFO_SUBJECT_FACTORY =
new SubjectFactory<DiffInfoSubject, DiffInfo>() {
@Override
public DiffInfoSubject getSubject(FailureStrategy failureStrategy, DiffInfo diffInfo) {
return new DiffInfoSubject(failureStrategy, diffInfo);
}
};
public static DiffInfoSubject assertThat(DiffInfo diffInfo) { public static DiffInfoSubject assertThat(DiffInfo diffInfo) {
return assertAbout(DIFF_INFO_SUBJECT_FACTORY).that(diffInfo); return assertAbout(DiffInfoSubject::new).that(diffInfo);
} }
private DiffInfoSubject(FailureStrategy failureStrategy, DiffInfo diffInfo) { private DiffInfoSubject(FailureMetadata failureMetadata, DiffInfo diffInfo) {
super(failureStrategy, diffInfo); super(failureMetadata, diffInfo);
} }
public ListSubject<ContentEntrySubject, ContentEntry> content() { public ListSubject<ContentEntrySubject, ContentEntry> content() {

View File

@@ -16,26 +16,17 @@ package com.google.gerrit.extensions.common;
import static com.google.common.truth.Truth.assertAbout; import static com.google.common.truth.Truth.assertAbout;
import com.google.common.truth.FailureStrategy; import com.google.common.truth.FailureMetadata;
import com.google.common.truth.StringSubject; import com.google.common.truth.StringSubject;
import com.google.common.truth.Subject; import com.google.common.truth.Subject;
import com.google.common.truth.SubjectFactory;
import com.google.common.truth.Truth; import com.google.common.truth.Truth;
import com.google.gerrit.truth.OptionalSubject; import com.google.gerrit.truth.OptionalSubject;
import java.util.Optional; import java.util.Optional;
public class EditInfoSubject extends Subject<EditInfoSubject, EditInfo> { public class EditInfoSubject extends Subject<EditInfoSubject, EditInfo> {
private static final SubjectFactory<EditInfoSubject, EditInfo> EDIT_INFO_SUBJECT_FACTORY =
new SubjectFactory<EditInfoSubject, EditInfo>() {
@Override
public EditInfoSubject getSubject(FailureStrategy failureStrategy, EditInfo editInfo) {
return new EditInfoSubject(failureStrategy, editInfo);
}
};
public static EditInfoSubject assertThat(EditInfo editInfo) { public static EditInfoSubject assertThat(EditInfo editInfo) {
return assertAbout(EDIT_INFO_SUBJECT_FACTORY).that(editInfo); return assertAbout(EditInfoSubject::new).that(editInfo);
} }
public static OptionalSubject<EditInfoSubject, EditInfo> assertThat( public static OptionalSubject<EditInfoSubject, EditInfo> assertThat(
@@ -43,8 +34,8 @@ public class EditInfoSubject extends Subject<EditInfoSubject, EditInfo> {
return OptionalSubject.assertThat(editInfoOptional, EditInfoSubject::assertThat); return OptionalSubject.assertThat(editInfoOptional, EditInfoSubject::assertThat);
} }
private EditInfoSubject(FailureStrategy failureStrategy, EditInfo editInfo) { private EditInfoSubject(FailureMetadata failureMetadata, EditInfo editInfo) {
super(failureStrategy, editInfo); super(failureMetadata, editInfo);
} }
public CommitInfoSubject commit() { public CommitInfoSubject commit() {

View File

@@ -17,28 +17,19 @@ package com.google.gerrit.extensions.common;
import static com.google.common.truth.Truth.assertAbout; import static com.google.common.truth.Truth.assertAbout;
import com.google.common.truth.ComparableSubject; import com.google.common.truth.ComparableSubject;
import com.google.common.truth.FailureStrategy; import com.google.common.truth.FailureMetadata;
import com.google.common.truth.IntegerSubject; import com.google.common.truth.IntegerSubject;
import com.google.common.truth.Subject; import com.google.common.truth.Subject;
import com.google.common.truth.SubjectFactory;
import com.google.common.truth.Truth; import com.google.common.truth.Truth;
public class FileInfoSubject extends Subject<FileInfoSubject, FileInfo> { public class FileInfoSubject extends Subject<FileInfoSubject, FileInfo> {
private static final SubjectFactory<FileInfoSubject, FileInfo> FILE_INFO_SUBJECT_FACTORY =
new SubjectFactory<FileInfoSubject, FileInfo>() {
@Override
public FileInfoSubject getSubject(FailureStrategy failureStrategy, FileInfo fileInfo) {
return new FileInfoSubject(failureStrategy, fileInfo);
}
};
public static FileInfoSubject assertThat(FileInfo fileInfo) { public static FileInfoSubject assertThat(FileInfo fileInfo) {
return assertAbout(FILE_INFO_SUBJECT_FACTORY).that(fileInfo); return assertAbout(FileInfoSubject::new).that(fileInfo);
} }
private FileInfoSubject(FailureStrategy failureStrategy, FileInfo fileInfo) { private FileInfoSubject(FailureMetadata failureMetadata, FileInfo fileInfo) {
super(failureStrategy, fileInfo); super(failureMetadata, fileInfo);
} }
public IntegerSubject linesInserted() { public IntegerSubject linesInserted() {

View File

@@ -16,33 +16,22 @@ package com.google.gerrit.extensions.common;
import static com.google.common.truth.Truth.assertAbout; import static com.google.common.truth.Truth.assertAbout;
import com.google.common.truth.FailureStrategy; import com.google.common.truth.FailureMetadata;
import com.google.common.truth.StringSubject; import com.google.common.truth.StringSubject;
import com.google.common.truth.Subject; import com.google.common.truth.Subject;
import com.google.common.truth.SubjectFactory;
import com.google.common.truth.Truth; import com.google.common.truth.Truth;
import com.google.gerrit.extensions.client.RangeSubject; import com.google.gerrit.extensions.client.RangeSubject;
public class FixReplacementInfoSubject public class FixReplacementInfoSubject
extends Subject<FixReplacementInfoSubject, FixReplacementInfo> { extends Subject<FixReplacementInfoSubject, FixReplacementInfo> {
private static final SubjectFactory<FixReplacementInfoSubject, FixReplacementInfo>
FIX_REPLACEMENT_INFO_SUBJECT_FACTORY =
new SubjectFactory<FixReplacementInfoSubject, FixReplacementInfo>() {
@Override
public FixReplacementInfoSubject getSubject(
FailureStrategy failureStrategy, FixReplacementInfo fixReplacementInfo) {
return new FixReplacementInfoSubject(failureStrategy, fixReplacementInfo);
}
};
public static FixReplacementInfoSubject assertThat(FixReplacementInfo fixReplacementInfo) { public static FixReplacementInfoSubject assertThat(FixReplacementInfo fixReplacementInfo) {
return assertAbout(FIX_REPLACEMENT_INFO_SUBJECT_FACTORY).that(fixReplacementInfo); return assertAbout(FixReplacementInfoSubject::new).that(fixReplacementInfo);
} }
private FixReplacementInfoSubject( private FixReplacementInfoSubject(
FailureStrategy failureStrategy, FixReplacementInfo fixReplacementInfo) { FailureMetadata failureMetadata, FixReplacementInfo fixReplacementInfo) {
super(failureStrategy, fixReplacementInfo); super(failureMetadata, fixReplacementInfo);
} }
public StringSubject path() { public StringSubject path() {

View File

@@ -16,32 +16,21 @@ package com.google.gerrit.extensions.common;
import static com.google.common.truth.Truth.assertAbout; import static com.google.common.truth.Truth.assertAbout;
import com.google.common.truth.FailureStrategy; import com.google.common.truth.FailureMetadata;
import com.google.common.truth.StringSubject; import com.google.common.truth.StringSubject;
import com.google.common.truth.Subject; import com.google.common.truth.Subject;
import com.google.common.truth.SubjectFactory;
import com.google.common.truth.Truth; import com.google.common.truth.Truth;
import com.google.gerrit.truth.ListSubject; import com.google.gerrit.truth.ListSubject;
public class FixSuggestionInfoSubject extends Subject<FixSuggestionInfoSubject, FixSuggestionInfo> { public class FixSuggestionInfoSubject extends Subject<FixSuggestionInfoSubject, FixSuggestionInfo> {
private static final SubjectFactory<FixSuggestionInfoSubject, FixSuggestionInfo>
FIX_SUGGESTION_INFO_SUBJECT_FACTORY =
new SubjectFactory<FixSuggestionInfoSubject, FixSuggestionInfo>() {
@Override
public FixSuggestionInfoSubject getSubject(
FailureStrategy failureStrategy, FixSuggestionInfo fixSuggestionInfo) {
return new FixSuggestionInfoSubject(failureStrategy, fixSuggestionInfo);
}
};
public static FixSuggestionInfoSubject assertThat(FixSuggestionInfo fixSuggestionInfo) { public static FixSuggestionInfoSubject assertThat(FixSuggestionInfo fixSuggestionInfo) {
return assertAbout(FIX_SUGGESTION_INFO_SUBJECT_FACTORY).that(fixSuggestionInfo); return assertAbout(FixSuggestionInfoSubject::new).that(fixSuggestionInfo);
} }
private FixSuggestionInfoSubject( private FixSuggestionInfoSubject(
FailureStrategy failureStrategy, FixSuggestionInfo fixSuggestionInfo) { FailureMetadata failureMetadata, FixSuggestionInfo fixSuggestionInfo) {
super(failureStrategy, fixSuggestionInfo); super(failureMetadata, fixSuggestionInfo);
} }
public StringSubject fixId() { public StringSubject fixId() {

View File

@@ -17,28 +17,19 @@ package com.google.gerrit.extensions.common;
import static com.google.common.truth.Truth.assertAbout; import static com.google.common.truth.Truth.assertAbout;
import com.google.common.truth.ComparableSubject; import com.google.common.truth.ComparableSubject;
import com.google.common.truth.FailureStrategy; import com.google.common.truth.FailureMetadata;
import com.google.common.truth.Subject; import com.google.common.truth.Subject;
import com.google.common.truth.SubjectFactory;
import com.google.common.truth.Truth; import com.google.common.truth.Truth;
import java.sql.Timestamp; import java.sql.Timestamp;
public class GitPersonSubject extends Subject<GitPersonSubject, GitPerson> { public class GitPersonSubject extends Subject<GitPersonSubject, GitPerson> {
private static final SubjectFactory<GitPersonSubject, GitPerson> GIT_PERSON_SUBJECT_FACTORY =
new SubjectFactory<GitPersonSubject, GitPerson>() {
@Override
public GitPersonSubject getSubject(FailureStrategy failureStrategy, GitPerson gitPerson) {
return new GitPersonSubject(failureStrategy, gitPerson);
}
};
public static GitPersonSubject assertThat(GitPerson gitPerson) { public static GitPersonSubject assertThat(GitPerson gitPerson) {
return assertAbout(GIT_PERSON_SUBJECT_FACTORY).that(gitPerson); return assertAbout(GitPersonSubject::new).that(gitPerson);
} }
private GitPersonSubject(FailureStrategy failureStrategy, GitPerson gitPerson) { private GitPersonSubject(FailureMetadata failureMetadata, GitPerson gitPerson) {
super(failureStrategy, gitPerson); super(failureMetadata, gitPerson);
} }
public ComparableSubject<?, Timestamp> creationDate() { public ComparableSubject<?, Timestamp> creationDate() {

View File

@@ -16,25 +16,16 @@ package com.google.gerrit.extensions.common;
import static com.google.common.truth.Truth.assertAbout; import static com.google.common.truth.Truth.assertAbout;
import com.google.common.truth.FailureStrategy; import com.google.common.truth.FailureMetadata;
import com.google.common.truth.Subject; import com.google.common.truth.Subject;
import com.google.common.truth.SubjectFactory;
import java.nio.file.Path; import java.nio.file.Path;
public class PathSubject extends Subject<PathSubject, Path> { public class PathSubject extends Subject<PathSubject, Path> {
private static final SubjectFactory<PathSubject, Path> PATH_SUBJECT_FACTORY = private PathSubject(FailureMetadata failureMetadata, Path path) {
new SubjectFactory<PathSubject, Path>() { super(failureMetadata, path);
@Override
public PathSubject getSubject(FailureStrategy failureStrategy, Path path) {
return new PathSubject(failureStrategy, path);
}
};
private PathSubject(FailureStrategy failureStrategy, Path path) {
super(failureStrategy, path);
} }
public static PathSubject assertThat(Path path) { public static PathSubject assertThat(Path path) {
return assertAbout(PATH_SUBJECT_FACTORY).that(path); return assertAbout(PathSubject::new).that(path);
} }
} }

View File

@@ -16,24 +16,13 @@ package com.google.gerrit.extensions.common;
import static com.google.common.truth.Truth.assertAbout; import static com.google.common.truth.Truth.assertAbout;
import com.google.common.truth.FailureStrategy; import com.google.common.truth.FailureMetadata;
import com.google.common.truth.Subject; import com.google.common.truth.Subject;
import com.google.common.truth.SubjectFactory;
import com.google.gerrit.truth.ListSubject; import com.google.gerrit.truth.ListSubject;
import java.util.List; import java.util.List;
public class RobotCommentInfoSubject extends Subject<RobotCommentInfoSubject, RobotCommentInfo> { public class RobotCommentInfoSubject extends Subject<RobotCommentInfoSubject, RobotCommentInfo> {
private static final SubjectFactory<RobotCommentInfoSubject, RobotCommentInfo>
ROBOT_COMMENT_INFO_SUBJECT_FACTORY =
new SubjectFactory<RobotCommentInfoSubject, RobotCommentInfo>() {
@Override
public RobotCommentInfoSubject getSubject(
FailureStrategy failureStrategy, RobotCommentInfo robotCommentInfo) {
return new RobotCommentInfoSubject(failureStrategy, robotCommentInfo);
}
};
public static ListSubject<RobotCommentInfoSubject, RobotCommentInfo> assertThatList( public static ListSubject<RobotCommentInfoSubject, RobotCommentInfo> assertThatList(
List<RobotCommentInfo> robotCommentInfos) { List<RobotCommentInfo> robotCommentInfos) {
return ListSubject.assertThat(robotCommentInfos, RobotCommentInfoSubject::assertThat) return ListSubject.assertThat(robotCommentInfos, RobotCommentInfoSubject::assertThat)
@@ -41,12 +30,12 @@ public class RobotCommentInfoSubject extends Subject<RobotCommentInfoSubject, Ro
} }
public static RobotCommentInfoSubject assertThat(RobotCommentInfo robotCommentInfo) { public static RobotCommentInfoSubject assertThat(RobotCommentInfo robotCommentInfo) {
return assertAbout(ROBOT_COMMENT_INFO_SUBJECT_FACTORY).that(robotCommentInfo); return assertAbout(RobotCommentInfoSubject::new).that(robotCommentInfo);
} }
private RobotCommentInfoSubject( private RobotCommentInfoSubject(
FailureStrategy failureStrategy, RobotCommentInfo robotCommentInfo) { FailureMetadata failureMetadata, RobotCommentInfo robotCommentInfo) {
super(failureStrategy, robotCommentInfo); super(failureMetadata, robotCommentInfo);
} }
public ListSubject<FixSuggestionInfoSubject, FixSuggestionInfo> fixSuggestions() { public ListSubject<FixSuggestionInfoSubject, FixSuggestionInfo> fixSuggestions() {

View File

@@ -16,11 +16,10 @@ package com.google.gerrit.extensions.restapi;
import static com.google.common.truth.Truth.assertAbout; import static com.google.common.truth.Truth.assertAbout;
import com.google.common.truth.FailureStrategy; import com.google.common.truth.FailureMetadata;
import com.google.common.truth.PrimitiveByteArraySubject; import com.google.common.truth.PrimitiveByteArraySubject;
import com.google.common.truth.StringSubject; import com.google.common.truth.StringSubject;
import com.google.common.truth.Subject; import com.google.common.truth.Subject;
import com.google.common.truth.SubjectFactory;
import com.google.common.truth.Truth; import com.google.common.truth.Truth;
import com.google.gerrit.truth.OptionalSubject; import com.google.gerrit.truth.OptionalSubject;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
@@ -29,18 +28,8 @@ import java.util.Optional;
public class BinaryResultSubject extends Subject<BinaryResultSubject, BinaryResult> { public class BinaryResultSubject extends Subject<BinaryResultSubject, BinaryResult> {
private static final SubjectFactory<BinaryResultSubject, BinaryResult>
BINARY_RESULT_SUBJECT_FACTORY =
new SubjectFactory<BinaryResultSubject, BinaryResult>() {
@Override
public BinaryResultSubject getSubject(
FailureStrategy failureStrategy, BinaryResult binaryResult) {
return new BinaryResultSubject(failureStrategy, binaryResult);
}
};
public static BinaryResultSubject assertThat(BinaryResult binaryResult) { public static BinaryResultSubject assertThat(BinaryResult binaryResult) {
return assertAbout(BINARY_RESULT_SUBJECT_FACTORY).that(binaryResult); return assertAbout(BinaryResultSubject::new).that(binaryResult);
} }
public static OptionalSubject<BinaryResultSubject, BinaryResult> assertThat( public static OptionalSubject<BinaryResultSubject, BinaryResult> assertThat(
@@ -48,8 +37,8 @@ public class BinaryResultSubject extends Subject<BinaryResultSubject, BinaryResu
return OptionalSubject.assertThat(binaryResultOptional, BinaryResultSubject::assertThat); return OptionalSubject.assertThat(binaryResultOptional, BinaryResultSubject::assertThat);
} }
private BinaryResultSubject(FailureStrategy failureStrategy, BinaryResult binaryResult) { private BinaryResultSubject(FailureMetadata failureMetadata, BinaryResult binaryResult) {
super(failureStrategy, binaryResult); super(failureMetadata, binaryResult);
} }
public StringSubject asString() throws IOException { public StringSubject asString() throws IOException {

View File

@@ -17,10 +17,9 @@ package com.google.gerrit.truth;
import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.truth.Truth.assertAbout; import static com.google.common.truth.Truth.assertAbout;
import com.google.common.truth.FailureStrategy; import com.google.common.truth.FailureMetadata;
import com.google.common.truth.IterableSubject; import com.google.common.truth.IterableSubject;
import com.google.common.truth.Subject; import com.google.common.truth.Subject;
import com.google.common.truth.SubjectFactory;
import java.util.List; import java.util.List;
import java.util.function.Function; import java.util.function.Function;
@@ -38,8 +37,8 @@ public class ListSubject<S extends Subject<S, E>, E> extends IterableSubject {
} }
private ListSubject( private ListSubject(
FailureStrategy failureStrategy, List<E> list, Function<E, S> elementAssertThatFunction) { FailureMetadata failureMetadata, List<E> list, Function<E, S> elementAssertThatFunction) {
super(failureStrategy, list); super(failureMetadata, list);
this.elementAssertThatFunction = elementAssertThatFunction; this.elementAssertThatFunction = elementAssertThatFunction;
} }
@@ -71,7 +70,7 @@ public class ListSubject<S extends Subject<S, E>, E> extends IterableSubject {
} }
private static class ListSubjectFactory<S extends Subject<S, T>, T> private static class ListSubjectFactory<S extends Subject<S, T>, T>
extends SubjectFactory<IterableSubject, Iterable<?>> { implements Subject.Factory<IterableSubject, Iterable<?>> {
private Function<T, S> elementAssertThatFunction; private Function<T, S> elementAssertThatFunction;
@@ -81,10 +80,10 @@ public class ListSubject<S extends Subject<S, E>, E> extends IterableSubject {
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
@Override @Override
public ListSubject<S, T> getSubject(FailureStrategy failureStrategy, Iterable<?> objects) { public ListSubject<S, T> createSubject(FailureMetadata failureMetadata, Iterable<?> objects) {
// The constructor of ListSubject only accepts lists. // The constructor of ListSubject only accepts lists.
// -> Casting is appropriate. // -> Casting is appropriate.
return new ListSubject<>(failureStrategy, (List<T>) objects, elementAssertThatFunction); return new ListSubject<>(failureMetadata, (List<T>) objects, elementAssertThatFunction);
} }
} }
} }

View File

@@ -17,9 +17,8 @@ package com.google.gerrit.truth;
import static com.google.common.truth.Truth.assertAbout; import static com.google.common.truth.Truth.assertAbout;
import com.google.common.truth.DefaultSubject; import com.google.common.truth.DefaultSubject;
import com.google.common.truth.FailureStrategy; import com.google.common.truth.FailureMetadata;
import com.google.common.truth.Subject; import com.google.common.truth.Subject;
import com.google.common.truth.SubjectFactory;
import com.google.common.truth.Truth; import com.google.common.truth.Truth;
import java.util.Optional; import java.util.Optional;
import java.util.function.Function; import java.util.function.Function;
@@ -47,10 +46,10 @@ public class OptionalSubject<S extends Subject<S, ? super T>, T>
} }
private OptionalSubject( private OptionalSubject(
FailureStrategy failureStrategy, FailureMetadata failureMetadata,
Optional<T> optional, Optional<T> optional,
Function<? super T, ? extends S> valueAssertThatFunction) { Function<? super T, ? extends S> valueAssertThatFunction) {
super(failureStrategy, optional); super(failureMetadata, optional);
this.valueAssertThatFunction = valueAssertThatFunction; this.valueAssertThatFunction = valueAssertThatFunction;
} }
@@ -82,7 +81,7 @@ public class OptionalSubject<S extends Subject<S, ? super T>, T>
} }
private static class OptionalSubjectFactory<S extends Subject<S, ? super T>, T> private static class OptionalSubjectFactory<S extends Subject<S, ? super T>, T>
extends SubjectFactory<OptionalSubject<S, T>, Optional<T>> { implements Subject.Factory<OptionalSubject<S, T>, Optional<T>> {
private Function<? super T, ? extends S> valueAssertThatFunction; private Function<? super T, ? extends S> valueAssertThatFunction;
@@ -91,8 +90,9 @@ public class OptionalSubject<S extends Subject<S, ? super T>, T>
} }
@Override @Override
public OptionalSubject<S, T> getSubject(FailureStrategy failureStrategy, Optional<T> optional) { public OptionalSubject<S, T> createSubject(
return new OptionalSubject<>(failureStrategy, optional, valueAssertThatFunction); FailureMetadata failureMetadata, Optional<T> optional) {
return new OptionalSubject<>(failureMetadata, optional, valueAssertThatFunction);
} }
} }
} }