diff --git a/core/src/main/java/com/google/common/truth/AbstractArraySubject.java b/core/src/main/java/com/google/common/truth/AbstractArraySubject.java index fb09a4c09..340abc1b2 100644 --- a/core/src/main/java/com/google/common/truth/AbstractArraySubject.java +++ b/core/src/main/java/com/google/common/truth/AbstractArraySubject.java @@ -26,11 +26,11 @@ * * @author Christian Gruber (cgruber@israfil.net) */ -abstract class AbstractArraySubject, T> extends Subject { - private final T actual; +abstract class AbstractArraySubject extends Subject { + private final Object actual; AbstractArraySubject( - FailureMetadata metadata, @NullableDecl T actual, @NullableDecl String typeDescription) { + FailureMetadata metadata, @NullableDecl Object actual, @NullableDecl String typeDescription) { super(metadata, actual, typeDescription); this.actual = actual; } diff --git a/core/src/main/java/com/google/common/truth/AtomicLongMapSubject.java b/core/src/main/java/com/google/common/truth/AtomicLongMapSubject.java index eced9952d..f4c6446fa 100644 --- a/core/src/main/java/com/google/common/truth/AtomicLongMapSubject.java +++ b/core/src/main/java/com/google/common/truth/AtomicLongMapSubject.java @@ -28,7 +28,7 @@ * * @author Kurt Alfred Kluever */ -public final class AtomicLongMapSubject extends Subject> { +public final class AtomicLongMapSubject extends Subject { private final AtomicLongMap actual; AtomicLongMapSubject(FailureMetadata metadata, @NullableDecl AtomicLongMap map) { diff --git a/core/src/main/java/com/google/common/truth/BooleanSubject.java b/core/src/main/java/com/google/common/truth/BooleanSubject.java index bb95462ad..2ac258daf 100644 --- a/core/src/main/java/com/google/common/truth/BooleanSubject.java +++ b/core/src/main/java/com/google/common/truth/BooleanSubject.java @@ -24,7 +24,7 @@ * * @author Christian Gruber (cgruber@israfil.net) */ -public final class BooleanSubject extends Subject { +public final class BooleanSubject extends Subject { private final Boolean actual; BooleanSubject(FailureMetadata metadata, @NullableDecl Boolean actual) { diff --git a/core/src/main/java/com/google/common/truth/ClassSubject.java b/core/src/main/java/com/google/common/truth/ClassSubject.java index 30b96e5ad..b72ac7cf6 100644 --- a/core/src/main/java/com/google/common/truth/ClassSubject.java +++ b/core/src/main/java/com/google/common/truth/ClassSubject.java @@ -24,7 +24,7 @@ * @author Kurt Alfred Kluever */ @GwtIncompatible("reflection") -public final class ClassSubject extends Subject> { +public final class ClassSubject extends Subject { private final Class actual; ClassSubject(FailureMetadata metadata, @NullableDecl Class o) { diff --git a/core/src/main/java/com/google/common/truth/FailureMetadata.java b/core/src/main/java/com/google/common/truth/FailureMetadata.java index fe728536e..3ee77060d 100644 --- a/core/src/main/java/com/google/common/truth/FailureMetadata.java +++ b/core/src/main/java/com/google/common/truth/FailureMetadata.java @@ -61,7 +61,7 @@ static FailureMetadata forFailureStrategy(FailureStrategy failureStrategy) { * The data from a call to either (a) a {@link Subject} constructor or (b) {@link Subject#check}. */ private static final class Step { - static Step subjectCreation(Subject subject) { + static Step subjectCreation(Subject subject) { return new Step(checkNotNull(subject), null, null); } @@ -78,7 +78,7 @@ static Step checkCall( * time we receive it. We *might* be able to make it safe to call if it looks only at actual(), * but it might try to look at facts initialized by a subclass, which aren't ready yet. */ - @NullableDecl final Subject subject; + @NullableDecl final Subject subject; @NullableDecl final Function descriptionUpdate; @@ -86,7 +86,7 @@ static Step checkCall( @NullableDecl final OldAndNewValuesAreSimilar valuesAreSimilar; private Step( - @NullableDecl Subject subject, + @NullableDecl Subject subject, @NullableDecl Function descriptionUpdate, @NullableDecl OldAndNewValuesAreSimilar valuesAreSimilar) { this.subject = subject; @@ -124,7 +124,7 @@ boolean isCheckCall() { * the initial that(...) call and continuing into any chained calls, like {@link * ThrowableSubject#hasMessageThat}. */ - FailureMetadata updateForSubject(Subject subject) { + FailureMetadata updateForSubject(Subject subject) { ImmutableList steps = append(this.steps, Step.subjectCreation(subject)); return derive(messages, steps); } diff --git a/core/src/main/java/com/google/common/truth/GuavaOptionalSubject.java b/core/src/main/java/com/google/common/truth/GuavaOptionalSubject.java index 375e63404..03ffd2c00 100644 --- a/core/src/main/java/com/google/common/truth/GuavaOptionalSubject.java +++ b/core/src/main/java/com/google/common/truth/GuavaOptionalSubject.java @@ -29,7 +29,7 @@ * * @author Christian Gruber */ -public final class GuavaOptionalSubject extends Subject> { +public final class GuavaOptionalSubject extends Subject { private final Optional actual; GuavaOptionalSubject( diff --git a/core/src/main/java/com/google/common/truth/IterableSubject.java b/core/src/main/java/com/google/common/truth/IterableSubject.java index 48706b4f4..c6682f88d 100644 --- a/core/src/main/java/com/google/common/truth/IterableSubject.java +++ b/core/src/main/java/com/google/common/truth/IterableSubject.java @@ -88,7 +88,7 @@ * @author Pete Gillin */ // Can't be final since MultisetSubject and SortedSetSubject extend it -public class IterableSubject extends Subject> { +public class IterableSubject extends Subject { private final Iterable actual; @@ -944,7 +944,8 @@ public void isNoneOf( /** @deprecated You probably meant to call {@link #containsNoneIn} instead. */ @Override @Deprecated - public void isNotIn(Iterable iterable) { + // TODO(b/133145187): Restore to Iterable after removing the type parameters from Subject. + public void isNotIn(Iterable iterable) { if (Iterables.contains(iterable, actual)) { failWithActual("expected not to be any of", iterable); } diff --git a/core/src/main/java/com/google/common/truth/MapSubject.java b/core/src/main/java/com/google/common/truth/MapSubject.java index ae991c46f..86fb57dd2 100644 --- a/core/src/main/java/com/google/common/truth/MapSubject.java +++ b/core/src/main/java/com/google/common/truth/MapSubject.java @@ -50,7 +50,7 @@ * @author Christian Gruber * @author Kurt Alfred Kluever */ -public class MapSubject extends Subject> { +public class MapSubject extends Subject { private final Map actual; /** diff --git a/core/src/main/java/com/google/common/truth/MultimapSubject.java b/core/src/main/java/com/google/common/truth/MultimapSubject.java index 88398d13e..587060585 100644 --- a/core/src/main/java/com/google/common/truth/MultimapSubject.java +++ b/core/src/main/java/com/google/common/truth/MultimapSubject.java @@ -56,7 +56,7 @@ * @author Daniel Ploch * @author Kurt Alfred Kluever */ -public class MultimapSubject extends Subject> { +public class MultimapSubject extends Subject { /** Ordered implementation that does nothing because an earlier check already caused a failure. */ private static final Ordered ALREADY_FAILED = diff --git a/core/src/main/java/com/google/common/truth/ObjectArraySubject.java b/core/src/main/java/com/google/common/truth/ObjectArraySubject.java index 1647df901..d8a6bc691 100644 --- a/core/src/main/java/com/google/common/truth/ObjectArraySubject.java +++ b/core/src/main/java/com/google/common/truth/ObjectArraySubject.java @@ -23,7 +23,7 @@ * * @author Christian Gruber */ -public final class ObjectArraySubject extends AbstractArraySubject, T[]> { +public final class ObjectArraySubject extends AbstractArraySubject { private final T[] actual; ObjectArraySubject( diff --git a/core/src/main/java/com/google/common/truth/PrimitiveBooleanArraySubject.java b/core/src/main/java/com/google/common/truth/PrimitiveBooleanArraySubject.java index db64b064e..c8121c3e6 100644 --- a/core/src/main/java/com/google/common/truth/PrimitiveBooleanArraySubject.java +++ b/core/src/main/java/com/google/common/truth/PrimitiveBooleanArraySubject.java @@ -23,8 +23,7 @@ * * @author Christian Gruber (cgruber@israfil.net) */ -public final class PrimitiveBooleanArraySubject - extends AbstractArraySubject { +public final class PrimitiveBooleanArraySubject extends AbstractArraySubject { private final boolean[] actual; PrimitiveBooleanArraySubject( diff --git a/core/src/main/java/com/google/common/truth/PrimitiveByteArraySubject.java b/core/src/main/java/com/google/common/truth/PrimitiveByteArraySubject.java index 2627c541d..1f4176608 100644 --- a/core/src/main/java/com/google/common/truth/PrimitiveByteArraySubject.java +++ b/core/src/main/java/com/google/common/truth/PrimitiveByteArraySubject.java @@ -23,8 +23,7 @@ * * @author Kurt Alfred Kluever */ -public final class PrimitiveByteArraySubject - extends AbstractArraySubject { +public final class PrimitiveByteArraySubject extends AbstractArraySubject { private final byte[] actual; PrimitiveByteArraySubject( diff --git a/core/src/main/java/com/google/common/truth/PrimitiveCharArraySubject.java b/core/src/main/java/com/google/common/truth/PrimitiveCharArraySubject.java index b54007c93..48c9925a0 100644 --- a/core/src/main/java/com/google/common/truth/PrimitiveCharArraySubject.java +++ b/core/src/main/java/com/google/common/truth/PrimitiveCharArraySubject.java @@ -23,8 +23,7 @@ * * @author Christian Gruber (cgruber@israfil.net) */ -public final class PrimitiveCharArraySubject - extends AbstractArraySubject { +public final class PrimitiveCharArraySubject extends AbstractArraySubject { private final char[] actual; PrimitiveCharArraySubject( diff --git a/core/src/main/java/com/google/common/truth/PrimitiveDoubleArraySubject.java b/core/src/main/java/com/google/common/truth/PrimitiveDoubleArraySubject.java index 190ca626c..5ff321457 100644 --- a/core/src/main/java/com/google/common/truth/PrimitiveDoubleArraySubject.java +++ b/core/src/main/java/com/google/common/truth/PrimitiveDoubleArraySubject.java @@ -30,8 +30,7 @@ * * @author Christian Gruber (cgruber@israfil.net) */ -public final class PrimitiveDoubleArraySubject - extends AbstractArraySubject { +public final class PrimitiveDoubleArraySubject extends AbstractArraySubject { private final double[] actual; PrimitiveDoubleArraySubject( diff --git a/core/src/main/java/com/google/common/truth/PrimitiveFloatArraySubject.java b/core/src/main/java/com/google/common/truth/PrimitiveFloatArraySubject.java index 005793b1e..0be0b95bf 100644 --- a/core/src/main/java/com/google/common/truth/PrimitiveFloatArraySubject.java +++ b/core/src/main/java/com/google/common/truth/PrimitiveFloatArraySubject.java @@ -30,8 +30,7 @@ * * @author Christian Gruber (cgruber@israfil.net) */ -public final class PrimitiveFloatArraySubject - extends AbstractArraySubject { +public final class PrimitiveFloatArraySubject extends AbstractArraySubject { private final float[] actual; PrimitiveFloatArraySubject( diff --git a/core/src/main/java/com/google/common/truth/PrimitiveIntArraySubject.java b/core/src/main/java/com/google/common/truth/PrimitiveIntArraySubject.java index 8886aad78..5c886398d 100644 --- a/core/src/main/java/com/google/common/truth/PrimitiveIntArraySubject.java +++ b/core/src/main/java/com/google/common/truth/PrimitiveIntArraySubject.java @@ -23,8 +23,7 @@ * * @author Christian Gruber (cgruber@israfil.net) */ -public final class PrimitiveIntArraySubject - extends AbstractArraySubject { +public final class PrimitiveIntArraySubject extends AbstractArraySubject { private final int[] actual; PrimitiveIntArraySubject( diff --git a/core/src/main/java/com/google/common/truth/PrimitiveLongArraySubject.java b/core/src/main/java/com/google/common/truth/PrimitiveLongArraySubject.java index 4512920b0..cb2599129 100644 --- a/core/src/main/java/com/google/common/truth/PrimitiveLongArraySubject.java +++ b/core/src/main/java/com/google/common/truth/PrimitiveLongArraySubject.java @@ -23,8 +23,7 @@ * * @author Christian Gruber (cgruber@israfil.net) */ -public final class PrimitiveLongArraySubject - extends AbstractArraySubject { +public final class PrimitiveLongArraySubject extends AbstractArraySubject { private final long[] actual; PrimitiveLongArraySubject( diff --git a/core/src/main/java/com/google/common/truth/PrimitiveShortArraySubject.java b/core/src/main/java/com/google/common/truth/PrimitiveShortArraySubject.java index b96449dd3..2db7ea069 100644 --- a/core/src/main/java/com/google/common/truth/PrimitiveShortArraySubject.java +++ b/core/src/main/java/com/google/common/truth/PrimitiveShortArraySubject.java @@ -23,8 +23,7 @@ * * @author Christian Gruber (cgruber@israfil.net) */ -public final class PrimitiveShortArraySubject - extends AbstractArraySubject { +public final class PrimitiveShortArraySubject extends AbstractArraySubject { private final short[] actual; PrimitiveShortArraySubject( diff --git a/core/src/main/java/com/google/common/truth/SubjectUtils.java b/core/src/main/java/com/google/common/truth/SubjectUtils.java index c42a9b6ea..8584ddffb 100644 --- a/core/src/main/java/com/google/common/truth/SubjectUtils.java +++ b/core/src/main/java/com/google/common/truth/SubjectUtils.java @@ -39,7 +39,7 @@ import java.util.Map; /** - * Utility methods used in {@code Subject} implementors. + * Utility methods used in {@code Subject} implementors. * * @author Christian Gruber * @author Jens Nyman diff --git a/core/src/main/java/com/google/common/truth/TableSubject.java b/core/src/main/java/com/google/common/truth/TableSubject.java index ab699e9a4..d59e10b8d 100644 --- a/core/src/main/java/com/google/common/truth/TableSubject.java +++ b/core/src/main/java/com/google/common/truth/TableSubject.java @@ -29,7 +29,7 @@ * * @author Kurt Alfred Kluever */ -public final class TableSubject extends Subject> { +public final class TableSubject extends Subject { private final Table actual; TableSubject(FailureMetadata metadata, @NullableDecl Table table) { diff --git a/core/src/main/java/com/google/common/truth/ThrowableSubject.java b/core/src/main/java/com/google/common/truth/ThrowableSubject.java index 1a6a6a298..f0d134847 100644 --- a/core/src/main/java/com/google/common/truth/ThrowableSubject.java +++ b/core/src/main/java/com/google/common/truth/ThrowableSubject.java @@ -22,7 +22,7 @@ * * @author Kurt Alfred Kluever */ -public class ThrowableSubject extends Subject { +public class ThrowableSubject extends Subject { private final Throwable actual; /** diff --git a/core/src/test/java/com/google/common/truth/ChainingTest.java b/core/src/test/java/com/google/common/truth/ChainingTest.java index e098ac526..41813bdf4 100644 --- a/core/src/test/java/com/google/common/truth/ChainingTest.java +++ b/core/src/test/java/com/google/common/truth/ChainingTest.java @@ -223,7 +223,7 @@ public void badFormat() { * tests like MultimapSubjectTest. */ - private static final class MyObjectSubject extends Subject { + private static final class MyObjectSubject extends Subject { static final Factory FACTORY = new Factory() { @Override diff --git a/core/src/test/java/com/google/common/truth/ExpectFailureTest.java b/core/src/test/java/com/google/common/truth/ExpectFailureTest.java index a17edee7f..ff7f1f9d1 100644 --- a/core/src/test/java/com/google/common/truth/ExpectFailureTest.java +++ b/core/src/test/java/com/google/common/truth/ExpectFailureTest.java @@ -140,7 +140,7 @@ public StringSubject createSubject(FailureMetadata fm, String that) { }; } - private static class BadSubject extends Subject { + private static class BadSubject extends Subject { private final Integer actual; BadSubject(FailureMetadata failureMetadat, Integer actual) { diff --git a/core/src/test/java/com/google/common/truth/SubjectTest.java b/core/src/test/java/com/google/common/truth/SubjectTest.java index 0a3d1d16c..ac8169610 100644 --- a/core/src/test/java/com/google/common/truth/SubjectTest.java +++ b/core/src/test/java/com/google/common/truth/SubjectTest.java @@ -97,7 +97,7 @@ public void allAssertThatOverloadsAcceptNull() throws Exception { && method.getName().equals("assertThat") && method.getParameterTypes().length == 1) { Object actual = null; - Subject subject = (Subject) method.invoke(Truth.class, actual); + Subject subject = (Subject) method.invoke(Truth.class, actual); subject.isNull(); try { @@ -783,8 +783,7 @@ public boolean equals(Object obj) { } } - private static final class ForbidsEqualityChecksSubject - extends Subject { + private static final class ForbidsEqualityChecksSubject extends Subject { ForbidsEqualityChecksSubject(FailureMetadata metadata, @NullableDecl Object actual) { super(metadata, actual); } diff --git a/core/src/test/java/com/google/common/truth/extension/EmployeeSubject.java b/core/src/test/java/com/google/common/truth/extension/EmployeeSubject.java index dad2eddab..6a90befeb 100644 --- a/core/src/test/java/com/google/common/truth/extension/EmployeeSubject.java +++ b/core/src/test/java/com/google/common/truth/extension/EmployeeSubject.java @@ -27,7 +27,7 @@ * * @author Kurt Alfred Kluever (kak@google.com) */ -public final class EmployeeSubject extends Subject { +public final class EmployeeSubject extends Subject { // User-defined entry point public static EmployeeSubject assertThat(@NullableDecl Employee employee) { diff --git a/extensions/java8/src/main/java/com/google/common/truth/IntStreamSubject.java b/extensions/java8/src/main/java/com/google/common/truth/IntStreamSubject.java index 2b535cead..98a45ec0f 100644 --- a/extensions/java8/src/main/java/com/google/common/truth/IntStreamSubject.java +++ b/extensions/java8/src/main/java/com/google/common/truth/IntStreamSubject.java @@ -40,7 +40,7 @@ * * @author Kurt Alfred Kluever */ -public final class IntStreamSubject extends Subject { +public final class IntStreamSubject extends Subject { private final List actualList; diff --git a/extensions/java8/src/main/java/com/google/common/truth/LongStreamSubject.java b/extensions/java8/src/main/java/com/google/common/truth/LongStreamSubject.java index b3b7ad3d7..a4c6af32c 100644 --- a/extensions/java8/src/main/java/com/google/common/truth/LongStreamSubject.java +++ b/extensions/java8/src/main/java/com/google/common/truth/LongStreamSubject.java @@ -40,7 +40,7 @@ * * @author Kurt Alfred Kluever */ -public final class LongStreamSubject extends Subject { +public final class LongStreamSubject extends Subject { private final List actualList; diff --git a/extensions/java8/src/main/java/com/google/common/truth/OptionalDoubleSubject.java b/extensions/java8/src/main/java/com/google/common/truth/OptionalDoubleSubject.java index 8216971cc..36b625f15 100644 --- a/extensions/java8/src/main/java/com/google/common/truth/OptionalDoubleSubject.java +++ b/extensions/java8/src/main/java/com/google/common/truth/OptionalDoubleSubject.java @@ -26,7 +26,7 @@ * * @author Ben Douglass */ -public final class OptionalDoubleSubject extends Subject { +public final class OptionalDoubleSubject extends Subject { private final OptionalDouble actual; diff --git a/extensions/java8/src/main/java/com/google/common/truth/OptionalIntSubject.java b/extensions/java8/src/main/java/com/google/common/truth/OptionalIntSubject.java index bb9d1119a..1edfaaad6 100644 --- a/extensions/java8/src/main/java/com/google/common/truth/OptionalIntSubject.java +++ b/extensions/java8/src/main/java/com/google/common/truth/OptionalIntSubject.java @@ -26,7 +26,7 @@ * * @author Ben Douglass */ -public final class OptionalIntSubject extends Subject { +public final class OptionalIntSubject extends Subject { private final OptionalInt actual; OptionalIntSubject( diff --git a/extensions/java8/src/main/java/com/google/common/truth/OptionalLongSubject.java b/extensions/java8/src/main/java/com/google/common/truth/OptionalLongSubject.java index 5cbd12831..532448d3f 100644 --- a/extensions/java8/src/main/java/com/google/common/truth/OptionalLongSubject.java +++ b/extensions/java8/src/main/java/com/google/common/truth/OptionalLongSubject.java @@ -26,7 +26,7 @@ * * @author Ben Douglass */ -public final class OptionalLongSubject extends Subject { +public final class OptionalLongSubject extends Subject { private final OptionalLong actual; OptionalLongSubject( diff --git a/extensions/java8/src/main/java/com/google/common/truth/OptionalSubject.java b/extensions/java8/src/main/java/com/google/common/truth/OptionalSubject.java index 02b78dee0..6827a10b3 100644 --- a/extensions/java8/src/main/java/com/google/common/truth/OptionalSubject.java +++ b/extensions/java8/src/main/java/com/google/common/truth/OptionalSubject.java @@ -26,7 +26,7 @@ * * @author Christian Gruber */ -public final class OptionalSubject extends Subject> { +public final class OptionalSubject extends Subject { private final Optional actual; OptionalSubject( diff --git a/extensions/java8/src/main/java/com/google/common/truth/PathSubject.java b/extensions/java8/src/main/java/com/google/common/truth/PathSubject.java index a1953d7f2..ead8fd80d 100644 --- a/extensions/java8/src/main/java/com/google/common/truth/PathSubject.java +++ b/extensions/java8/src/main/java/com/google/common/truth/PathSubject.java @@ -20,7 +20,7 @@ /** Assertions for {@link Path} instances. */ @GwtIncompatible -public final class PathSubject extends Subject { +public final class PathSubject extends Subject { private PathSubject(FailureMetadata failureMetadata, Path actual) { super(failureMetadata, actual); } diff --git a/extensions/java8/src/main/java/com/google/common/truth/StreamSubject.java b/extensions/java8/src/main/java/com/google/common/truth/StreamSubject.java index 02f696f53..3bcc2cb31 100644 --- a/extensions/java8/src/main/java/com/google/common/truth/StreamSubject.java +++ b/extensions/java8/src/main/java/com/google/common/truth/StreamSubject.java @@ -31,15 +31,15 @@ * provide more readable failure messages. You should not use this class if you intend to leave the * stream un-consumed or if the stream is very large or infinite. * - *

If you intend to make multiple assertions on the same stream of data you should instead - * first collect the contents of the stream into a collection, and then assert directly on that. + *

If you intend to make multiple assertions on the same stream of data you should instead first + * collect the contents of the stream into a collection, and then assert directly on that. * *

For very large or infinite streams you may want to first {@linkplain Stream#limit limit} the * stream before asserting on it. * * @author Kurt Alfred Kluever */ -public final class StreamSubject extends Subject> { +public final class StreamSubject extends Subject { private final List actualList; diff --git a/extensions/liteproto/src/main/java/com/google/common/truth/extensions/proto/LiteProtoSubject.java b/extensions/liteproto/src/main/java/com/google/common/truth/extensions/proto/LiteProtoSubject.java index fc5fc8a43..63751d02d 100644 --- a/extensions/liteproto/src/main/java/com/google/common/truth/extensions/proto/LiteProtoSubject.java +++ b/extensions/liteproto/src/main/java/com/google/common/truth/extensions/proto/LiteProtoSubject.java @@ -24,7 +24,6 @@ import com.google.common.truth.FailureMetadata; import com.google.common.truth.IntegerSubject; import com.google.common.truth.Subject; -import com.google.common.truth.Truth; import com.google.errorprone.annotations.CheckReturnValue; import com.google.protobuf.MessageLite; import java.util.regex.Pattern; @@ -36,36 +35,16 @@ *

LiteProtoSubject supports versions 2 and 3 of Protocol Buffers. Due to the lack of runtime * descriptors, its functionality is limited compared to ProtoSubject, in particular in performing * detailed comparisons between messages. - * - * @param deprecated - the self-type, allowing {@code this}-returning methods to avoid - * needing subclassing. Both type parameters will be removed, as the methods that need them - * are being removed. You can prepare for this change by editing your class to refer to raw - * {@code LiteProtoSubject} today. - * @param deprecated - the type of the message being tested by this {@code Subject}. - * Both type parameters will be removed, as the methods that need them are being removed. You - * can prepare for this change by editing your class to refer to raw {@code LiteProtoSubject} - * today. */ @CheckReturnValue -public class LiteProtoSubject, M extends MessageLite> - extends Subject { - - /** - * Typed extension of {@link Subject.Factory}. - * - *

The existence of this class is necessary in order to satisfy the generic constraints of - * {@link Truth#assertAbout(Subject.Factory)}, whilst also hiding the Untyped classes which are - * not meant to be exposed. - */ - public abstract static class Factory, M extends MessageLite> - implements Subject.Factory {} +public class LiteProtoSubject extends Subject { /** - * Returns a SubjectFactory for {@link MessageLite} subjects which you can use to assert things - * about Lite Protobuf properties. + * Returns a {@code Subject.Factory} for {@link MessageLite} subjects which you can use to assert + * things about Lite Protobuf properties. */ - static Factory liteProtos() { - return MessageLiteSubjectFactory.INSTANCE; + static Factory liteProtos() { + return LiteProtoSubjectFactory.INSTANCE; } /* @@ -83,9 +62,10 @@ static Factory liteProtos() { * TODO(b/127819891): Use a better API for this if one is addded. */ private final FailureMetadata metadata; - private final M actual; + private final MessageLite actual; - protected LiteProtoSubject(FailureMetadata failureMetadata, @NullableDecl M messageLite) { + protected LiteProtoSubject( + FailureMetadata failureMetadata, @NullableDecl MessageLite messageLite) { super(failureMetadata, messageLite); this.metadata = failureMetadata; this.actual = messageLite; @@ -250,21 +230,14 @@ public IntegerSubject serializedSize() { return check("getSerializedSize()").that(actual.getSerializedSize()); } - static final class MessageLiteSubject extends LiteProtoSubject { - - MessageLiteSubject(FailureMetadata failureMetadata, @NullableDecl MessageLite messageLite) { - super(failureMetadata, messageLite); - } - } - - private static final class MessageLiteSubjectFactory - extends Factory { - private static final MessageLiteSubjectFactory INSTANCE = new MessageLiteSubjectFactory(); + private static final class LiteProtoSubjectFactory + implements Factory { + private static final LiteProtoSubjectFactory INSTANCE = new LiteProtoSubjectFactory(); @Override - public MessageLiteSubject createSubject( + public LiteProtoSubject createSubject( FailureMetadata failureMetadata, @NullableDecl MessageLite messageLite) { - return new MessageLiteSubject(failureMetadata, messageLite); + return new LiteProtoSubject(failureMetadata, messageLite); } } } diff --git a/extensions/liteproto/src/main/java/com/google/common/truth/extensions/proto/LiteProtoTruth.java b/extensions/liteproto/src/main/java/com/google/common/truth/extensions/proto/LiteProtoTruth.java index 15ff60c0f..c0b327eb4 100644 --- a/extensions/liteproto/src/main/java/com/google/common/truth/extensions/proto/LiteProtoTruth.java +++ b/extensions/liteproto/src/main/java/com/google/common/truth/extensions/proto/LiteProtoTruth.java @@ -18,8 +18,9 @@ import static com.google.common.truth.Truth.assertAbout; -import com.google.protobuf.MessageLite; +import com.google.common.truth.Subject; import com.google.errorprone.annotations.CheckReturnValue; +import com.google.protobuf.MessageLite; import org.checkerframework.checker.nullness.compatqual.NullableDecl; /** @@ -36,11 +37,11 @@ */ @CheckReturnValue public final class LiteProtoTruth { - public static LiteProtoSubject assertThat(@NullableDecl MessageLite messageLite) { + public static LiteProtoSubject assertThat(@NullableDecl MessageLite messageLite) { return assertAbout(liteProtos()).that(messageLite); } - public static LiteProtoSubject.Factory liteProtos() { + public static Subject.Factory liteProtos() { return LiteProtoSubject.liteProtos(); } diff --git a/extensions/liteproto/src/test/java/com/google/common/truth/extensions/proto/LiteProtoSubjectTest.java b/extensions/liteproto/src/test/java/com/google/common/truth/extensions/proto/LiteProtoSubjectTest.java index 315d7462f..2512a16c1 100644 --- a/extensions/liteproto/src/test/java/com/google/common/truth/extensions/proto/LiteProtoSubjectTest.java +++ b/extensions/liteproto/src/test/java/com/google/common/truth/extensions/proto/LiteProtoSubjectTest.java @@ -131,11 +131,11 @@ public LiteProtoSubjectTest(@SuppressWarnings("unused") String name, Config conf this.config = config; } - private LiteProtoSubject expectThat(@NullableDecl MessageLite m) { + private LiteProtoSubject expectThat(@NullableDecl MessageLite m) { return expect.about(LiteProtoTruth.liteProtos()).that(m); } - private Subject expectThat(@NullableDecl Object o) { + private Subject expectThat(@NullableDecl Object o) { return expect.that(o); } @@ -276,16 +276,16 @@ public void testSerializedSize_failure() { assertThat(config.nonEmptyMessage()).serializedSize().isGreaterThan(size); fail("Should have failed."); } catch (AssertionError e) { - assertThat(e).factValue("value of").isEqualTo("messageLite.getSerializedSize()"); - assertThat(e).factValue("messageLite was").containsMatch("optional_int:\\s*3"); + assertThat(e).factValue("value of").isEqualTo("liteProto.getSerializedSize()"); + assertThat(e).factValue("liteProto was").containsMatch("optional_int:\\s*3"); } try { assertThat(config.defaultInstance()).serializedSize().isGreaterThan(0); fail("Should have failed."); } catch (AssertionError e) { - assertThat(e).factValue("value of").isEqualTo("messageLite.getSerializedSize()"); - assertThat(e).factValue("messageLite was").contains("[empty proto]"); + assertThat(e).factValue("value of").isEqualTo("liteProto.getSerializedSize()"); + assertThat(e).factValue("liteProto was").contains("[empty proto]"); } } diff --git a/extensions/proto/src/main/java/com/google/common/truth/extensions/proto/ProtoSubject.java b/extensions/proto/src/main/java/com/google/common/truth/extensions/proto/ProtoSubject.java index fcf885e72..7257237e4 100644 --- a/extensions/proto/src/main/java/com/google/common/truth/extensions/proto/ProtoSubject.java +++ b/extensions/proto/src/main/java/com/google/common/truth/extensions/proto/ProtoSubject.java @@ -46,43 +46,31 @@ *

Equality tests, and other methods, may yield slightly different behavior for versions 2 and 3 * of Protocol Buffers. If testing protos of multiple versions, make sure you understand the * behaviors of default and unknown fields so you don't under or over test. - * - * @param deprecated - the self-type, allowing {@code this}-returning methods to avoid - * needing subclassing. Both type parameters will be removed, as the methods that need them - * are being removed. You can prepare for this change by editing your class to refer to raw - * {@code ProtoSubject} today. - * @param deprecated - the type of the message being tested by this {@code Subject}. - * Both type parameters will be removed, as the methods that need them are being removed. You - * can prepare for this change by editing your class to refer to raw {@code ProtoSubject} - * today. */ -public class ProtoSubject, M extends Message> - extends LiteProtoSubject implements ProtoFluentAssertion { +public class ProtoSubject extends LiteProtoSubject implements ProtoFluentAssertion { /* * Storing a FailureMetadata instance in a Subject subclass is generally a bad practice. For an * explanation of why it works out OK here, see LiteProtoSubject. */ private final FailureMetadata metadata; - private final M actual; - // TODO(user): Type this if we solve the typing assertAbout() problem for - // IterableOfProtosSubject and there is use for such typing. + private final Message actual; private final FluentEqualityConfig config; - protected ProtoSubject(FailureMetadata failureMetadata, @NullableDecl M message) { + protected ProtoSubject(FailureMetadata failureMetadata, @NullableDecl Message message) { this(failureMetadata, FluentEqualityConfig.defaultInstance(), message); } ProtoSubject( - FailureMetadata failureMetadata, FluentEqualityConfig config, @NullableDecl M message) { + FailureMetadata failureMetadata, FluentEqualityConfig config, @NullableDecl Message message) { super(failureMetadata, message); this.metadata = failureMetadata; this.actual = message; this.config = config; } - ProtoSubject usingConfig(FluentEqualityConfig newConfig) { - return new MessageSubject(metadata, newConfig, actual); + ProtoSubject usingConfig(FluentEqualityConfig newConfig) { + return new ProtoSubject(metadata, newConfig, actual); } @Override @@ -368,17 +356,4 @@ private ProtoTruthMessageDifferencer makeDifferencer(Message expected) { .withExpectedMessages(Arrays.asList(expected)) .toMessageDifferencer(actual.getDescriptorForType()); } - - static final class MessageSubject extends ProtoSubject { - MessageSubject(FailureMetadata failureMetadata, @NullableDecl Message message) { - super(failureMetadata, message); - } - - private MessageSubject( - FailureMetadata failureMetadata, - FluentEqualityConfig config, - @NullableDecl Message message) { - super(failureMetadata, config, message); - } - } } diff --git a/extensions/proto/src/main/java/com/google/common/truth/extensions/proto/ProtoSubjectBuilder.java b/extensions/proto/src/main/java/com/google/common/truth/extensions/proto/ProtoSubjectBuilder.java index 99618a3a5..54ce1c2b2 100644 --- a/extensions/proto/src/main/java/com/google/common/truth/extensions/proto/ProtoSubjectBuilder.java +++ b/extensions/proto/src/main/java/com/google/common/truth/extensions/proto/ProtoSubjectBuilder.java @@ -50,12 +50,12 @@ private ProtoSubjectBuilder(FailureMetadata failureMetadata) { super(failureMetadata); } - public LiteProtoSubject that(@NullableDecl MessageLite messageLite) { - return new LiteProtoSubject.MessageLiteSubject(metadata(), messageLite); + public LiteProtoSubject that(@NullableDecl MessageLite messageLite) { + return new LiteProtoSubject(metadata(), messageLite); } - public ProtoSubject that(@NullableDecl Message message) { - return new ProtoSubject.MessageSubject(metadata(), message); + public ProtoSubject that(@NullableDecl Message message) { + return new ProtoSubject(metadata(), message); } public IterableOfProtosSubject> that( diff --git a/extensions/proto/src/main/java/com/google/common/truth/extensions/proto/ProtoTruth.java b/extensions/proto/src/main/java/com/google/common/truth/extensions/proto/ProtoTruth.java index 5402b1bda..5cc73dd92 100644 --- a/extensions/proto/src/main/java/com/google/common/truth/extensions/proto/ProtoTruth.java +++ b/extensions/proto/src/main/java/com/google/common/truth/extensions/proto/ProtoTruth.java @@ -48,12 +48,12 @@ public static CustomSubjectBuilder.Factory protos() { } /** Assert on a single {@link MessageLite} instance. */ - public static LiteProtoSubject assertThat(@NullableDecl MessageLite messageLite) { + public static LiteProtoSubject assertThat(@NullableDecl MessageLite messageLite) { return assertAbout(protos()).that(messageLite); } /** Assert on a single {@link Message} instance. */ - public static ProtoSubject assertThat(@NullableDecl Message message) { + public static ProtoSubject assertThat(@NullableDecl Message message) { return assertAbout(protos()).that(message); } diff --git a/extensions/proto/src/test/java/com/google/common/truth/extensions/proto/ProtoSubjectTestBase.java b/extensions/proto/src/test/java/com/google/common/truth/extensions/proto/ProtoSubjectTestBase.java index 9fce0d7a6..d97b2aec8 100644 --- a/extensions/proto/src/test/java/com/google/common/truth/extensions/proto/ProtoSubjectTestBase.java +++ b/extensions/proto/src/test/java/com/google/common/truth/extensions/proto/ProtoSubjectTestBase.java @@ -156,7 +156,7 @@ protected final TruthFailureSubject expectThatFailure() { return expect.about(truthFailures()).that(multiExpectFailure.getFailure()); } - protected final ProtoSubject expectThat(@NullableDecl Message message) { + protected final ProtoSubject expectThat(@NullableDecl Message message) { return expect.about(ProtoTruth.protos()).that(message); } @@ -175,8 +175,7 @@ protected final ProtoSubject expectThat(@NullableDecl Message messag return expect.about(ProtoTruth.protos()).that(multimap); } - protected final ProtoSubject expectThatWithMessage( - String msg, @NullableDecl Message message) { + protected final ProtoSubject expectThatWithMessage(String msg, @NullableDecl Message message) { return expect.withMessage(msg).about(ProtoTruth.protos()).that(message); } diff --git a/extensions/re2j/src/main/java/com/google/common/truth/extensions/re2j/Re2jSubjects.java b/extensions/re2j/src/main/java/com/google/common/truth/extensions/re2j/Re2jSubjects.java index cc19d42e8..67b1ed81c 100644 --- a/extensions/re2j/src/main/java/com/google/common/truth/extensions/re2j/Re2jSubjects.java +++ b/extensions/re2j/src/main/java/com/google/common/truth/extensions/re2j/Re2jSubjects.java @@ -47,7 +47,7 @@ public static Subject.Factory re2jString() { * * @see #re2jString */ - public static final class Re2jStringSubject extends Subject { + public static final class Re2jStringSubject extends Subject { private static final Subject.Factory FACTORY = new Subject.Factory() { @Override