30 Commits
Author SHA1 Message Date
cpovirk bb8fb34bf9 Replace calls to Runnables.doNothing() with a do-nothing lambda, () -> {}.
`Runnables.doNothing()` exists only because Java lambdas didn't exist in 2013. `() -> {}` is shorter and more standard.

PiperOrigin-RevId: 972641734
2026-08-28 09:49:46 -07:00
cpovirk 621416a240 Modernize cancellation configuration.
https://github.com/google/guice/commit/35173790910fd604e01c763df2ce9c4ae33e5198 probably used the best tools available in 2022. But this PR's approach, which we've been using with success [in Guava](https://github.com/google/guava/blob/0adf237b742d899d00239dfeefdd42807ff46a83/.github/workflows/ci.yml#L14-L17) and in other projects, looks to be [the recommended approach](https://docs.github.com/en/actions/reference/workflows-and-actions/workflow-syntax#example-using-a-fallback-value) nowadays.

In particular, I wonder if the current setup is over-canceling: Currently, I see reports like ["Canceling since a higher priority waiting request for ci-main-b7c7483a46afadd43a2f04935aaee5ff0cd09145 exists"](https://github.com/google/guice/actions/runs/30832661591/job/91750157428) on a large number of jobs, causing GitHub to report the overall CI status as "failure."

RELNOTES=n/a
PiperOrigin-RevId: 958535716
2026-08-03 13:07:48 -07:00
cpovirk b7c7483a46 Bump JSpecify to 1.0.1.
RELNOTES=n/a
PiperOrigin-RevId: 958418513
2026-08-03 09:32:49 -07:00
cpovirk 676edd7a6e Address zizmor findings:
- [`persist-credentials: false`](https://docs.zizmor.sh/audits/#artipacked)
- [excessive permissions](https://docs.zizmor.sh/audits/#excessive-permissions)

There may be other findings, but these are the easy ones.

RELNOTES=n/a
PiperOrigin-RevId: 958407678
2026-08-03 09:08:35 -07:00
cpovirk 174317a08a [Migrate](https://bazel.build/external/migration) to Bazel's ["new" module system](https://bazel.build/external/overview).
My immediate win is that this includes migrating off the old version of bazel-common that includes `google_common_workspace_rules()`: Calling `google_common_workspace_rules()` leads to trouble under macos-latest (as previously in https://github.com/google/guice/commit/17011080a118fc2d23314ccf0d5546ce53e8b650):

```
  ERROR: /Users/runner/work/guice/guice/WORKSPACE:26:30: fetching android_sdk_repository rule //external:androidsdk: Android SDK api level 34 was requested but it is not installed in the Android SDK at /Users/runner/Library/Android/sdk. The api levels found were [36, 35]. Please choose an available api level or install api level 34 from the Android SDK Manager.
  ERROR: Analysis of target '//tools:osgi_wrapper' failed; build aborted: Android SDK api level 34 was requested but it is not installed in the Android SDK at /Users/runner/Library/Android/sdk. The api levels found were [36, 35]. Please choose an available api level or install api level 34 from the Android SDK Manager.
```

RELNOTES=n/a
PiperOrigin-RevId: 957370304
2026-07-31 15:50:31 -07:00
cpovirk 2a1d0fb47c Prepare for changes in how Truth prints class names.
Truth will soon:
- print only the simple name for some well-known classes (e.g., print "NullPointerException" instead of "java.lang.NullPointerException")
- print the canonical name where available instead of the binary name (e.g., print "com.google.Foo.BarException" instead of "com.google.Foo$BarException"

This CL updates callers to accept both versions.

RELNOTES=n/a
PiperOrigin-RevId: 775721999
2025-06-25 09:29:31 -07:00
cpovirk cdf076c99e Annotate toProvider(..) methods to specify that providers can return null.
This doesn't change any Guice behavior; it just lets nullness checkers (like Kotlin and the Checker Framework) allow you to bind to such providers more easily.

Guice's handling of `null` is not entirely principled, and this CL doesn't attempt to "solve" that, nor does it attempt to thoroughly annotate for nullness, let alone enable a nullness checker for the Guice codebase. Rather, it aims only to remove a restriction that I don't think is serving any particular purpose and that no on "intended"; I think it just kind of happened because the Checker Framework treats unannotated code leniently and strictly at different times, and this happens to be one of the strict cases. (We might also have once had the hope of cracking down on injection of `null`?)

The immediate motivation for this CL is https://github.com/google/inject-common/pull/26: Soon, nullness checkers will know that `Providers.of(null)` returns *gasp* a `Provider` that can return `null`. That makes `bind(Foo.class).to(Providers.of(null))` an error. This CL lets those callers continue to compile.

PiperOrigin-RevId: 734755975
2025-03-07 19:00:18 -08:00
cpovirk 018f28f701 Remove empty plugins lists.
RELNOTES=n/a
PiperOrigin-RevId: 617628676
2024-03-20 14:38:32 -07:00
cpovirk 1ddec22017 Migrate usages of Truth8.assertThat to equivalent usages of Truth.assertThat.
The `Truth8` methods will be deprecated (or hidden) in the future. Callers should move to `Truth`.

Some (but not all) of the CLs in this batch require Truth [1.4.0](https://github.com/google/truth/releases/tag/v1.4.0). I submitted a CL earlier today to (I hope) perform that upgrade for your project.

PiperOrigin-RevId: 604731456
2024-02-06 12:36:36 -08:00
cpovirk a7c5944a67 Update to [Truth 1.4.0](https://github.com/google/truth/releases/tag/v1.4.0).
This makes available the rest of the Truth APIs that were recently added in Google's monorepo.

It may be worth also updating to the _following_ version of Truth after it's released, but the purpose of that release will mostly be to deprecate `Truth8`. So, if you just avoid using `Truth8` now (starting by approving any migration CLs that I send your way), then there will be little need for that upgrade. Or, more to the point: I don't expect to keep sending you weekly upgrade CLs after this one :)

PiperOrigin-RevId: 604719853
2024-02-06 11:57:23 -08:00
cpovirk 4f94f0031b Migrate most usages of Truth8.assertThat to equivalent usages of Truth.assertThat, and qualify others.
By "qualify," I mean that, instead of static importing `Truth8.assertThat`, we write "`Truth8.assertThat(...)`" at the call site.

This is normally the opposite of what we recommend. However, it's a necessary step in our migration: We are copying all the `Truth8` methods to `Truth`, and we can't do that if any files static import both `Truth.assertThat` and `Truth8.assertThat` (because it produces a compile error about ambiguous overloads). To unblock that, we're moving callers away from the static import.

We will update static analysis to stop suggesting the import.

A later step will migrate these callers to the new `Truth.assertThat` methods, which we will static import.

The `Truth8` methods will be hidden in the future. All callers will use `Truth`.

PiperOrigin-RevId: 603073706
2024-01-31 09:33:09 -08:00
cpovirk 5a4e23a1b9 Update bazel-common to pick up Guava 33.0.0 and Truth to 1.3.0.
New commit: https://github.com/google/bazel-common/commit/2a6b6406e12208e02b2060df0631fb30919080f3

This helps with https://github.com/google/truth/issues/746.

PiperOrigin-RevId: 602832261
2024-01-30 13:56:21 -08:00
cpovirk 25d7233fe3 Apply @CheckReturnValue to the rest of com.google.inject.util.Modules.OverriddenModuleBuilder.
PiperOrigin-RevId: 429668967
2022-02-18 16:13:22 -08:00
cpovirk 9a998363f7 Add @CheckReturnValue to com.google.inject.util.Modules.OverriddenModuleBuilder#with(com.google.inject.Module[]).
PiperOrigin-RevId: 429343356
2022-02-17 10:30:22 -08:00
cpovirk 3fea884084 Add @CheckReturnValue to com.google.inject.util.Modules#override(com.google.inject.Module[]).
PiperOrigin-RevId: 429339743
2022-02-17 10:16:13 -08:00
cpovirk 1e8ede8007 Add @CheckReturnValue to com.google.inject.util.Modules#combine(com.google.inject.Module[]).
PiperOrigin-RevId: 429337151
2022-02-17 10:07:11 -08:00
cpovirk ed75b0b3c0 Add @CheckReturnValue to com.google.inject.util.Providers.
PiperOrigin-RevId: 429297357
2022-02-17 06:44:33 -08:00
cpovirk dc837e402c Copybara config for Guice.
RELNOTES=n/a

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=318305193
2020-06-29 11:03:49 -04:00
cpovirk 159e13370d Update to Truth 0.45, and address deprecations.
Renames may include:
- containsAllOf => containsAtLeast
- containsAllIn => containsAtLeastElementsIn
- isSameAs => isSameInstanceAs
- isOrdered => isInOrder
- isStrictlyOrdered => isInStrictOrder

The other major change is to change custom subjects to extend raw Subject instead of supplying type parameters. The type parameters are being removed from Subject. This CL will temporarily produce rawtypes warnings, which will go away when I remove the type parameters (as soon as this batch of CLs is submitted).

Some CLs in this batch also migrate calls away from actualAsString(). Its literal replacement is `"<" + actual + ">"` (unless an object overrides actualCustomStringRepresentation()), but usually I've made a larger change, such as switching from an old-style "Not true that..." failure message to one generated with the Fact API. In that case, the new code usually contains a direct reference to this.actual (a field that I occasionally had to create). Another larger change I sometimes made is to switch from a manual check-and-fail approach to instead use check(...). And sometimes I just remove a withMessage() call that's no longer necessary now that the code uses check(...), or I introduce a check(...) call. (An assertion made with check(...) automatically includes the actual value from the original subject, so there's no need to set it again with withMessage().)

Finally, there's one CL in this batch in which I migrate a Correspondence subclass to instead use Correspondence.from.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=251472122
2019-06-06 11:06:16 -04:00
cpovirk 553a475a2c Migrate Truth Subjects from no-arg check() to the overload that accepts a description.
The overload that accepts a description generally produces better failure messages:
- The first line of the message it produces is something like: "value of: myProto.getResponse()" (where "getResponse()" is taken from the provided description)
- The last line of the message it produces is something like: "myProto was: response: query was throttled" (the full value of myProto)
- And the existing text goes in between.

Additional motivation: We are deleting the no-arg overload externally (and probably internally thereafter).

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=247095743
2019-05-08 10:35:03 -04:00
cpovirk ea179b962f Instead of calling Subject.actual(), store the actual value in a field, and read that.
actual() is being removed.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=247039297
2019-05-08 10:35:03 -04:00
cpovirk a0552a16d8 Update to Truth 0.44.
-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=244875738
2019-04-29 11:34:54 -04:00
cpovirk 289073ec20 Update to Guava 25.1-android.
It's required by Truth 0.41, which we switched to in CL 200574789.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=202732649
2018-07-02 16:36:45 -04:00
cpovirk 12692cbe89 Update to Truth 0.41, and expect a single failure-message format instead of the current multiple possibilities.
Also, update the bundled-for-Ant JUnit from JUnit 3-something to JUnit 4.11. This matches the dependency used by the Maven build. It's necessary to avoid the problem "java.lang.ClassNotFoundException: org.junit.ComparisonFailure." Truth was already using that type as of 0.36[*], so I suspect that we were just getting away with the JUnit 3 dependency because of the vagaries of class loading. Presumably, if a test had ever actually failed in a way that should have produced a ComparisonFailure, the current build setup would have produces the same error.

[*] https://github.com/google/truth/blob/release_0_36/core/src/main/java/com/google/common/truth/Platform.java#L24

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=200574789
2018-07-02 16:36:45 -04:00
cpovirk 48b3f62aa1 Migrate off failWithRawMessageAndCause, which is being deprecated.
I'm sorry that the replacement is so ugly. Our reason for not supporting this directly is partially that it's needed by only ~1% of subjects. But mostly, we've over time taken the position that Truth is intended for only the "assert" phases of the "arrange, act, assert" testing process. Exceptions, on the other hand, usually come from the earlier phases.

Unfortunately, I still owe everyone a long explanation of *why* we have come to this position. If it's bugging you now, let me know, and I can make it happen.

(And yes, in this particular case, we're basically arguing that Your Subject Is Wrong. Sorry: I'm not trying to get you to delete it or recant or anything; I'm just trying to explain where we're coming from.)

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=192278109
2018-04-11 13:37:20 -04:00
cpovirk 44c65c164d Update tests for upcoming changes to Truth's failure message format.
We now accept (sigh) 3 versions:
- The version generated by the latest open-source release of Truth.
- The version generated by the current internal version of Truth.
- The version that will be generated once I submit CL 185043225.

I continue to promise to reduce this back to expecting a single version once I release a version of Truth that contains CL 185043225.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=190771332
2018-04-03 12:08:37 -04:00
cpovirk b56a8561a9 Update tests for when withMessage() messages are displayed on separate lines from the main failure message.
Before:
some messsage: the main message

After:
some message
the main message

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=189625749
2018-03-20 18:25:51 -04:00
cpovirk 66f1a16adb Update maven-javadoc-plugin to 3.0.0.
This is necessary to build with JDK9.
(You can still build *for* older versions of Java to maintain compatibility; this is just to work with build tools from JDK9, as will become the Google default.)

As part of that, migrate from additionalparam, which was deprecated and removed last year, to additionalOptions.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=182374950
2018-01-25 11:12:58 -05:00
cpovirk 50b2764654 Migrate from fail* calls on deprecated this.failureStrategy to equivalent this.fail* calls.
The new this.fail* methods are available in Truth 0.36, which I've imported into the [] Maven repository for people who use that. If I could find a pom/build.xml for your open-source project, this CL updates it.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=169571495
2018-01-25 11:12:58 -05:00
cpovirk 46e146db97 Fix tests that intend to check that an error is thrown but don't.
Tests of a testing API often look like this:

	try {
		runATestThatShouldFail();
		fail();
	} catch (AssertionError expected) {
	}

However, the catch() block can catch not only the expected failure from runATestThatShouldFail() but also the "test did not fail when it should have" failure from fail().
-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=118941782
2016-06-13 17:09:24 -04:00