diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index 5b1eed4c6..cdf5f5c9e 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -9,11 +9,8 @@ on:
- master
jobs:
- test:
- name: "JDK ${{ matrix.java }}"
- strategy:
- matrix:
- java: [ 8, 11 ]
+ build:
+ name: 'Build with JDK 11'
runs-on: ubuntu-latest
steps:
# Cancel any previous runs for the same branch that are still running.
@@ -23,25 +20,54 @@ jobs:
access_token: ${{ github.token }}
- name: 'Check out repository'
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8
- - name: 'Set up JDK ${{ matrix.java }}'
+ - name: 'Set up JDK 11 for compilation'
uses: actions/setup-java@dded0888837ed1f317902acf8a20df0ad188d165
with:
- java-version: ${{ matrix.java }}
+ java-version: 11
distribution: 'zulu'
cache: 'maven'
- name: 'Install'
shell: bash
run: mvn -B -P!standard-with-extra-repos install -U -DskipTests=true
- - name: 'Test'
- shell: bash
- run: mvn -B -P!standard-with-extra-repos verify -U -Dmaven.javadoc.skip=true
- name: 'Javadoc Test Run'
shell: bash
run: mvn -B -P!standard-with-extra-repos javadoc:aggregate -U
+ - name: 'Upload build artifacts'
+ uses: actions/upload-artifact@v3
+ with:
+ name: truth-jars
+ path: |
+ **/target/*.jar
+ !**/target/*-sources.jar
+ !**/target/*-javadoc.jar
+
+ test:
+ name: "Test with JDK ${{ matrix.java }}"
+ needs: build
+ strategy:
+ matrix:
+ java: [ 8, 11, 17 ]
+ runs-on: ubuntu-latest
+ steps:
+ - name: 'Check out repository'
+ uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8
+ - name: 'Set up JDK ${{ matrix.java }} for testing'
+ uses: actions/setup-java@dded0888837ed1f317902acf8a20df0ad188d165
+ with:
+ java-version: ${{ matrix.java }}
+ distribution: 'zulu'
+ cache: 'maven'
+ - name: 'Download build artifacts'
+ uses: actions/download-artifact@v3
+ with:
+ name: truth-jars
+ - name: 'Test'
+ shell: bash
+ run: mvn -B -P!standard-with-extra-repos verify -U -Dmaven.javadoc.skip=true
publish_snapshot:
name: 'Publish snapshot'
- needs: test
+ needs: [build, test]
if: github.event_name == 'push' && github.repository == 'google/truth'
runs-on: ubuntu-latest
steps:
@@ -66,7 +92,7 @@ jobs:
permissions:
contents: write
name: 'Generate latest docs'
- needs: test
+ needs: [build, test]
if: github.event_name == 'push' && github.repository == 'google/truth'
runs-on: ubuntu-latest
steps:
diff --git a/core/pom.xml b/core/pom.xml
index 32fe3ef88..1bdd43c0d 100644
--- a/core/pom.xml
+++ b/core/pom.xml
@@ -5,7 +5,7 @@
This is an internal API and should not be used by client code. + * This class may be removed or changed at any time without notice. + */ +public final class LiteProtoSubjectAccess { + + /** + * Accessor interface for LiteProtoSubject internal methods. + * Set by LiteProtoSubject during class initialization. + */ + public interface Accessor { + String getCustomStringRepresentation(LiteProtoSubject subject); + } + + private static Accessor accessor; + + /** + * Sets the accessor. This is called by LiteProtoSubject during class initialization. + * + * @param accessor the accessor implementation + * @throws IllegalStateException if the accessor is already set + */ + public static void setAccessor(Accessor accessor) { + if (LiteProtoSubjectAccess.accessor != null) { + throw new IllegalStateException("Accessor already set"); + } + LiteProtoSubjectAccess.accessor = accessor; + } + + /** + * Gets the custom string representation for the given LiteProtoSubject. + * + * @param subject the LiteProtoSubject instance + * @return the custom string representation + * @throws IllegalStateException if no accessor has been set + */ + public static String getCustomStringRepresentation(LiteProtoSubject subject) { + if (accessor == null) { + throw new IllegalStateException("No accessor set"); + } + return accessor.getCustomStringRepresentation(subject); + } + + private LiteProtoSubjectAccess() {} +} \ No newline at end of file diff --git a/extensions/liteproto/src/main/java/com/google/common/truth/extensions/liteproto/package-info.java b/extensions/liteproto/src/main/java/com/google/common/truth/extensions/liteproto/package-info.java new file mode 100644 index 000000000..95805545b --- /dev/null +++ b/extensions/liteproto/src/main/java/com/google/common/truth/extensions/liteproto/package-info.java @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2016 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. + */ + +/** + * Custom subjects for testing Protocol + * Buffer Lite instances. + * + *
This package provides Truth extensions specifically for protobuf-lite, which is a + * lighter-weight version of Protocol Buffers with reduced functionality but smaller + * binary size and better performance for resource-constrained environments. + * + *
This package is a part of the open-source Truth
+ * project.
+ */
+@CheckReturnValue
+package com.google.common.truth.extensions.liteproto;
+
+import com.google.errorprone.annotations.CheckReturnValue;
\ No newline at end of file
diff --git a/extensions/liteproto/src/main/java/module-info.java b/extensions/liteproto/src/main/java/module-info.java
new file mode 100644
index 000000000..9bb27b891
--- /dev/null
+++ b/extensions/liteproto/src/main/java/module-info.java
@@ -0,0 +1,30 @@
+/*
+ * Copyright (c) 2025 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.
+ */
+
+module com.google.truth.extensions.liteproto {
+ requires com.google.truth;
+ requires com.google.common;
+ requires java.compiler;
+
+ requires static org.jspecify;
+ requires static com.google.errorprone.annotations;
+ requires static protobuf.lite;
+ requires static auto.value.annotations;
+ requires static com.google.j2objc.annotations;
+
+ exports com.google.common.truth.extensions.liteproto;
+ exports com.google.common.truth.extensions.liteproto.internal to com.google.truth.extensions.proto;
+}
\ No newline at end of file
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/liteproto/test/LiteProtoSubjectTest.java
similarity index 93%
rename from extensions/liteproto/src/test/java/com/google/common/truth/extensions/proto/LiteProtoSubjectTest.java
rename to extensions/liteproto/src/test/java/com/google/common/truth/extensions/liteproto/test/LiteProtoSubjectTest.java
index 205867d67..1f7dc1a8a 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/liteproto/test/LiteProtoSubjectTest.java
@@ -13,19 +13,25 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package com.google.common.truth.extensions.proto;
+package com.google.common.truth.extensions.liteproto.test;
import static com.google.common.truth.ExpectFailure.assertThat;
import static com.google.common.truth.ExpectFailure.expectFailureAbout;
-import static com.google.common.truth.extensions.proto.LiteProtoTruth.assertThat;
-import static com.google.common.truth.extensions.proto.LiteProtoTruth.liteProtos;
+import static com.google.common.truth.extensions.liteproto.LiteProtoTruth.assertThat;
+import static com.google.common.truth.extensions.liteproto.LiteProtoTruth.liteProtos;
import com.google.auto.value.AutoValue;
+import com.google.common.truth.extensions.liteproto.test.proto.OtherTestMessageLite2;
+import com.google.common.truth.extensions.liteproto.test.proto.OtherTestMessageLite3;
+import com.google.common.truth.extensions.liteproto.test.proto.TestMessageLite2;
+import com.google.common.truth.extensions.liteproto.test.proto.TestMessageLite2WithRequiredFields;
+import com.google.common.truth.extensions.liteproto.test.proto.TestMessageLite3;
import com.google.common.base.Optional;
import com.google.common.collect.ImmutableList;
import com.google.common.truth.Expect;
import com.google.common.truth.ExpectFailure.SimpleSubjectBuilderCallback;
import com.google.common.truth.Subject;
+import com.google.common.truth.extensions.liteproto.LiteProtoSubject;
import com.google.protobuf.MessageLite;
import java.util.Arrays;
import java.util.Collection;
@@ -134,7 +140,7 @@ public LiteProtoSubjectTest(@SuppressWarnings("unused") String name, Config conf
}
private LiteProtoSubject expectThat(@Nullable MessageLite m) {
- return expect.about(LiteProtoTruth.liteProtos()).that(m);
+ return expect.about(liteProtos()).that(m);
}
private Subject expectThat(@Nullable Object o) {
diff --git a/extensions/pom.xml b/extensions/pom.xml
index a3af92922..f5549cf66 100644
--- a/extensions/pom.xml
+++ b/extensions/pom.xml
@@ -7,7 +7,7 @@
This package provides Truth extensions for full Protocol Buffers (protobuf-java), which + * includes advanced features like reflection, text format, and comprehensive message manipulation. + * For lighter-weight protobuf-lite support, see + * {@link com.google.common.truth.extensions.liteproto}. * *
This package is a part of the open-source Truth
* project.
@@ -24,4 +29,4 @@
@CheckReturnValue
package com.google.common.truth.extensions.proto;
-import com.google.errorprone.annotations.CheckReturnValue;
+import com.google.errorprone.annotations.CheckReturnValue;
\ No newline at end of file
diff --git a/extensions/proto/src/main/java/module-info.java b/extensions/proto/src/main/java/module-info.java
new file mode 100644
index 000000000..7581473ef
--- /dev/null
+++ b/extensions/proto/src/main/java/module-info.java
@@ -0,0 +1,29 @@
+/*
+ * Copyright (c) 2025 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.
+ */
+
+module com.google.truth.extensions.proto {
+ requires com.google.truth;
+ requires com.google.truth.extensions.liteproto;
+ requires com.google.common;
+ requires com.google.protobuf;
+ requires java.compiler;
+
+ requires static org.jspecify;
+ requires static com.google.errorprone.annotations;
+ requires static auto.value.annotations;
+
+ exports com.google.common.truth.extensions.proto;
+}
\ No newline at end of file
diff --git a/extensions/proto/src/test/java/com/google/common/truth/extensions/proto/FieldScopesTest.java b/extensions/proto/src/test/java/com/google/common/truth/extensions/proto/test/FieldScopesTest.java
similarity index 99%
rename from extensions/proto/src/test/java/com/google/common/truth/extensions/proto/FieldScopesTest.java
rename to extensions/proto/src/test/java/com/google/common/truth/extensions/proto/test/FieldScopesTest.java
index 077d647f2..8df762678 100644
--- a/extensions/proto/src/test/java/com/google/common/truth/extensions/proto/FieldScopesTest.java
+++ b/extensions/proto/src/test/java/com/google/common/truth/extensions/proto/test/FieldScopesTest.java
@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package com.google.common.truth.extensions.proto;
+package com.google.common.truth.extensions.proto.test;
import static com.google.common.truth.extensions.proto.ProtoTruth.assertThat;
import static java.nio.charset.StandardCharsets.UTF_8;
@@ -23,6 +23,8 @@
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableMultimap;
+import com.google.common.truth.extensions.proto.FieldScope;
+import com.google.common.truth.extensions.proto.FieldScopes;
import com.google.protobuf.ByteString;
import com.google.protobuf.Descriptors.FieldDescriptor;
import com.google.protobuf.InvalidProtocolBufferException;
diff --git a/extensions/proto/src/test/java/com/google/common/truth/extensions/proto/IterableOfProtosSubjectTest.java b/extensions/proto/src/test/java/com/google/common/truth/extensions/proto/test/IterableOfProtosSubjectTest.java
similarity index 99%
rename from extensions/proto/src/test/java/com/google/common/truth/extensions/proto/IterableOfProtosSubjectTest.java
rename to extensions/proto/src/test/java/com/google/common/truth/extensions/proto/test/IterableOfProtosSubjectTest.java
index 9d2b52edb..475c27d59 100644
--- a/extensions/proto/src/test/java/com/google/common/truth/extensions/proto/IterableOfProtosSubjectTest.java
+++ b/extensions/proto/src/test/java/com/google/common/truth/extensions/proto/test/IterableOfProtosSubjectTest.java
@@ -14,12 +14,14 @@
* limitations under the License.
*/
-package com.google.common.truth.extensions.proto;
+package com.google.common.truth.extensions.proto.test;
import static java.util.Comparator.comparing;
import com.google.common.base.Function;
import com.google.common.collect.ImmutableList;
+import com.google.common.truth.extensions.proto.FieldScopes;
+import com.google.common.truth.extensions.proto.IterableOfProtosSubject;
import com.google.protobuf.Message;
import java.util.Collection;
import java.util.Comparator;
diff --git a/extensions/proto/src/test/java/com/google/common/truth/extensions/proto/MapWithProtoValuesSubjectTest.java b/extensions/proto/src/test/java/com/google/common/truth/extensions/proto/test/MapWithProtoValuesSubjectTest.java
similarity index 97%
rename from extensions/proto/src/test/java/com/google/common/truth/extensions/proto/MapWithProtoValuesSubjectTest.java
rename to extensions/proto/src/test/java/com/google/common/truth/extensions/proto/test/MapWithProtoValuesSubjectTest.java
index 1bdf2f34d..807d7840c 100644
--- a/extensions/proto/src/test/java/com/google/common/truth/extensions/proto/MapWithProtoValuesSubjectTest.java
+++ b/extensions/proto/src/test/java/com/google/common/truth/extensions/proto/test/MapWithProtoValuesSubjectTest.java
@@ -14,10 +14,12 @@
* limitations under the License.
*/
-package com.google.common.truth.extensions.proto;
+package com.google.common.truth.extensions.proto.test;
import com.google.common.collect.ImmutableMap;
import com.google.common.truth.MapSubject;
+import com.google.common.truth.extensions.proto.MapWithProtoValuesFluentAssertion;
+import com.google.common.truth.extensions.proto.MapWithProtoValuesSubject;
import com.google.protobuf.Message;
import java.util.Collection;
import org.junit.Test;
diff --git a/extensions/proto/src/test/java/com/google/common/truth/extensions/proto/MultiExpectFailure.java b/extensions/proto/src/test/java/com/google/common/truth/extensions/proto/test/MultiExpectFailure.java
similarity index 97%
rename from extensions/proto/src/test/java/com/google/common/truth/extensions/proto/MultiExpectFailure.java
rename to extensions/proto/src/test/java/com/google/common/truth/extensions/proto/test/MultiExpectFailure.java
index d1ae1dd5c..a8ad20f87 100644
--- a/extensions/proto/src/test/java/com/google/common/truth/extensions/proto/MultiExpectFailure.java
+++ b/extensions/proto/src/test/java/com/google/common/truth/extensions/proto/test/MultiExpectFailure.java
@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package com.google.common.truth.extensions.proto;
+package com.google.common.truth.extensions.proto.test;
import com.google.common.base.Preconditions;
import com.google.common.truth.ExpectFailure;
diff --git a/extensions/proto/src/test/java/com/google/common/truth/extensions/proto/MultimapWithProtoValuesSubjectTest.java b/extensions/proto/src/test/java/com/google/common/truth/extensions/proto/test/MultimapWithProtoValuesSubjectTest.java
similarity index 98%
rename from extensions/proto/src/test/java/com/google/common/truth/extensions/proto/MultimapWithProtoValuesSubjectTest.java
rename to extensions/proto/src/test/java/com/google/common/truth/extensions/proto/test/MultimapWithProtoValuesSubjectTest.java
index f7570fdc6..0e74692c8 100644
--- a/extensions/proto/src/test/java/com/google/common/truth/extensions/proto/MultimapWithProtoValuesSubjectTest.java
+++ b/extensions/proto/src/test/java/com/google/common/truth/extensions/proto/test/MultimapWithProtoValuesSubjectTest.java
@@ -14,11 +14,13 @@
* limitations under the License.
*/
-package com.google.common.truth.extensions.proto;
+package com.google.common.truth.extensions.proto.test;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableMultimap;
import com.google.common.truth.MultimapSubject;
+import com.google.common.truth.extensions.proto.MultimapWithProtoValuesFluentAssertion;
+import com.google.common.truth.extensions.proto.MultimapWithProtoValuesSubject;
import com.google.protobuf.Message;
import java.util.Collection;
import org.junit.Test;
diff --git a/extensions/proto/src/test/java/com/google/common/truth/extensions/proto/OverloadResolutionTest.java b/extensions/proto/src/test/java/com/google/common/truth/extensions/proto/test/OverloadResolutionTest.java
similarity index 99%
rename from extensions/proto/src/test/java/com/google/common/truth/extensions/proto/OverloadResolutionTest.java
rename to extensions/proto/src/test/java/com/google/common/truth/extensions/proto/test/OverloadResolutionTest.java
index adc4ee5ae..518d2994d 100644
--- a/extensions/proto/src/test/java/com/google/common/truth/extensions/proto/OverloadResolutionTest.java
+++ b/extensions/proto/src/test/java/com/google/common/truth/extensions/proto/test/OverloadResolutionTest.java
@@ -14,7 +14,7 @@
* limitations under the License.
*/
-package com.google.common.truth.extensions.proto;
+package com.google.common.truth.extensions.proto.test;
import static com.google.common.truth.Truth.assertAbout;
import static com.google.common.truth.Truth.assertThat;
diff --git a/extensions/proto/src/test/java/com/google/common/truth/extensions/proto/ProtoSubjectTest.java b/extensions/proto/src/test/java/com/google/common/truth/extensions/proto/test/ProtoSubjectTest.java
similarity index 99%
rename from extensions/proto/src/test/java/com/google/common/truth/extensions/proto/ProtoSubjectTest.java
rename to extensions/proto/src/test/java/com/google/common/truth/extensions/proto/test/ProtoSubjectTest.java
index b9f8ffcbe..a502f68e1 100644
--- a/extensions/proto/src/test/java/com/google/common/truth/extensions/proto/ProtoSubjectTest.java
+++ b/extensions/proto/src/test/java/com/google/common/truth/extensions/proto/test/ProtoSubjectTest.java
@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package com.google.common.truth.extensions.proto;
+package com.google.common.truth.extensions.proto.test;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.truth.Truth.assertThat;
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/test/ProtoSubjectTestBase.java
similarity index 95%
rename from extensions/proto/src/test/java/com/google/common/truth/extensions/proto/ProtoSubjectTestBase.java
rename to extensions/proto/src/test/java/com/google/common/truth/extensions/proto/test/ProtoSubjectTestBase.java
index e686a4f4a..023119308 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/test/ProtoSubjectTestBase.java
@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package com.google.common.truth.extensions.proto;
+package com.google.common.truth.extensions.proto.test;
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.truth.Truth.assertThat;
@@ -32,6 +32,12 @@
import com.google.common.truth.ExpectFailure;
import com.google.common.truth.Subject;
import com.google.common.truth.TruthFailureSubject;
+import com.google.common.truth.extensions.proto.IterableOfProtosSubject;
+import com.google.common.truth.extensions.proto.MapWithProtoValuesSubject;
+import com.google.common.truth.extensions.proto.MultimapWithProtoValuesSubject;
+import com.google.common.truth.extensions.proto.ProtoSubject;
+import com.google.common.truth.extensions.proto.ProtoSubjectBuilder;
+import com.google.common.truth.extensions.proto.ProtoTruth;
import com.google.protobuf.Descriptors.FieldDescriptor;
import com.google.protobuf.ExtensionRegistry;
import com.google.protobuf.InvalidProtocolBufferException;
diff --git a/extensions/re2j/pom.xml b/extensions/re2j/pom.xml
index 6ca4180ce..0a9b83970 100644
--- a/extensions/re2j/pom.xml
+++ b/extensions/re2j/pom.xml
@@ -7,7 +7,7 @@