Migrate Google Truth to AssertJ
org.openrewrite.java.testing.truth.MigrateTruthToAssertJ
Migrate Google Truth assertions to AssertJ assertions.
Tags
Recipe source
GitHub, Issue Tracker, Maven Central
This recipe is composed of more than one recipe. If you want to customize the set of recipes this is composed of, you can find and copy the GitHub source for the recipe from the link above.
This recipe is available under the Moderne Source Available License.
Definition
- Recipe List
- Yaml Recipe List
- Add Gradle or Maven dependency
- groupId:
org.assertj
- artifactId:
assertj-core
- version:
3.x
- onlyIfUsing:
com.google.common.truth.*
- acceptTransitive:
true
- groupId:
- Convert Truth
assert_()
to AssertJ - Convert Truth
assertWithMessage
to AssertJ - Convert Truth Throwable assertions to AssertJ
- Migrate Truth custom subjects to AssertJ
- Change method name
- methodPattern:
com.google.common.truth..* hasLength(int)
- newMethodName:
hasSize
- methodPattern:
- Change method name
- methodPattern:
com.google.common.truth.StringSubject containsMatch(..)
- newMethodName:
matches
- methodPattern:
- Change method name
- methodPattern:
com.google.common.truth.StringSubject doesNotContainMatch(..)
- newMethodName:
doesNotMatch
- methodPattern:
- Change type
- oldFullyQualifiedTypeName:
com.google.common.truth.StringSubject
- newFullyQualifiedTypeName:
org.assertj.core.api.AbstractStringAssert
- oldFullyQualifiedTypeName:
- Change method name
- methodPattern:
com.google.common.truth.ComparableSubject isAtLeast(..)
- newMethodName:
isGreaterThanOrEqualTo
- methodPattern:
- Change method name
- methodPattern:
com.google.common.truth.ComparableSubject isAtMost(..)
- newMethodName:
isLessThanOrEqualTo
- methodPattern:
- Change type
- oldFullyQualifiedTypeName:
com.google.common.truth.ComparableSubject
- newFullyQualifiedTypeName:
org.assertj.core.api.AbstractComparableAssert
- oldFullyQualifiedTypeName:
- Change method name
- methodPattern:
com.google.common.truth.Subject isSameInstanceAs(..)
- newMethodName:
isSameAs
- methodPattern:
- Change method name
- methodPattern:
com.google.common.truth.Subject isNotSameInstanceAs(..)
- newMethodName:
isNotSameAs
- methodPattern:
- Change type
- oldFullyQualifiedTypeName:
com.google.common.truth.Subject
- newFullyQualifiedTypeName:
org.assertj.core.api.AbstractObjectAssert
- oldFullyQualifiedTypeName:
- Change method name
- methodPattern:
com.google.common.truth.IterableSubject containsExactlyElementsIn(..)
- newMethodName:
containsExactlyElementsOf
- methodPattern:
- Change method name
- methodPattern:
com.google.common.truth.IterableSubject containsAnyIn(..)
- newMethodName:
containsAnyElementsOf
- methodPattern:
- Change method name
- methodPattern:
com.google.common.truth.IterableSubject containsNoneIn(..)
- newMethodName:
doesNotContainAnyElementsOf
- methodPattern:
- Change method name
- methodPattern:
com.google.common.truth.IterableSubject containsAllIn(..)
- newMethodName:
containsAll
- methodPattern:
- Change method name
- methodPattern:
com.google.common.truth.IterableSubject containsAllOf(..)
- newMethodName:
contains
- methodPattern:
- Change method name
- methodPattern:
com.google.common.truth.IterableSubject containsNoneOf(..)
- newMethodName:
doesNotContain
- methodPattern:
- Change type
- oldFullyQualifiedTypeName:
com.google.common.truth.IterableSubject
- newFullyQualifiedTypeName:
org.assertj.core.api.AbstractIterableAssert
- oldFullyQualifiedTypeName:
- Change method name
- methodPattern:
com.google.common.truth.OptionalSubject hasValue(..)
- newMethodName:
contains
- methodPattern:
- Change type
- oldFullyQualifiedTypeName:
com.google.common.truth.OptionalSubject
- newFullyQualifiedTypeName:
org.assertj.core.api.AbstractOptionalAssert
- oldFullyQualifiedTypeName:
- Change type
- oldFullyQualifiedTypeName:
com.google.common.truth.GuavaOptionalSubject
- newFullyQualifiedTypeName:
org.assertj.core.api.AbstractOptionalAssert
- oldFullyQualifiedTypeName:
- Change method name
- methodPattern:
org.assertj.core.api.AbstractMapAssert containsEntries(..)
- newMethodName:
contains
- methodPattern:
- Change type
- oldFullyQualifiedTypeName:
com.google.common.truth.MapSubject
- newFullyQualifiedTypeName:
org.assertj.core.api.AbstractMapAssert
- oldFullyQualifiedTypeName:
- Change method name
- methodPattern:
com.google.common.truth.ObjectArraySubject asList()
- newMethodName:
containsExactly
- methodPattern:
- Change type
- oldFullyQualifiedTypeName:
com.google.common.truth.ObjectArraySubject
- newFullyQualifiedTypeName:
org.assertj.core.api.AbstractObjectArrayAssert
- oldFullyQualifiedTypeName:
- Change type
- oldFullyQualifiedTypeName:
com.google.common.truth.BooleanSubject
- newFullyQualifiedTypeName:
org.assertj.core.api.AbstractBooleanAssert
- oldFullyQualifiedTypeName:
- Change type
- oldFullyQualifiedTypeName:
com.google.common.truth.IntegerSubject
- newFullyQualifiedTypeName:
org.assertj.core.api.AbstractIntegerAssert
- oldFullyQualifiedTypeName:
- Change type
- oldFullyQualifiedTypeName:
com.google.common.truth.LongSubject
- newFullyQualifiedTypeName:
org.assertj.core.api.AbstractLongAssert
- oldFullyQualifiedTypeName:
- Change type
- oldFullyQualifiedTypeName:
com.google.common.truth.DoubleSubject
- newFullyQualifiedTypeName:
org.assertj.core.api.AbstractDoubleAssert
- oldFullyQualifiedTypeName:
- Change type
- oldFullyQualifiedTypeName:
com.google.common.truth.FloatSubject
- newFullyQualifiedTypeName:
org.assertj.core.api.AbstractFloatAssert
- oldFullyQualifiedTypeName:
- Change type
- oldFullyQualifiedTypeName:
com.google.common.truth.BigDecimalSubject
- newFullyQualifiedTypeName:
org.assertj.core.api.AbstractBigDecimalAssert
- oldFullyQualifiedTypeName:
- Change type
- oldFullyQualifiedTypeName:
com.google.common.truth.PrimitiveBooleanArraySubject
- newFullyQualifiedTypeName:
org.assertj.core.api.AbstractBooleanArrayAssert
- oldFullyQualifiedTypeName:
- Change type
- oldFullyQualifiedTypeName:
com.google.common.truth.PrimitiveIntArraySubject
- newFullyQualifiedTypeName:
org.assertj.core.api.AbstractIntArrayAssert
- oldFullyQualifiedTypeName:
- Change type
- oldFullyQualifiedTypeName:
com.google.common.truth.PrimitiveLongArraySubject
- newFullyQualifiedTypeName:
org.assertj.core.api.AbstractLongArrayAssert
- oldFullyQualifiedTypeName:
- Change type
- oldFullyQualifiedTypeName:
com.google.common.truth.PrimitiveDoubleArraySubject
- newFullyQualifiedTypeName:
org.assertj.core.api.AbstractDoubleArrayAssert
- oldFullyQualifiedTypeName:
- Change type
- oldFullyQualifiedTypeName:
com.google.common.truth.PrimitiveFloatArraySubject
- newFullyQualifiedTypeName:
org.assertj.core.api.AbstractFloatArrayAssert
- oldFullyQualifiedTypeName:
- Change type
- oldFullyQualifiedTypeName:
com.google.common.truth.PrimitiveByteArraySubject
- newFullyQualifiedTypeName:
org.assertj.core.api.AbstractByteArrayAssert
- oldFullyQualifiedTypeName:
- Change type
- oldFullyQualifiedTypeName:
com.google.common.truth.PrimitiveCharArraySubject
- newFullyQualifiedTypeName:
org.assertj.core.api.AbstractCharArrayAssert
- oldFullyQualifiedTypeName:
- Change type
- oldFullyQualifiedTypeName:
com.google.common.truth.PrimitiveShortArraySubject
- newFullyQualifiedTypeName:
org.assertj.core.api.AbstractShortArrayAssert
- oldFullyQualifiedTypeName:
- Change type
- oldFullyQualifiedTypeName:
com.google.common.truth.Truth8
- newFullyQualifiedTypeName:
org.assertj.core.api.Assertions
- oldFullyQualifiedTypeName:
- Change type
- oldFullyQualifiedTypeName:
com.google.common.truth.OptionalIntSubject
- newFullyQualifiedTypeName:
org.assertj.core.api.AbstractOptionalIntAssert
- oldFullyQualifiedTypeName:
- Change type
- oldFullyQualifiedTypeName:
com.google.common.truth.OptionalLongSubject
- newFullyQualifiedTypeName:
org.assertj.core.api.AbstractOptionalLongAssert
- oldFullyQualifiedTypeName:
- Change type
- oldFullyQualifiedTypeName:
com.google.common.truth.OptionalDoubleSubject
- newFullyQualifiedTypeName:
org.assertj.core.api.AbstractOptionalDoubleAssert
- oldFullyQualifiedTypeName:
- Change type
- oldFullyQualifiedTypeName:
com.google.common.truth.StreamSubject
- newFullyQualifiedTypeName:
org.assertj.core.api.ListAssert
- oldFullyQualifiedTypeName:
- Change type
- oldFullyQualifiedTypeName:
com.google.common.truth.IntStreamSubject
- newFullyQualifiedTypeName:
org.assertj.core.api.AbstractIntArrayAssert
- oldFullyQualifiedTypeName:
- Change type
- oldFullyQualifiedTypeName:
com.google.common.truth.LongStreamSubject
- newFullyQualifiedTypeName:
org.assertj.core.api.AbstractLongArrayAssert
- oldFullyQualifiedTypeName:
- Change type
- oldFullyQualifiedTypeName:
com.google.common.truth.PathSubject
- newFullyQualifiedTypeName:
org.assertj.core.api.AbstractPathAssert
- oldFullyQualifiedTypeName:
- Change type
- oldFullyQualifiedTypeName:
com.google.common.truth.ClassSubject
- newFullyQualifiedTypeName:
org.assertj.core.api.AbstractClassAssert
- oldFullyQualifiedTypeName:
- Change type
- oldFullyQualifiedTypeName:
com.google.common.truth.ThrowableSubject
- newFullyQualifiedTypeName:
org.assertj.core.api.AbstractThrowableAssert
- oldFullyQualifiedTypeName:
- Remove unused imports
- Change type
- oldFullyQualifiedTypeName:
com.google.common.truth.Truth
- newFullyQualifiedTypeName:
org.assertj.core.api.Assertions
- oldFullyQualifiedTypeName:
- Remove a Gradle or Maven dependency
- groupId:
com.google.truth
- artifactId:
truth
- groupId:
---
type: specs.openrewrite.org/v1beta/recipe
name: org.openrewrite.java.testing.truth.MigrateTruthToAssertJ
displayName: Migrate Google Truth to AssertJ
description: |
Migrate Google Truth assertions to AssertJ assertions.
tags:
- truth
- testing
- assertj
recipeList:
- org.openrewrite.java.dependencies.AddDependency:
groupId: org.assertj
artifactId: assertj-core
version: 3.x
onlyIfUsing: com.google.common.truth.*
acceptTransitive: true
- org.openrewrite.java.testing.truth.TruthAssertToAssertThat
- org.openrewrite.java.testing.truth.TruthAssertWithMessageToAssertJ
- org.openrewrite.java.testing.truth.TruthThrowableAssertions
- org.openrewrite.java.testing.truth.TruthCustomSubjectsToAssertJ
- org.openrewrite.java.ChangeMethodName:
methodPattern: com.google.common.truth..* hasLength(int)
newMethodName: hasSize
- org.openrewrite.java.ChangeMethodName:
methodPattern: com.google.common.truth.StringSubject containsMatch(..)
newMethodName: matches
- org.openrewrite.java.ChangeMethodName:
methodPattern: com.google.common.truth.StringSubject doesNotContainMatch(..)
newMethodName: doesNotMatch
- org.openrewrite.java.ChangeType:
oldFullyQualifiedTypeName: com.google.common.truth.StringSubject
newFullyQualifiedTypeName: org.assertj.core.api.AbstractStringAssert
- org.openrewrite.java.ChangeMethodName:
methodPattern: com.google.common.truth.ComparableSubject isAtLeast(..)
newMethodName: isGreaterThanOrEqualTo
- org.openrewrite.java.ChangeMethodName:
methodPattern: com.google.common.truth.ComparableSubject isAtMost(..)
newMethodName: isLessThanOrEqualTo
- org.openrewrite.java.ChangeType:
oldFullyQualifiedTypeName: com.google.common.truth.ComparableSubject
newFullyQualifiedTypeName: org.assertj.core.api.AbstractComparableAssert
- org.openrewrite.java.ChangeMethodName:
methodPattern: com.google.common.truth.Subject isSameInstanceAs(..)
newMethodName: isSameAs
- org.openrewrite.java.ChangeMethodName:
methodPattern: com.google.common.truth.Subject isNotSameInstanceAs(..)
newMethodName: isNotSameAs
- org.openrewrite.java.ChangeType:
oldFullyQualifiedTypeName: com.google.common.truth.Subject
newFullyQualifiedTypeName: org.assertj.core.api.AbstractObjectAssert
- org.openrewrite.java.ChangeMethodName:
methodPattern: com.google.common.truth.IterableSubject containsExactlyElementsIn(..)
newMethodName: containsExactlyElementsOf
- org.openrewrite.java.ChangeMethodName:
methodPattern: com.google.common.truth.IterableSubject containsAnyIn(..)
newMethodName: containsAnyElementsOf
- org.openrewrite.java.ChangeMethodName:
methodPattern: com.google.common.truth.IterableSubject containsNoneIn(..)
newMethodName: doesNotContainAnyElementsOf
- org.openrewrite.java.ChangeMethodName:
methodPattern: com.google.common.truth.IterableSubject containsAllIn(..)
newMethodName: containsAll
- org.openrewrite.java.ChangeMethodName:
methodPattern: com.google.common.truth.IterableSubject containsAllOf(..)
newMethodName: contains
- org.openrewrite.java.ChangeMethodName:
methodPattern: com.google.common.truth.IterableSubject containsNoneOf(..)
newMethodName: doesNotContain
- org.openrewrite.java.ChangeType:
oldFullyQualifiedTypeName: com.google.common.truth.IterableSubject
newFullyQualifiedTypeName: org.assertj.core.api.AbstractIterableAssert
- org.openrewrite.java.ChangeMethodName:
methodPattern: com.google.common.truth.OptionalSubject hasValue(..)
newMethodName: contains
- org.openrewrite.java.ChangeType:
oldFullyQualifiedTypeName: com.google.common.truth.OptionalSubject
newFullyQualifiedTypeName: org.assertj.core.api.AbstractOptionalAssert
- org.openrewrite.java.ChangeType:
oldFullyQualifiedTypeName: com.google.common.truth.GuavaOptionalSubject
newFullyQualifiedTypeName: org.assertj.core.api.AbstractOptionalAssert
- org.openrewrite.java.ChangeMethodName:
methodPattern: org.assertj.core.api.AbstractMapAssert containsEntries(..)
newMethodName: contains
- org.openrewrite.java.ChangeType:
oldFullyQualifiedTypeName: com.google.common.truth.MapSubject
newFullyQualifiedTypeName: org.assertj.core.api.AbstractMapAssert
- org.openrewrite.java.ChangeMethodName:
methodPattern: com.google.common.truth.ObjectArraySubject asList()
newMethodName: containsExactly
- org.openrewrite.java.ChangeType:
oldFullyQualifiedTypeName: com.google.common.truth.ObjectArraySubject
newFullyQualifiedTypeName: org.assertj.core.api.AbstractObjectArrayAssert
- org.openrewrite.java.ChangeType:
oldFullyQualifiedTypeName: com.google.common.truth.BooleanSubject
newFullyQualifiedTypeName: org.assertj.core.api.AbstractBooleanAssert
- org.openrewrite.java.ChangeType:
oldFullyQualifiedTypeName: com.google.common.truth.IntegerSubject
newFullyQualifiedTypeName: org.assertj.core.api.AbstractIntegerAssert
- org.openrewrite.java.ChangeType:
oldFullyQualifiedTypeName: com.google.common.truth.LongSubject
newFullyQualifiedTypeName: org.assertj.core.api.AbstractLongAssert
- org.openrewrite.java.ChangeType:
oldFullyQualifiedTypeName: com.google.common.truth.DoubleSubject
newFullyQualifiedTypeName: org.assertj.core.api.AbstractDoubleAssert
- org.openrewrite.java.ChangeType:
oldFullyQualifiedTypeName: com.google.common.truth.FloatSubject
newFullyQualifiedTypeName: org.assertj.core.api.AbstractFloatAssert
- org.openrewrite.java.ChangeType:
oldFullyQualifiedTypeName: com.google.common.truth.BigDecimalSubject
newFullyQualifiedTypeName: org.assertj.core.api.AbstractBigDecimalAssert
- org.openrewrite.java.ChangeType:
oldFullyQualifiedTypeName: com.google.common.truth.PrimitiveBooleanArraySubject
newFullyQualifiedTypeName: org.assertj.core.api.AbstractBooleanArrayAssert
- org.openrewrite.java.ChangeType:
oldFullyQualifiedTypeName: com.google.common.truth.PrimitiveIntArraySubject
newFullyQualifiedTypeName: org.assertj.core.api.AbstractIntArrayAssert
- org.openrewrite.java.ChangeType:
oldFullyQualifiedTypeName: com.google.common.truth.PrimitiveLongArraySubject
newFullyQualifiedTypeName: org.assertj.core.api.AbstractLongArrayAssert
- org.openrewrite.java.ChangeType:
oldFullyQualifiedTypeName: com.google.common.truth.PrimitiveDoubleArraySubject
newFullyQualifiedTypeName: org.assertj.core.api.AbstractDoubleArrayAssert
- org.openrewrite.java.ChangeType:
oldFullyQualifiedTypeName: com.google.common.truth.PrimitiveFloatArraySubject
newFullyQualifiedTypeName: org.assertj.core.api.AbstractFloatArrayAssert
- org.openrewrite.java.ChangeType:
oldFullyQualifiedTypeName: com.google.common.truth.PrimitiveByteArraySubject
newFullyQualifiedTypeName: org.assertj.core.api.AbstractByteArrayAssert
- org.openrewrite.java.ChangeType:
oldFullyQualifiedTypeName: com.google.common.truth.PrimitiveCharArraySubject
newFullyQualifiedTypeName: org.assertj.core.api.AbstractCharArrayAssert
- org.openrewrite.java.ChangeType:
oldFullyQualifiedTypeName: com.google.common.truth.PrimitiveShortArraySubject
newFullyQualifiedTypeName: org.assertj.core.api.AbstractShortArrayAssert
- org.openrewrite.java.ChangeType:
oldFullyQualifiedTypeName: com.google.common.truth.Truth8
newFullyQualifiedTypeName: org.assertj.core.api.Assertions
- org.openrewrite.java.ChangeType:
oldFullyQualifiedTypeName: com.google.common.truth.OptionalIntSubject
newFullyQualifiedTypeName: org.assertj.core.api.AbstractOptionalIntAssert
- org.openrewrite.java.ChangeType:
oldFullyQualifiedTypeName: com.google.common.truth.OptionalLongSubject
newFullyQualifiedTypeName: org.assertj.core.api.AbstractOptionalLongAssert
- org.openrewrite.java.ChangeType:
oldFullyQualifiedTypeName: com.google.common.truth.OptionalDoubleSubject
newFullyQualifiedTypeName: org.assertj.core.api.AbstractOptionalDoubleAssert
- org.openrewrite.java.ChangeType:
oldFullyQualifiedTypeName: com.google.common.truth.StreamSubject
newFullyQualifiedTypeName: org.assertj.core.api.ListAssert
- org.openrewrite.java.ChangeType:
oldFullyQualifiedTypeName: com.google.common.truth.IntStreamSubject
newFullyQualifiedTypeName: org.assertj.core.api.AbstractIntArrayAssert
- org.openrewrite.java.ChangeType:
oldFullyQualifiedTypeName: com.google.common.truth.LongStreamSubject
newFullyQualifiedTypeName: org.assertj.core.api.AbstractLongArrayAssert
- org.openrewrite.java.ChangeType:
oldFullyQualifiedTypeName: com.google.common.truth.PathSubject
newFullyQualifiedTypeName: org.assertj.core.api.AbstractPathAssert
- org.openrewrite.java.ChangeType:
oldFullyQualifiedTypeName: com.google.common.truth.ClassSubject
newFullyQualifiedTypeName: org.assertj.core.api.AbstractClassAssert
- org.openrewrite.java.ChangeType:
oldFullyQualifiedTypeName: com.google.common.truth.ThrowableSubject
newFullyQualifiedTypeName: org.assertj.core.api.AbstractThrowableAssert
- org.openrewrite.java.RemoveUnusedImports
- org.openrewrite.java.ChangeType:
oldFullyQualifiedTypeName: com.google.common.truth.Truth
newFullyQualifiedTypeName: org.assertj.core.api.Assertions
- org.openrewrite.java.dependencies.RemoveDependency:
groupId: com.google.truth
artifactId: truth
Used by
This recipe is used as part of the following composite recipes:
Examples
Example 1
MigrateTruthToAssertJTest#basicAssertThatConversion
- java
- Diff
Before
import static com.google.common.truth.Truth.assertThat;
class Test {
void test() {
String actual = "hello";
assertThat(actual).isEqualTo("hello");
assertThat(actual).isNotEqualTo("world");
assertThat(actual).isNotNull();
assertThat(actual).contains("ell");
}
}
After
import static org.assertj.core.api.Assertions.assertThat;
class Test {
void test() {
String actual = "hello";
assertThat(actual).isEqualTo("hello");
assertThat(actual).isNotEqualTo("world");
assertThat(actual).isNotNull();
assertThat(actual).contains("ell");
}
}
@@ -1,1 +1,1 @@
-import static com.google.common.truth.Truth.assertThat;
+import static org.assertj.core.api.Assertions.assertThat;
Example 2
TruthThrowableAssertionsTest#hasMessageThatContains
- java
- Diff
Before
import static com.google.common.truth.Truth.assertThat;
class Test {
void test() {
Exception e = new IllegalArgumentException("Invalid argument provided");
assertThat(e).hasMessageThat().contains("Invalid");
}
}
After
import static org.assertj.core.api.Assertions.assertThat;
class Test {
void test() {
Exception e = new IllegalArgumentException("Invalid argument provided");
assertThat(e).hasMessageContaining("Invalid");
}
}
@@ -1,1 +1,1 @@
-import static com.google.common.truth.Truth.assertThat;
+import static org.assertj.core.api.Assertions.assertThat;
@@ -6,1 +6,1 @@
void test() {
Exception e = new IllegalArgumentException("Invalid argument provided");
- assertThat(e).hasMessageThat().contains("Invalid");
+ assertThat(e).hasMessageContaining("Invalid");
}
Example 3
MigrateTruthToAssertJTest#basicAssertThatConversion
- java
- Diff
Before
import static com.google.common.truth.Truth.assertThat;
class Test {
void test() {
String actual = "hello";
assertThat(actual).isEqualTo("hello");
assertThat(actual).isNotEqualTo("world");
assertThat(actual).isNotNull();
assertThat(actual).contains("ell");
}
}
After
import static org.assertj.core.api.Assertions.assertThat;
class Test {
void test() {
String actual = "hello";
assertThat(actual).isEqualTo("hello");
assertThat(actual).isNotEqualTo("world");
assertThat(actual).isNotNull();
assertThat(actual).contains("ell");
}
}
@@ -1,1 +1,1 @@
-import static com.google.common.truth.Truth.assertThat;
+import static org.assertj.core.api.Assertions.assertThat;
Example 4
TruthThrowableAssertionsTest#hasMessageThatContains
- java
- Diff
Before
import static com.google.common.truth.Truth.assertThat;
class Test {
void test() {
Exception e = new IllegalArgumentException("Invalid argument provided");
assertThat(e).hasMessageThat().contains("Invalid");
}
}
After
import static org.assertj.core.api.Assertions.assertThat;
class Test {
void test() {
Exception e = new IllegalArgumentException("Invalid argument provided");
assertThat(e).hasMessageContaining("Invalid");
}
}
@@ -1,1 +1,1 @@
-import static com.google.common.truth.Truth.assertThat;
+import static org.assertj.core.api.Assertions.assertThat;
@@ -6,1 +6,1 @@
void test() {
Exception e = new IllegalArgumentException("Invalid argument provided");
- assertThat(e).hasMessageThat().contains("Invalid");
+ assertThat(e).hasMessageContaining("Invalid");
}
Usage
This recipe has no required configuration options. It can be activated by adding a dependency on org.openrewrite.recipe:rewrite-testing-frameworks
in your build file or by running a shell command (in which case no build changes are needed):
- Gradle
- Gradle init script
- Maven POM
- Maven Command Line
- Moderne CLI
- Add the following to your
build.gradle
file:
plugins {
id("org.openrewrite.rewrite") version("latest.release")
}
rewrite {
activeRecipe("org.openrewrite.java.testing.truth.MigrateTruthToAssertJ")
setExportDatatables(true)
}
repositories {
mavenCentral()
}
dependencies {
rewrite("org.openrewrite.recipe:rewrite-testing-frameworks:3.19.0")
}
- Run
gradle rewriteRun
to run the recipe.
- Create a file named
init.gradle
in the root of your project.
initscript {
repositories {
maven { url "https://plugins.gradle.org/m2" }
}
dependencies { classpath("org.openrewrite:plugin:7.18.0") }
}
rootProject {
plugins.apply(org.openrewrite.gradle.RewritePlugin)
dependencies {
rewrite("org.openrewrite.recipe:rewrite-testing-frameworks:3.19.0")
}
rewrite {
activeRecipe("org.openrewrite.java.testing.truth.MigrateTruthToAssertJ")
setExportDatatables(true)
}
afterEvaluate {
if (repositories.isEmpty()) {
repositories {
mavenCentral()
}
}
}
}
- Run the recipe.
gradle --init-script init.gradle rewriteRun
- Add the following to your
pom.xml
file:
<project>
<build>
<plugins>
<plugin>
<groupId>org.openrewrite.maven</groupId>
<artifactId>rewrite-maven-plugin</artifactId>
<version>6.21.0</version>
<configuration>
<exportDatatables>true</exportDatatables>
<activeRecipes>
<recipe>org.openrewrite.java.testing.truth.MigrateTruthToAssertJ</recipe>
</activeRecipes>
</configuration>
<dependencies>
<dependency>
<groupId>org.openrewrite.recipe</groupId>
<artifactId>rewrite-testing-frameworks</artifactId>
<version>3.19.0</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
</project>
- Run
mvn rewrite:run
to run the recipe.
You will need to have Maven installed on your machine before you can run the following command.
mvn -U org.openrewrite.maven:rewrite-maven-plugin:run -Drewrite.recipeArtifactCoordinates=org.openrewrite.recipe:rewrite-testing-frameworks:RELEASE -Drewrite.activeRecipes=org.openrewrite.java.testing.truth.MigrateTruthToAssertJ -Drewrite.exportDatatables=true
You will need to have configured the Moderne CLI on your machine before you can run the following command.
mod run . --recipe MigrateTruthToAssertJ
If the recipe is not available locally, then you can install it using:
mod config recipes jar install org.openrewrite.recipe:rewrite-testing-frameworks:3.19.0
See how this recipe works across multiple open-source repositories
Run this recipe on OSS repos at scale with the Moderne SaaS.

The community edition of the Moderne platform enables you to easily run recipes across thousands of open-source repositories.
Please contact Moderne for more information about safely running the recipes on your own codebase in a private SaaS.
Data Tables
- SourcesFileResults
- SourcesFileErrors
- RecipeRunStats
Source files that had results
org.openrewrite.table.SourcesFileResults
Source files that were modified by the recipe run.
Column Name | Description |
---|---|
Source path before the run | The source path of the file before the run. null when a source file was created during the run. |
Source path after the run | A recipe may modify the source path. This is the path after the run. null when a source file was deleted during the run. |
Parent of the recipe that made changes | In a hierarchical recipe, the parent of the recipe that made a change. Empty if this is the root of a hierarchy or if the recipe is not hierarchical at all. |
Recipe that made changes | The specific recipe that made a change. |
Estimated time saving | An estimated effort that a developer to fix manually instead of using this recipe, in unit of seconds. |
Cycle | The recipe cycle in which the change was made. |
Source files that errored on a recipe
org.openrewrite.table.SourcesFileErrors
The details of all errors produced by a recipe run.
Column Name | Description |
---|---|
Source path | The file that failed to parse. |
Recipe that made changes | The specific recipe that made a change. |
Stack trace | The stack trace of the failure. |
Recipe performance
org.openrewrite.table.RecipeRunStats
Statistics used in analyzing the performance of recipes.
Column Name | Description |
---|---|
The recipe | The recipe whose stats are being measured both individually and cumulatively. |
Source file count | The number of source files the recipe ran over. |
Source file changed count | The number of source files which were changed in the recipe run. Includes files created, deleted, and edited. |
Cumulative scanning time (ns) | The total time spent across the scanning phase of this recipe. |
Max scanning time (ns) | The max time scanning any one source file. |
Cumulative edit time (ns) | The total time spent across the editing phase of this recipe. |
Max edit time (ns) | The max time editing any one source file. |