Skip to content

Commit

Permalink
Remove type parameters from ProtoSubject and LiteProtoSubject and the…
Browse files Browse the repository at this point in the history
…ir users.

Also, change most Subject classes in Truth itself (including ProtoSubject and LiteProtoSubject) to extend raw Subject. The type parameters will be removed from Subject.

This CL doesn't cover subjects that extend from ComparableSubject, since we are removing only *some* of its type parameters (and I'm planning to make that change atomically). Ditto for IterableOfProtosSubject, MapWithProtoValuesSubject, and MultimapWithProtoValuesSubject. I probably could have at least changed ComparableSubject, etc. to extend raw Subject in this CL, but I didn't think about it until now. Oh, well.

This CL also doesn't cover DefaultSubject.

RELNOTES=Removed the type parameters of `ProtoSubject` and `LiteProtoSubject`. If you subclass either of those types (or declare them as method return types, etc.), you will have to update those usages at the same time you update Truth. Or you can remove the type parameters from your usages (temporarily introducing rawtypes/unchecked warnings, which you may wish to suppress) and then update Truth (at which point the warnings will go away and you can remove any suppressions).

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=252053320
  • Loading branch information
cpovirk committed Jun 11, 2019
1 parent 5373725 commit eb3852c
Show file tree
Hide file tree
Showing 41 changed files with 81 additions and 141 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@
*
* @author Christian Gruber (cgruber@israfil.net)
*/
abstract class AbstractArraySubject<S extends AbstractArraySubject<S, T>, T> extends Subject<S, T> {
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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
*
* @author Kurt Alfred Kluever
*/
public final class AtomicLongMapSubject extends Subject<AtomicLongMapSubject, AtomicLongMap<?>> {
public final class AtomicLongMapSubject extends Subject {
private final AtomicLongMap<?> actual;

AtomicLongMapSubject(FailureMetadata metadata, @NullableDecl AtomicLongMap<?> map) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
*
* @author Christian Gruber (cgruber@israfil.net)
*/
public final class BooleanSubject extends Subject<BooleanSubject, Boolean> {
public final class BooleanSubject extends Subject {
private final Boolean actual;

BooleanSubject(FailureMetadata metadata, @NullableDecl Boolean actual) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
* @author Kurt Alfred Kluever
*/
@GwtIncompatible("reflection")
public final class ClassSubject extends Subject<ClassSubject, Class<?>> {
public final class ClassSubject extends Subject {
private final Class<?> actual;

ClassSubject(FailureMetadata metadata, @NullableDecl Class<?> o) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand All @@ -78,15 +78,15 @@ 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<String, String> descriptionUpdate;

// Present only when descriptionUpdate is.
@NullableDecl final OldAndNewValuesAreSimilar valuesAreSimilar;

private Step(
@NullableDecl Subject<?, ?> subject,
@NullableDecl Subject subject,
@NullableDecl Function<String, String> descriptionUpdate,
@NullableDecl OldAndNewValuesAreSimilar valuesAreSimilar) {
this.subject = subject;
Expand Down Expand Up @@ -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<Step> steps = append(this.steps, Step.subjectCreation(subject));
return derive(messages, steps);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
*
* @author Christian Gruber
*/
public final class GuavaOptionalSubject extends Subject<GuavaOptionalSubject, Optional<?>> {
public final class GuavaOptionalSubject extends Subject {
private final Optional<?> actual;

GuavaOptionalSubject(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@
* @author Pete Gillin
*/
// Can't be final since MultisetSubject and SortedSetSubject extend it
public class IterableSubject extends Subject<IterableSubject, Iterable<?>> {
public class IterableSubject extends Subject {

private final Iterable<?> actual;

Expand Down Expand Up @@ -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);
}
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/java/com/google/common/truth/MapSubject.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
* @author Christian Gruber
* @author Kurt Alfred Kluever
*/
public class MapSubject extends Subject<MapSubject, Map<?, ?>> {
public class MapSubject extends Subject {
private final Map<?, ?> actual;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
* @author Daniel Ploch
* @author Kurt Alfred Kluever
*/
public class MultimapSubject extends Subject<MultimapSubject, Multimap<?, ?>> {
public class MultimapSubject extends Subject {

/** Ordered implementation that does nothing because an earlier check already caused a failure. */
private static final Ordered ALREADY_FAILED =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
*
* @author Christian Gruber
*/
public final class ObjectArraySubject<T> extends AbstractArraySubject<ObjectArraySubject<T>, T[]> {
public final class ObjectArraySubject<T> extends AbstractArraySubject {
private final T[] actual;

ObjectArraySubject(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@
*
* @author Christian Gruber (cgruber@israfil.net)
*/
public final class PrimitiveBooleanArraySubject
extends AbstractArraySubject<PrimitiveBooleanArraySubject, boolean[]> {
public final class PrimitiveBooleanArraySubject extends AbstractArraySubject {
private final boolean[] actual;

PrimitiveBooleanArraySubject(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@
*
* @author Kurt Alfred Kluever
*/
public final class PrimitiveByteArraySubject
extends AbstractArraySubject<PrimitiveByteArraySubject, byte[]> {
public final class PrimitiveByteArraySubject extends AbstractArraySubject {
private final byte[] actual;

PrimitiveByteArraySubject(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@
*
* @author Christian Gruber (cgruber@israfil.net)
*/
public final class PrimitiveCharArraySubject
extends AbstractArraySubject<PrimitiveCharArraySubject, char[]> {
public final class PrimitiveCharArraySubject extends AbstractArraySubject {
private final char[] actual;

PrimitiveCharArraySubject(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@
*
* @author Christian Gruber (cgruber@israfil.net)
*/
public final class PrimitiveDoubleArraySubject
extends AbstractArraySubject<PrimitiveDoubleArraySubject, double[]> {
public final class PrimitiveDoubleArraySubject extends AbstractArraySubject {
private final double[] actual;

PrimitiveDoubleArraySubject(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@
*
* @author Christian Gruber (cgruber@israfil.net)
*/
public final class PrimitiveFloatArraySubject
extends AbstractArraySubject<PrimitiveFloatArraySubject, float[]> {
public final class PrimitiveFloatArraySubject extends AbstractArraySubject {
private final float[] actual;

PrimitiveFloatArraySubject(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@
*
* @author Christian Gruber (cgruber@israfil.net)
*/
public final class PrimitiveIntArraySubject
extends AbstractArraySubject<PrimitiveIntArraySubject, int[]> {
public final class PrimitiveIntArraySubject extends AbstractArraySubject {
private final int[] actual;

PrimitiveIntArraySubject(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@
*
* @author Christian Gruber (cgruber@israfil.net)
*/
public final class PrimitiveLongArraySubject
extends AbstractArraySubject<PrimitiveLongArraySubject, long[]> {
public final class PrimitiveLongArraySubject extends AbstractArraySubject {
private final long[] actual;

PrimitiveLongArraySubject(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@
*
* @author Christian Gruber (cgruber@israfil.net)
*/
public final class PrimitiveShortArraySubject
extends AbstractArraySubject<PrimitiveShortArraySubject, short[]> {
public final class PrimitiveShortArraySubject extends AbstractArraySubject {
private final short[] actual;

PrimitiveShortArraySubject(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
import java.util.Map;

/**
* Utility methods used in {@code Subject<T>} implementors.
* Utility methods used in {@code Subject} implementors.
*
* @author Christian Gruber
* @author Jens Nyman
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
*
* @author Kurt Alfred Kluever
*/
public final class TableSubject extends Subject<TableSubject, Table<?, ?, ?>> {
public final class TableSubject extends Subject {
private final Table<?, ?, ?> actual;

TableSubject(FailureMetadata metadata, @NullableDecl Table<?, ?, ?> table) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
*
* @author Kurt Alfred Kluever
*/
public class ThrowableSubject extends Subject<ThrowableSubject, Throwable> {
public class ThrowableSubject extends Subject {
private final Throwable actual;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ public void badFormat() {
* tests like MultimapSubjectTest.
*/

private static final class MyObjectSubject extends Subject<MyObjectSubject, Object> {
private static final class MyObjectSubject extends Subject {
static final Factory<MyObjectSubject, Object> FACTORY =
new Factory<MyObjectSubject, Object>() {
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ public StringSubject createSubject(FailureMetadata fm, String that) {
};
}

private static class BadSubject extends Subject<BadSubject, Integer> {
private static class BadSubject extends Subject {
private final Integer actual;

BadSubject(FailureMetadata failureMetadat, Integer actual) {
Expand Down
5 changes: 2 additions & 3 deletions core/src/test/java/com/google/common/truth/SubjectTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -783,8 +783,7 @@ public boolean equals(Object obj) {
}
}

private static final class ForbidsEqualityChecksSubject
extends Subject<ForbidsEqualityChecksSubject, Object> {
private static final class ForbidsEqualityChecksSubject extends Subject {
ForbidsEqualityChecksSubject(FailureMetadata metadata, @NullableDecl Object actual) {
super(metadata, actual);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
*
* @author Kurt Alfred Kluever (kak@google.com)
*/
public final class EmployeeSubject extends Subject<EmployeeSubject, Employee> {
public final class EmployeeSubject extends Subject {

// User-defined entry point
public static EmployeeSubject assertThat(@NullableDecl Employee employee) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
*
* @author Kurt Alfred Kluever
*/
public final class IntStreamSubject extends Subject<IntStreamSubject, IntStream> {
public final class IntStreamSubject extends Subject {

private final List<?> actualList;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
*
* @author Kurt Alfred Kluever
*/
public final class LongStreamSubject extends Subject<LongStreamSubject, LongStream> {
public final class LongStreamSubject extends Subject {

private final List<?> actualList;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
*
* @author Ben Douglass
*/
public final class OptionalDoubleSubject extends Subject<OptionalDoubleSubject, OptionalDouble> {
public final class OptionalDoubleSubject extends Subject {

private final OptionalDouble actual;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
*
* @author Ben Douglass
*/
public final class OptionalIntSubject extends Subject<OptionalIntSubject, OptionalInt> {
public final class OptionalIntSubject extends Subject {
private final OptionalInt actual;

OptionalIntSubject(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
*
* @author Ben Douglass
*/
public final class OptionalLongSubject extends Subject<OptionalLongSubject, OptionalLong> {
public final class OptionalLongSubject extends Subject {
private final OptionalLong actual;

OptionalLongSubject(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
*
* @author Christian Gruber
*/
public final class OptionalSubject extends Subject<OptionalSubject, Optional<?>> {
public final class OptionalSubject extends Subject {
private final Optional<?> actual;

OptionalSubject(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

/** Assertions for {@link Path} instances. */
@GwtIncompatible
public final class PathSubject extends Subject<PathSubject, Path> {
public final class PathSubject extends Subject {
private PathSubject(FailureMetadata failureMetadata, Path actual) {
super(failureMetadata, actual);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 <i>very</i> large or infinite.
*
* <p>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.
* <p>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.
*
* <p>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<StreamSubject, Stream<?>> {
public final class StreamSubject extends Subject {

private final List<?> actualList;

Expand Down
Loading

0 comments on commit eb3852c

Please sign in to comment.