Skip to content

Commit

Permalink
Move truth-java8-extension classes into the main truth artifact.
Browse files Browse the repository at this point in the history
While there, make some minor changes to prepare for moving the `Truth8` methods into `Truth`.

This is the first step of #746.

RELNOTES=Moved the `truth-java8-extension` classes into the main `truth` artifact. There is no longer any need to depend on `truth-java8-extension`, which is now empty. (We've also removed the `Truth8` [GWT](https://www.gwtproject.org/) module.)
PiperOrigin-RevId: 597243015
  • Loading branch information
cpovirk authored and Google Java Core Libraries committed Jan 10, 2024
1 parent e47ee27 commit eb0426e
Show file tree
Hide file tree
Showing 16 changed files with 80 additions and 47 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* Copyright (c) 2019 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 java.lang.annotation.ElementType.CONSTRUCTOR;
import static java.lang.annotation.ElementType.METHOD;
import static java.lang.annotation.ElementType.TYPE;

import java.lang.annotation.Target;

/**
* Disables Animal Sniffer's checking of compatibility with older versions of Java/Android.
*/
@Target({METHOD, CONSTRUCTOR, TYPE})
@interface IgnoreJRERequirement {}
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,16 @@
*
* @author Kurt Alfred Kluever
*/
@SuppressWarnings("deprecation") // TODO(b/134064106): design an alternative to no-arg check()
@SuppressWarnings({
"deprecation", // TODO(b/134064106): design an alternative to no-arg check()
"Java7ApiChecker", // used only from APIs with Java 8 in their signatures
})
@IgnoreJRERequirement
public final class IntStreamSubject extends Subject {

private final List<?> actualList;

private IntStreamSubject(FailureMetadata failureMetadata, @Nullable IntStream stream) {
IntStreamSubject(FailureMetadata failureMetadata, @Nullable IntStream stream) {
super(failureMetadata, stream);
this.actualList =
(stream == null) ? null : stream.boxed().collect(toCollection(ArrayList::new));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,16 @@
*
* @author Kurt Alfred Kluever
*/
@SuppressWarnings("deprecation") // TODO(b/134064106): design an alternative to no-arg check()
@SuppressWarnings({
"deprecation", // TODO(b/134064106): design an alternative to no-arg check()
"Java7ApiChecker", // used only from APIs with Java 8 in their signatures
})
@IgnoreJRERequirement
public final class LongStreamSubject extends Subject {

private final List<?> actualList;

private LongStreamSubject(FailureMetadata failureMetadata, @Nullable LongStream stream) {
LongStreamSubject(FailureMetadata failureMetadata, @Nullable LongStream stream) {
super(failureMetadata, stream);
this.actualList =
(stream == null) ? null : stream.boxed().collect(toCollection(ArrayList::new));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
*
* @author Ben Douglass
*/
@SuppressWarnings("Java7ApiChecker") // used only from APIs with Java 8 in their signatures
@IgnoreJRERequirement
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,6 +26,8 @@
*
* @author Ben Douglass
*/
@SuppressWarnings("Java7ApiChecker") // used only from APIs with Java 8 in their signatures
@IgnoreJRERequirement
public final class OptionalIntSubject extends Subject {
private final OptionalInt actual;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
*
* @author Ben Douglass
*/
@SuppressWarnings("Java7ApiChecker") // used only from APIs with Java 8 in their signatures
@IgnoreJRERequirement
public final class OptionalLongSubject extends Subject {
private final OptionalLong actual;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
*
* @author Christian Gruber
*/
@SuppressWarnings("Java7ApiChecker") // used only from APIs with Java 8 in their signatures
@IgnoreJRERequirement
public final class OptionalSubject extends Subject {
private final @Nullable Optional<?> actual;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@
/** Assertions for {@link Path} instances. */
@GwtIncompatible
@J2ObjCIncompatible
@J2ktIncompatible
public final class PathSubject extends Subject {
private PathSubject(FailureMetadata failureMetadata, Path actual) {
PathSubject(FailureMetadata failureMetadata, Path actual) {
super(failureMetadata, actual);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import static com.google.common.base.Preconditions.checkNotNull;

import com.google.common.annotations.GwtIncompatible;
import com.google.common.base.Optional;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Multimap;
import com.google.common.collect.Multiset;
Expand Down Expand Up @@ -149,7 +148,7 @@ public final PrimitiveDoubleArraySubject that(double @Nullable [] actual) {
return new PrimitiveDoubleArraySubject(metadata(), actual, "array");
}

public final GuavaOptionalSubject that(@Nullable Optional<?> actual) {
public final GuavaOptionalSubject that(com.google.common.base.@Nullable Optional<?> actual) {
return new GuavaOptionalSubject(metadata(), actual, "optional");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,16 @@
*
* @author Kurt Alfred Kluever
*/
@SuppressWarnings("deprecation") // TODO(b/134064106): design an alternative to no-arg check()
@SuppressWarnings({
"deprecation", // TODO(b/134064106): design an alternative to no-arg check()
"Java7ApiChecker", // used only from APIs with Java 8 in their signatures
})
@IgnoreJRERequirement
public final class StreamSubject extends Subject {

private final List<?> actualList;

private StreamSubject(FailureMetadata failureMetadata, @Nullable Stream<?> stream) {
StreamSubject(FailureMetadata failureMetadata, @Nullable Stream<?> stream) {
super(failureMetadata, stream);
this.actualList = (stream == null) ? null : stream.collect(toCollection(ArrayList::new));
}
Expand Down
4 changes: 2 additions & 2 deletions core/src/main/java/com/google/common/truth/Truth.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import static com.google.common.base.Preconditions.checkNotNull;

import com.google.common.annotations.GwtIncompatible;
import com.google.common.base.Optional;
import com.google.common.collect.Multimap;
import com.google.common.collect.Multiset;
import com.google.common.collect.Table;
Expand Down Expand Up @@ -229,7 +228,8 @@ public static PrimitiveDoubleArraySubject assertThat(double @Nullable [] actual)
return assert_().that(actual);
}

public static GuavaOptionalSubject assertThat(@Nullable Optional<?> actual) {
public static GuavaOptionalSubject assertThat(
com.google.common.base.@Nullable Optional<?> actual) {
return assert_().that(actual);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@
* <a href="https://truth.dev/faq#full-chain">How do I specify a custom message/failure
* behavior/{@code Subject} type?</a> in the Truth FAQ.
*/
// The methods here are no more dangerous that wherever the user got the (e.g.) Stream.
@SuppressWarnings("Java7ApiChecker")
public final class Truth8 {
@SuppressWarnings("AssertAboutOptionals") // suggests infinite recursion
public static OptionalSubject assertThat(@Nullable Optional<?> target) {
Expand Down Expand Up @@ -79,6 +81,7 @@ public static LongStreamSubject assertThat(@Nullable LongStream target) {
// to support Java environments without java.nio.file such as Android and J2CL.
@GwtIncompatible
@J2ObjCIncompatible
@J2ktIncompatible
public static PathSubject assertThat(@Nullable Path target) {
return assertAbout(PathSubject.paths()).that(target);
}
Expand Down
16 changes: 16 additions & 0 deletions core/src/test/java/com/google/common/truth/gwt/Inventory.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,19 @@
import com.google.common.truth.FailureStrategy;
import com.google.common.truth.FloatSubject;
import com.google.common.truth.GuavaOptionalSubject;
import com.google.common.truth.IntStreamSubject;
import com.google.common.truth.IntegerSubject;
import com.google.common.truth.IterableSubject;
import com.google.common.truth.LongStreamSubject;
import com.google.common.truth.LongSubject;
import com.google.common.truth.MapSubject;
import com.google.common.truth.MultimapSubject;
import com.google.common.truth.MultisetSubject;
import com.google.common.truth.ObjectArraySubject;
import com.google.common.truth.OptionalDoubleSubject;
import com.google.common.truth.OptionalIntSubject;
import com.google.common.truth.OptionalLongSubject;
import com.google.common.truth.OptionalSubject;
import com.google.common.truth.Ordered;
import com.google.common.truth.PrimitiveBooleanArraySubject;
import com.google.common.truth.PrimitiveByteArraySubject;
Expand All @@ -39,11 +45,13 @@
import com.google.common.truth.PrimitiveIntArraySubject;
import com.google.common.truth.PrimitiveLongArraySubject;
import com.google.common.truth.PrimitiveShortArraySubject;
import com.google.common.truth.StreamSubject;
import com.google.common.truth.StringSubject;
import com.google.common.truth.Subject;
import com.google.common.truth.TableSubject;
import com.google.common.truth.ThrowableSubject;
import com.google.common.truth.Truth;
import com.google.common.truth.Truth8;
import com.google.common.truth.TruthJUnit;

/**
Expand All @@ -59,12 +67,18 @@ public class Inventory {
FloatSubject floatSubject;
GuavaOptionalSubject guavaOptionalSubject;
IntegerSubject integerSubject;
IntStreamSubject intStreamSubject;
IterableSubject iterableSubject;
LongSubject longSubject;
LongStreamSubject longStreamSubject;
MapSubject mapSubject;
MultimapSubject multimapSubject;
MultisetSubject multisetSubject;
ObjectArraySubject<?> objectArraySubject;
OptionalSubject optionalSubject;
OptionalDoubleSubject optionalDoubleSubject;
OptionalIntSubject optionalIntSubject;
OptionalLongSubject optionalLongSubject;
Ordered ordered;
PrimitiveBooleanArraySubject primitiveBooleanArraySubject;
PrimitiveByteArraySubject primitiveByteArraySubject;
Expand All @@ -74,11 +88,13 @@ public class Inventory {
PrimitiveIntArraySubject primitiveIntArraySubject;
PrimitiveLongArraySubject primitiveLongArraySubject;
PrimitiveShortArraySubject primitiveShortArraySubject;
StreamSubject streamSubject;
StringSubject stringSubject;
Subject.Factory<?, ?> subjectFactory;
Subject subject;
TableSubject tableSubject;
ThrowableSubject throwableSubject;
Truth truth;
Truth8 truth8;
TruthJUnit truthJUnit;
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,5 @@
<inherits name="com.google.common.collect.Collect"/>
<inherits name="com.google.common.primitives.Primitives"/>
<inherits name="com.google.common.truth.Truth"/>
<!-- TODO(cpovirk): Test Truth8. -->
<inherits name="com.google.gwt.junit.JUnit"/>
</module>

This file was deleted.

1 change: 1 addition & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,7 @@
<artifactId>animal-sniffer-maven-plugin</artifactId>
<version>1.23</version>
<configuration>
<annotations>com.google.common.truth.IgnoreJRERequirement</annotations>
<signature>
<groupId>com.toasttab.android</groupId>
<artifactId>gummy-bears-api-19</artifactId>
Expand Down

0 comments on commit eb0426e

Please sign in to comment.