Skip to content

Commit 2487651

Browse files
nick-someoneronshapiro
authored andcommitted
Add @CompatibleWith("T") to the following Subject methods to catch callsites
where developers are testing things that could never be true: * isSameAs * isNotSameAs * isAnyOf * isNoneOf RELNOTES: Add the @CompatibleWith annotation from http://errorprone.info to isSameAs, isNotSameAs, isAnyOf, and isNoneOf in Subject, so users of the Error Prone compiler can check their tests. ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=182948419
1 parent 1f47a40 commit 2487651

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

core/src/main/java/com/google/common/truth/Subject.java

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import com.google.common.base.Predicates;
2424
import com.google.common.collect.Iterables;
2525
import com.google.errorprone.annotations.CanIgnoreReturnValue;
26+
import com.google.errorprone.annotations.CompatibleWith;
2627
import java.util.Arrays;
2728
import java.util.List;
2829
import javax.annotation.Nullable;
@@ -192,14 +193,14 @@ private static Long integralValue(Object o) {
192193
}
193194

194195
/** Fails if the subject is not the same instance as the given object. */
195-
public void isSameAs(@Nullable Object other) {
196+
public void isSameAs(@Nullable @CompatibleWith("T") Object other) {
196197
if (actual() != other) {
197198
failComparingToStrings("is the same instance as", actual(), other, other, true);
198199
}
199200
}
200201

201202
/** Fails if the subject is the same instance as the given object. */
202-
public void isNotSameAs(@Nullable Object other) {
203+
public void isNotSameAs(@Nullable @CompatibleWith("T") Object other) {
203204
if (actual() == other) {
204205
fail("is not the same instance as", other);
205206
}
@@ -255,7 +256,10 @@ public void isIn(Iterable<?> iterable) {
255256
}
256257

257258
/** Fails unless the subject is equal to any of the given elements. */
258-
public void isAnyOf(@Nullable Object first, @Nullable Object second, @Nullable Object... rest) {
259+
public void isAnyOf(
260+
@Nullable @CompatibleWith("T") Object first,
261+
@Nullable @CompatibleWith("T") Object second,
262+
@Nullable Object... rest) {
259263
List<Object> list = accumulate(first, second, rest);
260264
if (!list.contains(actual())) {
261265
fail("is equal to any of", list);
@@ -273,7 +277,10 @@ public void isNotIn(Iterable<?> iterable) {
273277
}
274278

275279
/** Fails if the subject is equal to any of the given elements. */
276-
public void isNoneOf(@Nullable Object first, @Nullable Object second, @Nullable Object... rest) {
280+
public void isNoneOf(
281+
@Nullable @CompatibleWith("T") Object first,
282+
@Nullable @CompatibleWith("T") Object second,
283+
@Nullable Object... rest) {
277284
isNotIn(accumulate(first, second, rest));
278285
}
279286

0 commit comments

Comments
 (0)