diff --git a/core/src/main/java/com/google/common/truth/AtomicLongMapSubject.java b/core/src/main/java/com/google/common/truth/AtomicLongMapSubject.java deleted file mode 100644 index b71db76bd..000000000 --- a/core/src/main/java/com/google/common/truth/AtomicLongMapSubject.java +++ /dev/null @@ -1,139 +0,0 @@ -/* - * Copyright (c) 2011 Google, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.google.common.truth; - -import static com.google.common.base.Preconditions.checkArgument; -import static com.google.common.base.Preconditions.checkNotNull; -import static com.google.common.collect.Maps.immutableEntry; -import static com.google.common.truth.Fact.simpleFact; - -import com.google.common.util.concurrent.AtomicLongMap; -import org.checkerframework.checker.nullness.compatqual.NullableDecl; - -/** - * Propositions for {@link AtomicLongMap} subjects. - * - * @author Kurt Alfred Kluever - * @deprecated Perform assertions on the {@link AtomicLongMap#asMap()} view. - */ -@Deprecated -public final class AtomicLongMapSubject extends Subject { - private final AtomicLongMap actual; - - AtomicLongMapSubject(FailureMetadata metadata, @NullableDecl AtomicLongMap map) { - super(metadata, map); - this.actual = map; - } - - /** - * @deprecated {@link AtomicLongMap} does not define equality (i.e., it does not implement - * equals()), so you probably don't want to call this method. Instead, perform your assertion - * on the map view (e.g., assertThat(atomicLongMap.asMap()).isEqualTo(EXPECTED_MAP)). - */ - @Deprecated - @Override - public void isEqualTo(@NullableDecl Object other) { - super.isEqualTo(other); - } - - /** - * @deprecated {@link AtomicLongMap} does not define equality (i.e., it does not implement - * equals()), so you probably don't want to call this method. Instead, perform your assertion - * on the map view (e.g., assertThat(atomicLongMap.asMap()).isNotEqualTo(UNEXPECTED_MAP)). - */ - @Deprecated - @Override - public void isNotEqualTo(@NullableDecl Object other) { - super.isNotEqualTo(other); - } - - /** Fails if the {@link AtomicLongMap} is not empty. */ - public void isEmpty() { - if (!actual.isEmpty()) { - failWithActual(simpleFact("expected to be empty")); - } - } - - /** Fails if the {@link AtomicLongMap} is empty. */ - public void isNotEmpty() { - if (actual.isEmpty()) { - failWithoutActual(simpleFact("expected not to be empty")); - } - } - - /** Fails if the {@link AtomicLongMap} does not have the given size. */ - public void hasSize(int expectedSize) { - checkArgument(expectedSize >= 0, "expectedSize (%s) must be >= 0", expectedSize); - check("size()").that(actual.size()).isEqualTo(expectedSize); - } - - /** Fails if the {@link AtomicLongMap} does not have the given sum. */ - public void hasSum(long expectedSum) { - check("sum()").that(actual.sum()).isEqualTo(expectedSum); - } - - /** Fails if the {@link AtomicLongMap} does not contain the given key. */ - public void containsKey(Object key) { - checkNotNull(key, "AtomicLongMap does not support null keys"); - check("asMap().keySet()").that(actual.asMap().keySet()).contains(key); - } - - /** Fails if the {@link AtomicLongMap} contains the given key. */ - public void doesNotContainKey(Object key) { - checkNotNull(key, "AtomicLongMap does not support null keys"); - check("asMap().keySet()").that(actual.asMap().keySet()).doesNotContain(key); - } - - /* - * TODO(cpovirk): These methods don't actually check whether the AtomicLongMap contains the given - * entry. Specifically, if `value` is 0, they check that the AtomicLongMap contains the key with - * value 0 *or* that it does *not* contain the key. (Contrast to containsKey above, which - * distinguishes between "present with value 0" and "not present.") - * - * We should consider renaming the methods to something like "hasValue" (or changing their - * behavior to really check that the key is present, but that seems unlikely to be what most users - * want): https://github.com/google/truth/issues/451 - */ - /** Fails if the {@link AtomicLongMap} does not contain the given entry. */ - @SuppressWarnings("unchecked") // worse case should be a ClassCastException - /* - * TODO(cpovirk): Consider requiring key to be a K here. But AtomicLongMapSubject isn't currently - * parameterized, and if we're going to add a type parameter, I'd rather wait until after we - * (hopefully) remove the other existing type parameters. - */ - public void containsEntry(Object key, long value) { - checkNotNull(key, "AtomicLongMap does not support null keys"); - long actualValue = ((AtomicLongMap) actual).get(key); - if (actualValue != value) { - failWithActual("expected to contain entry", immutableEntry(key, value)); - } - } - - @SuppressWarnings("unchecked") // see containsEntry - /** Fails if the {@link AtomicLongMap} contains the given entry. */ - public void doesNotContainEntry(Object key, long value) { - checkNotNull(key, "AtomicLongMap does not support null keys"); - long actualValue = ((AtomicLongMap) actual).get(key); - if (actualValue == value) { - failWithActual("expected not to contain entry", immutableEntry(key, value)); - } - } - - /* - * TODO(kak): Consider adding containsExactly() / containsExactlyEntriesIn() like MapSubject? If - * we do, see the TODO about containsEntry above. - */ -} diff --git a/core/src/main/java/com/google/common/truth/DefaultSubject.java b/core/src/main/java/com/google/common/truth/DefaultSubject.java deleted file mode 100644 index f538910ba..000000000 --- a/core/src/main/java/com/google/common/truth/DefaultSubject.java +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Copyright (c) 2011 Google, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.google.common.truth; - -import org.checkerframework.checker.nullness.compatqual.NullableDecl; - -/** - * @deprecated Use plain {@link Subject} instead. At the moment, {@code Subject} has type - * parameters, so you may wish to use {@code Subject}. However, those type parameters will - * soon go away, so you may wish to start using raw {@code Subject} now to prepare. - */ -@Deprecated -public class DefaultSubject extends Subject { - /** - * Constructor for use by subclasses. If you want to create an instance of this class itself, call - * {@link Subject#check}{@code .that(actual)}. - */ - protected DefaultSubject(FailureMetadata metadata, @NullableDecl Object o) { - super(metadata, o); - } -} diff --git a/core/src/main/java/com/google/common/truth/StandardSubjectBuilder.java b/core/src/main/java/com/google/common/truth/StandardSubjectBuilder.java index cab273504..28dffbf96 100644 --- a/core/src/main/java/com/google/common/truth/StandardSubjectBuilder.java +++ b/core/src/main/java/com/google/common/truth/StandardSubjectBuilder.java @@ -23,7 +23,6 @@ import com.google.common.collect.Multimap; import com.google.common.collect.Multiset; import com.google.common.collect.Table; -import com.google.common.util.concurrent.AtomicLongMap; import java.math.BigDecimal; import java.util.Map; import org.checkerframework.checker.nullness.compatqual.NullableDecl; @@ -171,12 +170,6 @@ public final TableSubject that(@NullableDecl Table actual) { return new TableSubject(metadata(), actual); } - /** @deprecated Perform assertions on the {@link AtomicLongMap#asMap()} view. */ - @Deprecated - public final AtomicLongMapSubject that(@NullableDecl AtomicLongMap actual) { - return new AtomicLongMapSubject(metadata(), actual); - } - /** * Returns a new instance that will output the given message before the main failure message. If * this method is called multiple times, the messages will appear in the order that they were @@ -228,18 +221,6 @@ public final void fail() { metadata().fail(ImmutableList.of()); } - /** - * Reports a failure with the given message. - * - * @deprecated Instead of {@code assert_().fail(...)}, use {@code assertWithMessage(...).fail()}. - * Similarly, instead of {@code expect.fail(...)}, use {@code expect.withMessage(...).fail()}, - * and so forth. - */ - @Deprecated - public final void fail(String format, Object /*@NullableDeclType*/... args) { - withMessage(format, args).fail(); - } - private FailureMetadata metadata() { checkStatePreconditions(); return metadataDoNotReferenceDirectly; 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 e1a88fac1..b4be5def2 100644 --- a/core/src/main/java/com/google/common/truth/ThrowableSubject.java +++ b/core/src/main/java/com/google/common/truth/ThrowableSubject.java @@ -69,7 +69,9 @@ public final ThrowableSubject hasCauseThat() { // TODO(diamondm) in keeping with other subjects' behavior this should still NPE if the subject // *itself* is null, since there's no context to lose. See also b/37645583 if (actual == null) { - check("getCause()").fail("Causal chain is not deep enough - add a .isNotNull() check?"); + check("getCause()") + .withMessage("Causal chain is not deep enough - add a .isNotNull() check?") + .fail(); return ignoreCheck() .that( new Throwable() { diff --git a/core/src/main/java/com/google/common/truth/Truth.java b/core/src/main/java/com/google/common/truth/Truth.java index 5ee42b410..19a6887d8 100644 --- a/core/src/main/java/com/google/common/truth/Truth.java +++ b/core/src/main/java/com/google/common/truth/Truth.java @@ -22,7 +22,6 @@ import com.google.common.collect.Multimap; import com.google.common.collect.Multiset; import com.google.common.collect.Table; -import com.google.common.util.concurrent.AtomicLongMap; import java.math.BigDecimal; import java.util.Map; import org.checkerframework.checker.nullness.compatqual.NullableDecl; @@ -242,13 +241,6 @@ public static TableSubject assertThat(@NullableDecl Table actual) { return assert_().that(actual); } - /** @deprecated Perform assertions on the {@link AtomicLongMap#asMap()} view. */ - @Deprecated - public static AtomicLongMapSubject assertThat( - @NullableDecl AtomicLongMap actual) { - return assert_().that(actual); - } - /** * An {@code AssertionError} that (a) always supports a cause, even under old versions of Android * and (b) omits "java.lang.AssertionError:" from the beginning of its toString() representation. diff --git a/core/src/test/java/com/google/common/truth/AtomicLongMapSubjectTest.java b/core/src/test/java/com/google/common/truth/AtomicLongMapSubjectTest.java deleted file mode 100644 index 84fdd4c27..000000000 --- a/core/src/test/java/com/google/common/truth/AtomicLongMapSubjectTest.java +++ /dev/null @@ -1,265 +0,0 @@ -/* - * Copyright (c) 2011 Google, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.google.common.truth; - -import static com.google.common.truth.Truth.assertThat; -import static org.junit.Assert.fail; - -import com.google.common.util.concurrent.AtomicLongMap; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.JUnit4; - -/** - * Tests for {@link AtomicLongMap} subjects. - * - * @author Kurt Alfred Kluever - */ -@RunWith(JUnit4.class) -public final class AtomicLongMapSubjectTest extends BaseSubjectTestCase { - - @Test - public void isEqualToFail() { - AtomicLongMap alm1 = AtomicLongMap.create(); - AtomicLongMap alm2 = AtomicLongMap.create(); - - expectFailureWhenTestingThat(alm1).isEqualTo(alm2); - } - - @Test - public void isEmpty() { - AtomicLongMap actual = AtomicLongMap.create(); - assertThat(actual).isEmpty(); - } - - @Test - public void isEmptyWithFailure() { - AtomicLongMap actual = AtomicLongMap.create(); - actual.getAndIncrement("foo"); - - expectFailureWhenTestingThat(actual).isEmpty(); - assertFailureKeys("expected to be empty", "but was"); - } - - @Test - public void isNotEmpty() { - AtomicLongMap actual = AtomicLongMap.create(); - actual.getAndIncrement("FOO"); - assertThat(actual).isNotEmpty(); - } - - @Test - public void isNotEmptyWithFailure() { - AtomicLongMap actual = AtomicLongMap.create(); - expectFailureWhenTestingThat(actual).isNotEmpty(); - assertFailureKeys("expected not to be empty"); - } - - @Test - public void hasSize() { - AtomicLongMap actual = AtomicLongMap.create(); - actual.getAndIncrement("kurt"); - assertThat(actual).hasSize(1); - } - - @Test - public void hasSizeZero() { - assertThat(AtomicLongMap.create()).hasSize(0); - } - - @Test - public void hasSizeNegative() { - try { - assertThat(AtomicLongMap.create()).hasSize(-1); - fail(); - } catch (IllegalArgumentException expected) { - } - } - - @Test - public void hasSizeFails() { - AtomicLongMap actual = AtomicLongMap.create(); - actual.getAndIncrement("kurt"); - expectFailureWhenTestingThat(actual).hasSize(2); - assertFailureValue("value of", "atomicLongMap.size()"); - } - - @Test - public void hasSum() { - AtomicLongMap actual = AtomicLongMap.create(); - actual.getAndIncrement("kurt"); - actual.getAndIncrement("kurt"); - assertThat(actual).hasSum(2); - } - - @Test - public void hasSumZero() { - assertThat(AtomicLongMap.create()).hasSum(0); - } - - @Test - public void hasSumNegative() { - AtomicLongMap actual = AtomicLongMap.create(); - actual.getAndDecrement("kurt"); - assertThat(actual).hasSum(-1); - } - - @Test - public void hasSumFails() { - AtomicLongMap actual = AtomicLongMap.create(); - actual.getAndIncrement("kurt"); - expectFailureWhenTestingThat(actual).hasSum(2); - assertFailureValue("value of", "atomicLongMap.sum()"); - } - - @Test - public void containsKey() { - AtomicLongMap actual = AtomicLongMap.create(); - actual.getAndIncrement("kurt"); - assertThat(actual).containsKey("kurt"); - } - - @Test - public void containsKeyFailure() { - AtomicLongMap actual = AtomicLongMap.create(); - actual.getAndIncrement("kurt"); - expectFailureWhenTestingThat(actual).containsKey("greg"); - assertFailureKeys("value of", "expected to contain", "but was", "atomicLongMap was"); - assertFailureValue("value of", "atomicLongMap.asMap().keySet()"); - assertFailureValue("expected to contain", "greg"); - } - - @Test - public void doesNotContainKey() { - AtomicLongMap actual = AtomicLongMap.create(); - actual.getAndIncrement("kurt"); - assertThat(actual).doesNotContainKey("greg"); - } - - @Test - public void doesNotContainKeyFailure() { - AtomicLongMap actual = AtomicLongMap.create(); - actual.getAndIncrement("kurt"); - expectFailureWhenTestingThat(actual).doesNotContainKey("kurt"); - assertFailureKeys("value of", "expected not to contain", "but was", "atomicLongMap was"); - assertFailureValue("value of", "atomicLongMap.asMap().keySet()"); - assertFailureValue("expected not to contain", "kurt"); - } - - @Test - public void doesNotContainNullKey() { - AtomicLongMap actual = AtomicLongMap.create(); - try { - assertThat(actual).doesNotContainKey(null); - fail("Should have thrown."); - } catch (NullPointerException expected) { - assertThat(expected).hasMessageThat().isEqualTo("AtomicLongMap does not support null keys"); - } - } - - @Test - public void containsEntry() { - AtomicLongMap actual = AtomicLongMap.create(); - actual.getAndIncrement("kurt"); - assertThat(actual).containsEntry("kurt", 1); - } - - @Test - public void containsEntryZeroDoesNotContain() { - AtomicLongMap actual = AtomicLongMap.create(); - // This passes, which is maybe surprising or maybe not. See the TODO in AtomicLongMapSubject. - assertThat(actual).containsEntry("kurt", 0); - } - - @Test - public void containsEntryFailure() { - AtomicLongMap actual = AtomicLongMap.create(); - actual.getAndIncrement("kurt"); - expectFailureWhenTestingThat(actual).containsEntry("greg", 2); - assertFailureKeys("expected to contain entry", "but was"); - assertFailureValue("expected to contain entry", "greg=2"); - assertFailureValue("but was", "{kurt=1}"); - } - - @Test - public void doesNotContainEntry() { - AtomicLongMap actual = AtomicLongMap.create(); - actual.getAndIncrement("kurt"); - assertThat(actual).doesNotContainEntry("greg", 2); - } - - @Test - public void doesNotContainEntryNullKey() { - AtomicLongMap actual = AtomicLongMap.create(); - try { - assertThat(actual).doesNotContainEntry(null, 2); - fail(); - } catch (NullPointerException expected) { - assertThat(expected).hasMessageThat().isEqualTo("AtomicLongMap does not support null keys"); - } - } - - @Test - public void doesNotContainEntryFailure() { - AtomicLongMap actual = AtomicLongMap.create(); - actual.getAndIncrement("kurt"); - expectFailureWhenTestingThat(actual).doesNotContainEntry("kurt", 1); - assertFailureKeys("expected not to contain entry", "but was"); - assertFailureValue("expected not to contain entry", "kurt=1"); - assertFailureValue("but was", "{kurt=1}"); - } - - @Test - public void failMapContainsKey() { - AtomicLongMap actual = AtomicLongMap.create(); - actual.getAndIncrement("kurt"); - expectFailureWhenTestingThat(actual).containsKey("greg"); - assertFailureKeys("value of", "expected to contain", "but was", "atomicLongMap was"); - assertFailureValue("value of", "atomicLongMap.asMap().keySet()"); - assertFailureValue("expected to contain", "greg"); - } - - @Test - public void failMapLacksKey() { - AtomicLongMap actual = AtomicLongMap.create(); - actual.getAndIncrement("kurt"); - expectFailureWhenTestingThat(actual).doesNotContainKey("kurt"); - assertFailureKeys("value of", "expected not to contain", "but was", "atomicLongMap was"); - assertFailureValue("value of", "atomicLongMap.asMap().keySet()"); - assertFailureValue("expected not to contain", "kurt"); - } - - @Test - public void containsKeyWithValue() { - AtomicLongMap actual = AtomicLongMap.create(); - actual.getAndIncrement("kurt"); - assertThat(actual).containsEntry("kurt", 1); - } - - @Test - public void failMapContainsKeyWithValue() { - AtomicLongMap actual = AtomicLongMap.create(); - actual.getAndIncrement("kurt"); - expectFailureWhenTestingThat(actual).containsEntry("kurt", 2); - assertFailureKeys("expected to contain entry", "but was"); - assertFailureValue("expected to contain entry", "kurt=2"); - assertFailureValue("but was", "{kurt=1}"); - } - - private AtomicLongMapSubject expectFailureWhenTestingThat(AtomicLongMap actual) { - return expectFailure.whenTesting().that(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 ac58ec06e..9365d2969 100644 --- a/core/src/test/java/com/google/common/truth/ChainingTest.java +++ b/core/src/test/java/com/google/common/truth/ChainingTest.java @@ -242,11 +242,11 @@ void isThePresentKingOfFrance() { } void doCheckFail() { - check().fail("message"); + check().withMessage("message").fail(); } void doCheckFail(String name) { - check(name).fail("message"); + check(name).withMessage("message").fail(); } /** diff --git a/core/src/test/java/com/google/common/truth/ExpectFailureRuleTest.java b/core/src/test/java/com/google/common/truth/ExpectFailureRuleTest.java index 8c83d8663..d79d75b77 100644 --- a/core/src/test/java/com/google/common/truth/ExpectFailureRuleTest.java +++ b/core/src/test/java/com/google/common/truth/ExpectFailureRuleTest.java @@ -33,7 +33,7 @@ public class ExpectFailureRuleTest { @Test public void expectFail_captureFailureAsExpected() { - expectFailure.whenTesting().fail("abc"); + expectFailure.whenTesting().withMessage("abc").fail(); assertThat(expectFailure.getFailure()).hasMessageThat().isEqualTo("abc"); } 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 ff7f1f9d1..74dd80dde 100644 --- a/core/src/test/java/com/google/common/truth/ExpectFailureTest.java +++ b/core/src/test/java/com/google/common/truth/ExpectFailureTest.java @@ -36,7 +36,7 @@ public void setupExpectFailure() { @Test public void expectFail() { - expectFailure.whenTesting().fail("abc"); + expectFailure.whenTesting().withMessage("abc").fail(); assertThat(expectFailure.getFailure()).hasMessageThat().isEqualTo("abc"); } diff --git a/core/src/test/java/com/google/common/truth/ExpectTest.java b/core/src/test/java/com/google/common/truth/ExpectTest.java index 8647897b0..e079ee14f 100644 --- a/core/src/test/java/com/google/common/truth/ExpectTest.java +++ b/core/src/test/java/com/google/common/truth/ExpectTest.java @@ -93,7 +93,7 @@ public void expectTrue() { public void singleExpectationFails() { thrown.expectMessage("1 expectation failed:"); thrown.expectMessage("1. x"); - expect.fail("x"); + expect.withMessage("x").fail(); } @Test @@ -102,9 +102,9 @@ public void expectFail() { thrown.expectMessage("1. x"); thrown.expectMessage("2. y"); thrown.expectMessage("3. z"); - expect.fail("x"); - expect.fail("y"); - expect.fail("z"); + expect.withMessage("x").fail(); + expect.withMessage("y").fail(); + expect.withMessage("z").fail(); } @Test @@ -113,7 +113,7 @@ public void expectFail10Aligned() { thrown.expectMessage(" 1. x"); thrown.expectMessage("10. x"); for (int i = 0; i < 10; i++) { - expect.fail("x"); + expect.withMessage("x").fail(); } } @@ -123,7 +123,7 @@ public void expectFail10WrappedAligned() { thrown.expectMessage(" 1. abc\n xyz"); thrown.expectMessage("10. abc\n xyz"); for (int i = 0; i < 10; i++) { - expect.fail("abc\nxyz"); + expect.withMessage("abc\nxyz").fail(); } } @@ -133,8 +133,8 @@ public void expectFailWithExceptionNoMessage() { thrown.expectMessage("1. x"); thrown.expectMessage("2. y"); thrown.expectMessage("3. Also, after those failures, an exception was thrown:"); - expect.fail("x"); - expect.fail("y"); + expect.withMessage("x").fail(); + expect.withMessage("y").fail(); throw new IllegalStateException(); } @@ -144,8 +144,8 @@ public void expectFailWithExceptionWithMessage() { thrown.expectMessage("1. x"); thrown.expectMessage("2. y"); thrown.expectMessage("3. Also, after those failures, an exception was thrown:"); - expect.fail("x"); - expect.fail("y"); + expect.withMessage("x").fail(); + expect.withMessage("y").fail(); throw new IllegalStateException("testing"); } @@ -154,8 +154,8 @@ public void expectFailWithExceptionBeforeExpectFailures() { thrown.expect(IllegalStateException.class); thrown.expectMessage("testing"); throwException(); - expect.fail("x"); - expect.fail("y"); + expect.withMessage("x").fail(); + expect.withMessage("y").fail(); } private void throwException() { @@ -168,16 +168,16 @@ public void expectFailWithFailuresBeforeAssume() { thrown.expectMessage("1. x"); thrown.expectMessage("2. y"); thrown.expectMessage("3. Also, after those failures, an assumption was violated:"); - expect.fail("x"); - expect.fail("y"); - assume().fail("testing"); + expect.withMessage("x").fail(); + expect.withMessage("y").fail(); + assume().withMessage("testing").fail(); } @Test public void expectSuccessWithFailuresAfterAssume() { - assume().fail("testing"); - expect.fail("x"); - expect.fail("y"); + assume().withMessage("testing").fail(); + expect.withMessage("x").fail(); + expect.withMessage("y").fail(); } @Test diff --git a/core/src/test/java/com/google/common/truth/StandardSubjectBuilderTest.java b/core/src/test/java/com/google/common/truth/StandardSubjectBuilderTest.java index 96bed9d9f..4b20d506f 100644 --- a/core/src/test/java/com/google/common/truth/StandardSubjectBuilderTest.java +++ b/core/src/test/java/com/google/common/truth/StandardSubjectBuilderTest.java @@ -16,8 +16,6 @@ package com.google.common.truth; -import static com.google.common.truth.Truth.assert_; - import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; @@ -30,19 +28,4 @@ public void failNoMessage() { expectFailure.whenTesting().fail(); assertThatFailure().hasMessageThat().isEmpty(); } - - @Test - public void failWithMessage() { - expectFailure.whenTesting().fail("at index %s", 1); - assertThatFailure().hasMessageThat().isEqualTo("at index 1"); - } - - @Test - public void failNullMessage() { - try { - assert_().fail(null); - throw new AssertionError("should have thrown NullPointerException"); - } catch (NullPointerException expected) { - } - } } diff --git a/core/src/test/java/com/google/common/truth/gwt/TruthGwtTest.java b/core/src/test/java/com/google/common/truth/gwt/TruthGwtTest.java index 5d9eeb499..4a10e4140 100644 --- a/core/src/test/java/com/google/common/truth/gwt/TruthGwtTest.java +++ b/core/src/test/java/com/google/common/truth/gwt/TruthGwtTest.java @@ -19,7 +19,6 @@ import static com.google.common.truth.Truth.assert_; import static java.util.Arrays.asList; -import com.google.gwt.junit.client.GWTTestCase; import java.util.AbstractList; import java.util.ArrayList; import java.util.Collection; @@ -33,7 +32,7 @@ * @author Christian Gruber (cgruber@israfil.net) */ -public class TruthGwtTest extends GWTTestCase { +public class TruthGwtTest extends com.google.gwt.junit.client.GWTTestCase { @Override public String getModuleName() { return "com.google.common.truth.gwt.TruthTest"; } @@ -60,7 +59,7 @@ public void testInteger() { } catch (AssertionError expected) { return; } - assert_().fail("Should have thrown an assertion error"); + assert_().withMessage("Should have thrown an assertion error").fail(); } public void testString() { @@ -73,7 +72,7 @@ public void testString() { } catch (AssertionError expected) { return; } - assert_().fail("Should have thrown an assertion error"); + assert_().withMessage("Should have thrown an assertion error").fail(); } public void testString_match() { @@ -91,7 +90,7 @@ public void testString_matchesFail() { } catch (AssertionError expected) { return; } - assert_().fail("Should have thrown an assertion error"); + assert_().withMessage("Should have thrown an assertion error").fail(); } public void testString_containsMatchFail() { @@ -100,7 +99,7 @@ public void testString_containsMatchFail() { } catch (AssertionError expected) { return; } - assert_().fail("Should have thrown an assertion error"); + assert_().withMessage("Should have thrown an assertion error").fail(); } public void testString_doesNotMatchFail() { @@ -109,7 +108,7 @@ public void testString_doesNotMatchFail() { } catch (AssertionError expected) { return; } - assert_().fail("Should have thrown an assertion error"); + assert_().withMessage("Should have thrown an assertion error").fail(); } public void testString_doesNotContainMatchFail() { @@ -118,7 +117,7 @@ public void testString_doesNotContainMatchFail() { } catch (AssertionError expected) { return; } - assert_().fail("Should have thrown an assertion error"); + assert_().withMessage("Should have thrown an assertion error").fail(); } public void testIterable() { 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 371e87d43..9e1fd525d 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 @@ -78,23 +78,6 @@ public void hasValue(double expected) { } } - /** - * Prepares for a check regarding the value contained within the {@link OptionalDouble}. Fails - * immediately if the subject is empty. - * - * @deprecated Instead of {@code assertThat(optional).hasValueThat()....}, use {@code - * assertThat(optional.getAsDouble())....}. - */ - @Deprecated - public DoubleSubject hasValueThat() { - if (actual == null || !actual.isPresent()) { - isPresent(); // fails - return ignoreCheck().that(0.0); - } else { - return check("getAsDouble()").that(actual.getAsDouble()); - } - } - public static Subject.Factory optionalDoubles() { return (metadata, subject) -> new OptionalDoubleSubject(metadata, subject, "optionalDouble"); } 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 9692cd78b..261102a41 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 @@ -71,23 +71,6 @@ public void hasValue(int expected) { } } - /** - * Prepares for a check regarding the value contained within the {@link OptionalInt}. Fails - * immediately if the subject is empty. - * - * @deprecated Instead of {@code assertThat(optional).hasValueThat()....}, use {@code - * assertThat(optional.getAsInt())....}. - */ - @Deprecated - public IntegerSubject hasValueThat() { - if (actual == null || !actual.isPresent()) { - isPresent(); // fails - return ignoreCheck().that(0); - } else { - return check("getAsInt()").that(actual.getAsInt()); - } - } - public static Subject.Factory optionalInts() { return (metadata, subject) -> new OptionalIntSubject(metadata, subject, "optionalInt"); } 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 5c6dcfced..23fa6926a 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 @@ -71,23 +71,6 @@ public void hasValue(long expected) { } } - /** - * Prepares for a check regarding the value contained within the {@link OptionalLong}. Fails - * immediately if the subject is empty. - * - * @deprecated Instead of {@code assertThat(optional).hasValueThat()....}, use {@code - * assertThat(optional.getAsLong())....}. - */ - @Deprecated - public LongSubject hasValueThat() { - if (actual == null || !actual.isPresent()) { - isPresent(); // fails - return ignoreCheck().that(0L); - } else { - return check("getAsLong()").that(actual.getAsLong()); - } - } - public static Subject.Factory optionalLongs() { return (metadata, subject) -> new OptionalLongSubject(metadata, subject, "optionalLong"); } diff --git a/extensions/java8/src/test/java/com/google/common/truth/OptionalDoubleSubjectTest.java b/extensions/java8/src/test/java/com/google/common/truth/OptionalDoubleSubjectTest.java index af0916948..94490fa02 100644 --- a/extensions/java8/src/test/java/com/google/common/truth/OptionalDoubleSubjectTest.java +++ b/extensions/java8/src/test/java/com/google/common/truth/OptionalDoubleSubjectTest.java @@ -93,31 +93,6 @@ public void hasValue_FailingWithWrongValue() { assertThat(expected).factValue("value of").isEqualTo("optionalDouble.getAsDouble()"); } - @Test - public void hasValueThat_FailingWithEmpty() { - AssertionError expected = - expectFailure( - whenTesting -> { - DoubleSubject unused = whenTesting.that(OptionalDouble.empty()).hasValueThat(); - }); - assertThat(expected).factKeys().containsExactly("expected to be present"); - } - - @Test - public void hasValueThat_FailingWithComparison() { - AssertionError expected = - expectFailure( - whenTesting -> - whenTesting.that(OptionalDouble.of(1337.0)).hasValueThat().isLessThan(42.0)); - // TODO(cpovirk): Assert that "value of" is present once we set it: - // assertThat(expected).fieldValue("value of").isEqualTo("optionalDouble.getAsDouble()"); - } - - @Test - public void hasValueThat_SuccessWithComparison() { - assertThat(OptionalDouble.of(1337.0)).hasValueThat().isGreaterThan(42.0); - } - private static AssertionError expectFailure( ExpectFailure.SimpleSubjectBuilderCallback assertionCallback) { diff --git a/extensions/java8/src/test/java/com/google/common/truth/OptionalIntSubjectTest.java b/extensions/java8/src/test/java/com/google/common/truth/OptionalIntSubjectTest.java index 3a9391af8..9c68a875f 100644 --- a/extensions/java8/src/test/java/com/google/common/truth/OptionalIntSubjectTest.java +++ b/extensions/java8/src/test/java/com/google/common/truth/OptionalIntSubjectTest.java @@ -93,30 +93,6 @@ public void hasValue_FailingWithWrongValue() { assertThat(expected).factValue("value of").isEqualTo("optionalInt.getAsInt()"); } - @Test - public void hasValueThat_FailingWithEmpty() { - AssertionError expected = - expectFailure( - whenTesting -> { - IntegerSubject unused = whenTesting.that(OptionalInt.empty()).hasValueThat(); - }); - assertThat(expected).factKeys().containsExactly("expected to be present"); - } - - @Test - public void hasValueThat_FailingWithComparison() { - AssertionError unused = - expectFailure( - whenTesting -> whenTesting.that(OptionalInt.of(1337)).hasValueThat().isLessThan(42)); - // TODO(cpovirk): Assert that "value of" is present once we set it: - // assertThat(expected).fieldValue("value of").isEqualTo("optionalInt.getAsInt()"); - } - - @Test - public void hasValueThat_SuccessWithComparison() { - assertThat(OptionalInt.of(1337)).hasValueThat().isGreaterThan(42); - } - private static AssertionError expectFailure( ExpectFailure.SimpleSubjectBuilderCallback assertionCallback) { diff --git a/extensions/java8/src/test/java/com/google/common/truth/OptionalLongSubjectTest.java b/extensions/java8/src/test/java/com/google/common/truth/OptionalLongSubjectTest.java index 123bb4400..211ed504d 100644 --- a/extensions/java8/src/test/java/com/google/common/truth/OptionalLongSubjectTest.java +++ b/extensions/java8/src/test/java/com/google/common/truth/OptionalLongSubjectTest.java @@ -93,30 +93,6 @@ public void hasValue_FailingWithWrongValue() { assertThat(expected).factValue("value of").isEqualTo("optionalLong.getAsLong()"); } - @Test - public void hasValueThat_FailingWithEmpty() { - AssertionError expected = - expectFailure( - whenTesting -> { - LongSubject unused = whenTesting.that(OptionalLong.empty()).hasValueThat(); - }); - assertThat(expected).factKeys().containsExactly("expected to be present"); - } - - @Test - public void hasValueThat_FailingWithComparison() { - AssertionError expected = - expectFailure( - whenTesting -> whenTesting.that(OptionalLong.of(1337L)).hasValueThat().isLessThan(42L)); - // TODO(cpovirk): Assert that "value of" is present once we set it: - // assertThat(expected).fieldValue("value of").isEqualTo("optionalLong.getAsLong()"); - } - - @Test - public void hasValueThat_SuccessWithComparison() { - assertThat(OptionalLong.of(1337L)).hasValueThat().isGreaterThan(42L); - } - private static AssertionError expectFailure( ExpectFailure.SimpleSubjectBuilderCallback assertionCallback) {