Extend raw Subject instead of supplying type parameters.

The type parameters are being removed from Subject. This CL will temporarily produce rawtypes warnings, which will go away when I remove the type parameters (as soon as this batch of CLs is submitted -- see https://github.com/google/truth/releases/tag/release_0_45).

Similarly, this CL changes custom subjects to extend raw ComparableSubject instead of supplying type parameters. The self-type parameter is being removed from ComparableSubject. In order to remove one type parameter while leaving the other in place, it's necessary either to make an atomic change (which is tricky for third-party code) or to temporarily remove *both* type parameters and then put the one back. This CL implements the latter. Again, this CL will temporarily produce rawtypes warnings -- and temporarily eliminate type-checking of calls to the ComparableSubject methods -- which will go away when I remove the type parameters (as soon as this batch of CLs is submitted).

This change requires Truth 0.45, which you've already updated to.

Change-Id: I75f3d1510b4c0cb06fd272b48be65e0cfd61973e
This commit is contained in:
Chris Povirk
2019-06-04 16:46:24 -04:00
committed by David Pursehouse
parent 9eee01a737
commit 5f040fb432
26 changed files with 48 additions and 65 deletions

View File

@@ -95,8 +95,7 @@ public abstract class AbstractNotificationTest extends AbstractDaemonTest {
gApi.accounts().self().setPreferences(prefs);
}
protected static class FakeEmailSenderSubject
extends Subject<FakeEmailSenderSubject, FakeEmailSender> {
protected static class FakeEmailSenderSubject extends Subject {
private final FakeEmailSender fakeEmailSender;
private Message message;
private StagedUsers users;

View File

@@ -21,9 +21,8 @@ import com.google.common.truth.FailureMetadata;
import com.google.common.truth.StringSubject;
import com.google.common.truth.Subject;
import com.google.gerrit.common.data.GroupReference;
import com.google.gerrit.reviewdb.client.AccountGroup;
public class GroupReferenceSubject extends Subject<GroupReferenceSubject, GroupReference> {
public class GroupReferenceSubject extends Subject {
public static GroupReferenceSubject assertThat(GroupReference group) {
return assertAbout(groupReferences()).that(group);
@@ -40,7 +39,7 @@ public class GroupReferenceSubject extends Subject<GroupReferenceSubject, GroupR
this.group = group;
}
public ComparableSubject<?, AccountGroup.UUID> groupUuid() {
public ComparableSubject groupUuid() {
isNotNull();
return check("getUUID()").that(group.getUUID());
}

View File

@@ -24,7 +24,7 @@ import com.google.common.truth.Subject;
import com.google.gerrit.extensions.common.CommitInfo;
import com.google.gerrit.truth.ListSubject;
public class CommitInfoSubject extends Subject<CommitInfoSubject, CommitInfo> {
public class CommitInfoSubject extends Subject {
public static CommitInfoSubject assertThat(CommitInfo commitInfo) {
return assertAbout(commits()).that(commitInfo);

View File

@@ -27,7 +27,7 @@ import com.google.common.truth.Subject;
import com.google.gerrit.extensions.common.DiffInfo.ContentEntry;
import com.google.gerrit.truth.ListSubject;
public class ContentEntrySubject extends Subject<ContentEntrySubject, ContentEntry> {
public class ContentEntrySubject extends Subject {
public static ContentEntrySubject assertThat(ContentEntry contentEntry) {
return assertAbout(contentEntries()).that(contentEntry);

View File

@@ -21,12 +21,11 @@ import static com.google.gerrit.truth.ListSubject.elements;
import com.google.common.truth.ComparableSubject;
import com.google.common.truth.FailureMetadata;
import com.google.common.truth.Subject;
import com.google.gerrit.extensions.common.ChangeType;
import com.google.gerrit.extensions.common.DiffInfo;
import com.google.gerrit.extensions.common.DiffInfo.ContentEntry;
import com.google.gerrit.truth.ListSubject;
public class DiffInfoSubject extends Subject<DiffInfoSubject, DiffInfo> {
public class DiffInfoSubject extends Subject {
public static DiffInfoSubject assertThat(DiffInfo diffInfo) {
return assertAbout(DiffInfoSubject::new).that(diffInfo);
@@ -46,7 +45,7 @@ public class DiffInfoSubject extends Subject<DiffInfoSubject, DiffInfo> {
.thatCustom(diffInfo.content, ContentEntrySubject.contentEntries());
}
public ComparableSubject<?, ChangeType> changeType() {
public ComparableSubject changeType() {
isNotNull();
return check("changeType").that(diffInfo.changeType);
}

View File

@@ -24,7 +24,7 @@ import com.google.gerrit.extensions.common.EditInfo;
import com.google.gerrit.truth.OptionalSubject;
import java.util.Optional;
public class EditInfoSubject extends Subject<EditInfoSubject, EditInfo> {
public class EditInfoSubject extends Subject {
public static EditInfoSubject assertThat(EditInfo editInfo) {
return assertAbout(edits()).that(editInfo);

View File

@@ -22,7 +22,7 @@ import com.google.common.truth.IntegerSubject;
import com.google.common.truth.Subject;
import com.google.gerrit.extensions.common.FileInfo;
public class FileInfoSubject extends Subject<FileInfoSubject, FileInfo> {
public class FileInfoSubject extends Subject {
public static FileInfoSubject assertThat(FileInfo fileInfo) {
return assertAbout(FileInfoSubject::new).that(fileInfo);
@@ -45,7 +45,7 @@ public class FileInfoSubject extends Subject<FileInfoSubject, FileInfo> {
return check("linesDeleted").that(fileInfo.linesDeleted);
}
public ComparableSubject<?, Character> status() {
public ComparableSubject status() {
isNotNull();
return check("status").that(fileInfo.status);
}

View File

@@ -21,7 +21,7 @@ import com.google.common.truth.IntegerSubject;
import com.google.common.truth.Subject;
import com.google.gerrit.extensions.common.DiffInfo.FileMeta;
public class FileMetaSubject extends Subject<FileMetaSubject, FileMeta> {
public class FileMetaSubject extends Subject {
public static FileMetaSubject assertThat(FileMeta fileMeta) {
return assertAbout(fileMetas()).that(fileMeta);

View File

@@ -22,8 +22,7 @@ import com.google.common.truth.StringSubject;
import com.google.common.truth.Subject;
import com.google.gerrit.extensions.common.FixReplacementInfo;
public class FixReplacementInfoSubject
extends Subject<FixReplacementInfoSubject, FixReplacementInfo> {
public class FixReplacementInfoSubject extends Subject {
public static FixReplacementInfoSubject assertThat(FixReplacementInfo fixReplacementInfo) {
return assertAbout(fixReplacements()).that(fixReplacementInfo);

View File

@@ -25,7 +25,7 @@ import com.google.gerrit.extensions.common.FixReplacementInfo;
import com.google.gerrit.extensions.common.FixSuggestionInfo;
import com.google.gerrit.truth.ListSubject;
public class FixSuggestionInfoSubject extends Subject<FixSuggestionInfoSubject, FixSuggestionInfo> {
public class FixSuggestionInfoSubject extends Subject {
public static FixSuggestionInfoSubject assertThat(FixSuggestionInfo fixSuggestionInfo) {
return assertAbout(fixSuggestions()).that(fixSuggestionInfo);

View File

@@ -23,11 +23,10 @@ import com.google.common.truth.IntegerSubject;
import com.google.common.truth.StringSubject;
import com.google.common.truth.Subject;
import com.google.gerrit.extensions.common.GitPerson;
import java.sql.Timestamp;
import java.util.Date;
import org.eclipse.jgit.lib.PersonIdent;
public class GitPersonSubject extends Subject<GitPersonSubject, GitPerson> {
public class GitPersonSubject extends Subject {
public static GitPersonSubject assertThat(GitPerson gitPerson) {
return assertAbout(gitPersons()).that(gitPerson);
@@ -54,7 +53,7 @@ public class GitPersonSubject extends Subject<GitPersonSubject, GitPerson> {
return check("email").that(gitPerson.email);
}
public ComparableSubject<?, Timestamp> date() {
public ComparableSubject date() {
isNotNull();
return check("date").that(gitPerson.date);
}

View File

@@ -22,7 +22,7 @@ import com.google.common.truth.IntegerSubject;
import com.google.common.truth.Subject;
import com.google.gerrit.extensions.client.Comment;
public class RangeSubject extends Subject<RangeSubject, Comment.Range> {
public class RangeSubject extends Subject {
public static RangeSubject assertThat(Comment.Range range) {
return assertAbout(ranges()).that(range);

View File

@@ -24,7 +24,7 @@ import com.google.gerrit.extensions.common.RobotCommentInfo;
import com.google.gerrit.truth.ListSubject;
import java.util.List;
public class RobotCommentInfoSubject extends Subject<RobotCommentInfoSubject, RobotCommentInfo> {
public class RobotCommentInfoSubject extends Subject {
public static ListSubject<RobotCommentInfoSubject, RobotCommentInfo> assertThatList(
List<RobotCommentInfo> robotCommentInfos) {

View File

@@ -26,7 +26,7 @@ import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.util.Optional;
public class BinaryResultSubject extends Subject<BinaryResultSubject, BinaryResult> {
public class BinaryResultSubject extends Subject {
public static BinaryResultSubject assertThat(BinaryResult binaryResult) {
return assertAbout(binaryResults()).that(binaryResult);

View File

@@ -24,7 +24,7 @@ import org.eclipse.jgit.lib.ObjectId;
import org.eclipse.jgit.revwalk.RevCommit;
/** Subject over JGit {@link RevCommit}s. */
public class CommitSubject extends Subject<CommitSubject, RevCommit> {
public class CommitSubject extends Subject {
/**
* Constructs a new subject.

View File

@@ -20,7 +20,7 @@ import com.google.common.truth.FailureMetadata;
import com.google.common.truth.Subject;
import org.eclipse.jgit.lib.ObjectId;
public class ObjectIdSubject extends Subject<ObjectIdSubject, ObjectId> {
public class ObjectIdSubject extends Subject {
public static ObjectIdSubject assertThat(ObjectId objectId) {
return assertAbout(objectIds()).that(objectId);
}

View File

@@ -32,7 +32,7 @@ import com.google.gerrit.common.Nullable;
import org.eclipse.jgit.transport.PushResult;
import org.eclipse.jgit.transport.RemoteRefUpdate;
public class PushResultSubject extends Subject<PushResultSubject, PushResult> {
public class PushResultSubject extends Subject {
public static PushResultSubject assertThat(PushResult actual) {
return assertAbout(PushResultSubject::new).that(actual);
}
@@ -139,8 +139,7 @@ public class PushResultSubject extends Subject<PushResultSubject, PushResult> {
return ref(refName);
}
public static class RemoteRefUpdateSubject
extends Subject<RemoteRefUpdateSubject, RemoteRefUpdate> {
public static class RemoteRefUpdateSubject extends Subject {
private final RemoteRefUpdate remoteRefUpdate;
private RemoteRefUpdateSubject(FailureMetadata metadata, RemoteRefUpdate remoteRefUpdate) {

View File

@@ -23,7 +23,7 @@ import com.google.common.truth.Subject;
import com.google.gerrit.index.query.QueryParser;
import org.antlr.runtime.tree.Tree;
public class TreeSubject extends Subject<TreeSubject, Tree> {
public class TreeSubject extends Subject {
public static TreeSubject assertThat(Tree actual) {
return assertAbout(TreeSubject::new).that(actual);
}

View File

@@ -48,7 +48,7 @@ import org.apache.commons.lang3.reflect.FieldUtils;
* the hand-written serializer. Usually, serializer implementations should be written in such a way
* that new fields are considered optional, and won't require bumping the version.
*/
public class SerializedClassSubject extends Subject<SerializedClassSubject, Class<?>> {
public class SerializedClassSubject extends Subject {
public static SerializedClassSubject assertThatSerializedClass(Class<?> actual) {
// This formulation fails in Eclipse 4.7.3a with "The type
// SerializedClassSubject does not define SerializedClassSubject() that is

View File

@@ -22,12 +22,9 @@ import com.google.common.truth.FailureMetadata;
import com.google.common.truth.IterableSubject;
import com.google.common.truth.StringSubject;
import com.google.common.truth.Subject;
import com.google.gerrit.reviewdb.client.AccountGroup;
import com.google.gerrit.server.group.InternalGroup;
import java.sql.Timestamp;
import org.eclipse.jgit.lib.ObjectId;
public class InternalGroupSubject extends Subject<InternalGroupSubject, InternalGroup> {
public class InternalGroupSubject extends Subject {
public static InternalGroupSubject assertThat(InternalGroup group) {
return assertAbout(internalGroups()).that(group);
@@ -44,12 +41,12 @@ public class InternalGroupSubject extends Subject<InternalGroupSubject, Internal
this.group = group;
}
public ComparableSubject<?, AccountGroup.UUID> groupUuid() {
public ComparableSubject groupUuid() {
isNotNull();
return check("getGroupUUID()").that(group.getGroupUUID());
}
public ComparableSubject<?, AccountGroup.NameKey> nameKey() {
public ComparableSubject nameKey() {
isNotNull();
return check("getNameKey()").that(group.getNameKey());
}
@@ -59,7 +56,7 @@ public class InternalGroupSubject extends Subject<InternalGroupSubject, Internal
return check("getName()").that(group.getName());
}
public Subject<?, ?> id() {
public Subject id() {
isNotNull();
return check("getId()").that(group.getId());
}
@@ -69,7 +66,7 @@ public class InternalGroupSubject extends Subject<InternalGroupSubject, Internal
return check("getDescription()").that(group.getDescription());
}
public ComparableSubject<?, AccountGroup.UUID> ownerGroupUuid() {
public ComparableSubject ownerGroupUuid() {
isNotNull();
return check("getOwnerGroupUUID()").that(group.getOwnerGroupUUID());
}
@@ -79,7 +76,7 @@ public class InternalGroupSubject extends Subject<InternalGroupSubject, Internal
return check("isVisibleToAll()").that(group.isVisibleToAll());
}
public ComparableSubject<?, Timestamp> createdOn() {
public ComparableSubject createdOn() {
isNotNull();
return check("getCreatedOn()").that(group.getCreatedOn());
}
@@ -94,7 +91,7 @@ public class InternalGroupSubject extends Subject<InternalGroupSubject, Internal
return check("getSubgroups()").that(group.getSubgroups());
}
public ComparableSubject<?, ObjectId> refState() {
public ComparableSubject refState() {
isNotNull();
return check("getRefState()").that(group.getRefState());
}

View File

@@ -24,7 +24,7 @@ import com.google.gerrit.common.UsedAt;
import com.google.gerrit.common.UsedAt.Project;
@UsedAt(Project.PLUGINS_ALL)
public class CacheStatsSubject extends Subject<CacheStatsSubject, CacheStats> {
public class CacheStatsSubject extends Subject {
public static CacheStatsSubject assertThat(CacheStats stats) {
return assertAbout(CacheStatsSubject::new).that(stats);
}

View File

@@ -30,7 +30,7 @@ import com.google.gerrit.common.Nullable;
import java.util.Arrays;
import org.eclipse.jgit.lib.Config;
public class ConfigSubject extends Subject<ConfigSubject, Config> {
public class ConfigSubject extends Subject {
public static ConfigSubject assertThat(Config config) {
return assertAbout(ConfigSubject::new).that(config);
}

View File

@@ -27,12 +27,12 @@ import com.google.common.truth.Subject;
import java.util.List;
import java.util.function.BiFunction;
public class ListSubject<S extends Subject<S, E>, E> extends IterableSubject {
public class ListSubject<S extends Subject, E> extends IterableSubject {
private final List<E> list;
private final BiFunction<StandardSubjectBuilder, E, S> elementSubjectCreator;
public static <S extends Subject<S, E>, E> ListSubject<S, E> assertThat(
public static <S extends Subject, E> ListSubject<S, E> assertThat(
List<E> list, Subject.Factory<S, E> subjectFactory) {
return assertAbout(elements()).thatCustom(list, subjectFactory);
}
@@ -77,12 +77,12 @@ public class ListSubject<S extends Subject<S, E>, E> extends IterableSubject {
super(failureMetadata);
}
public <S extends Subject<S, E>, E> ListSubject<S, E> thatCustom(
public <S extends Subject, E> ListSubject<S, E> thatCustom(
List<E> list, Subject.Factory<S, E> subjectFactory) {
return that(list, (builder, element) -> builder.about(subjectFactory).that(element));
}
public <S extends Subject<S, E>, E> ListSubject<S, E> that(
public <S extends Subject, E> ListSubject<S, E> that(
List<E> list, BiFunction<StandardSubjectBuilder, E, S> elementSubjectCreator) {
return new ListSubject<>(metadata(), list, elementSubjectCreator);
}

View File

@@ -18,7 +18,6 @@ import static com.google.common.truth.Fact.fact;
import static com.google.common.truth.Truth.assertAbout;
import com.google.common.truth.CustomSubjectBuilder;
import com.google.common.truth.DefaultSubject;
import com.google.common.truth.FailureMetadata;
import com.google.common.truth.StandardSubjectBuilder;
import com.google.common.truth.Subject;
@@ -26,32 +25,26 @@ import java.util.Optional;
import java.util.function.BiFunction;
import java.util.function.Function;
public class OptionalSubject<S extends Subject<S, ? super T>, T>
extends Subject<OptionalSubject<S, T>, Optional<T>> {
public class OptionalSubject<S extends Subject, T> extends Subject {
private final Optional<T> optional;
private final BiFunction<StandardSubjectBuilder, ? super T, ? extends S> valueSubjectCreator;
// TODO(aliceks): Remove when all relevant usages are adapted to new check()/factory approach.
public static <S extends Subject<S, T>, T> OptionalSubject<S, T> assertThat(
public static <S extends Subject, T> OptionalSubject<S, T> assertThat(
Optional<T> optional, Function<? super T, ? extends S> elementAssertThatFunction) {
Subject.Factory<S, T> valueSubjectFactory =
(metadata, value) -> elementAssertThatFunction.apply(value);
return assertThat(optional, valueSubjectFactory);
}
public static <S extends Subject<S, T>, T> OptionalSubject<S, T> assertThat(
public static <S extends Subject, T> OptionalSubject<S, T> assertThat(
Optional<T> optional, Subject.Factory<S, T> valueSubjectFactory) {
return assertAbout(optionals()).thatCustom(optional, valueSubjectFactory);
}
public static OptionalSubject<DefaultSubject, ?> assertThat(Optional<?> optional) {
// Unfortunately, we need to cast to DefaultSubject as StandardSubjectBuilder#that
// only returns Subject<DefaultSubject, Object>. There shouldn't be a way
// for that method not to return a DefaultSubject because the generic type
// definitions of a Subject are quite strict.
return assertAbout(optionals())
.that(optional, (builder, value) -> (DefaultSubject) builder.that(value));
public static OptionalSubject<Subject, ?> assertThat(Optional<?> optional) {
return assertAbout(optionals()).that(optional);
}
public static CustomSubjectBuilder.Factory<OptionalSubjectBuilder> optionals() {
@@ -97,16 +90,16 @@ public class OptionalSubject<S extends Subject<S, ? super T>, T>
super(failureMetadata);
}
public <S extends Subject<S, T>, T> OptionalSubject<S, T> thatCustom(
public <S extends Subject, T> OptionalSubject<S, T> thatCustom(
Optional<T> optional, Subject.Factory<S, T> valueSubjectFactory) {
return that(optional, (builder, value) -> builder.about(valueSubjectFactory).that(value));
}
public OptionalSubject<DefaultSubject, ?> that(Optional<?> optional) {
return that(optional, (builder, value) -> (DefaultSubject) builder.that(value));
public OptionalSubject<Subject, ?> that(Optional<?> optional) {
return that(optional, StandardSubjectBuilder::that);
}
public <S extends Subject<S, ? super T>, T> OptionalSubject<S, T> that(
public <S extends Subject, T> OptionalSubject<S, T> that(
Optional<T> optional,
BiFunction<StandardSubjectBuilder, ? super T, ? extends S> valueSubjectCreator) {
return new OptionalSubject<>(metadata(), optional, valueSubjectCreator);

View File

@@ -25,8 +25,7 @@ import java.io.IOException;
import java.io.InputStreamReader;
import java.nio.charset.StandardCharsets;
public class ChangeFileContentModificationSubject
extends Subject<ChangeFileContentModificationSubject, ChangeFileContentModification> {
public class ChangeFileContentModificationSubject extends Subject {
public static ChangeFileContentModificationSubject assertThat(
ChangeFileContentModification modification) {

View File

@@ -21,7 +21,7 @@ import com.google.common.truth.Subject;
import com.google.gerrit.truth.ListSubject;
import java.util.List;
public class TreeModificationSubject extends Subject<TreeModificationSubject, TreeModification> {
public class TreeModificationSubject extends Subject {
public static TreeModificationSubject assertThat(TreeModification treeModification) {
return assertAbout(treeModifications()).that(treeModification);