Migrating from Fest 2.x is easy since AssertJ is a fork of Fest and there are very few breaking changes.
First thing first, change your static import, from:
import static org.fest.assertions.api.Assertions
to
import static org.assertj.core.api.Assertions
For most users, that should be all you need to do !
For linux users, a quick way to do that is to use the following command:
find . -name "*.java" -exec sed -i "s/org.fest.assertions.api.Assertions/org.assertj.core.api.Assertions/g" '{}' \;
For mac users, you have an almost identical command (notice the "" after -i) :
find . -name "*.java" -exec sed -i "" "s/org.fest.assertions.api.Assertions/org.assertj.core.api.Assertions/g" '{}' \;
To do even more in a single command and also replacing non static imports and several statements, linux users can use the following command instead:
find . -name "*.java" -exec sed -i "s/import static org.fest.assertions.api./import static org.assertj.core.api./g;s/import org.fest.assertions.api./import org.assertj.core.api./g;s/import org.fest.assertions.core.Condition;/import org.assertj.core.api.Condition;/g;s/import org.fest.util./import org.assertj.core.util./g;s/import org.fest.assertions.data./import org.assertj.core.data./g" '{}' \;
Again, the equivalent command for Mac users is:
find . -name "*.java" -exec sed -i "" "s/import static org.fest.assertions.api./import static org.assertj.core.api./g;s/import org.fest.assertions.api./import org.assertj.core.api./g;s/import org.fest.assertions.core.Condition;/import org.assertj.core.api.Condition;/g;s/import org.fest.util./import org.assertj.core.util./g;s/import org.fest.assertions.data./import org.assertj.core.data./g" '{}' \;
Note: if your project uses both FestAssert Core assertions and Fest Joda-Time assertions, execute the above scripts for FestAssert Core Assertions after those for for Joda-Time!
The linux commands to automatically rename the assertions:
find . -name "*.java" -exec sed -i "s/isLenientEqualsToByIgnoringFields/isEqualToIgnoringGivenFields/g;s/isLenientEqualsToByAcceptingFields/isEqualToComparingOnlyGivenFields/g;s/isLenientEqualsToByIgnoringNullFields/isEqualToIgnoringNullFields/g;s/isEqualsToByComparingFields/isEqualToComparingFieldByField/g" '{}' \;
And the commands for Mac users:
find . -name "*.java" -exec sed -i "" "s/isLenientEqualsToByIgnoringFields/isEqualToIgnoringGivenFields/g;s/isLenientEqualsToByAcceptingFields/isEqualToComparingOnlyGivenFields/g;s/isLenientEqualsToByIgnoringNullFields/isEqualToIgnoringNullFields/g;s/isEqualsToByComparingFields/isEqualToComparingFieldByField/g" '{}' \;
If something's missing or doesn't work, please create an issue to update this section.
Migrating Fest Assert 1.4 is a little more involved than migrating from Fest Assert 2.x but is not difficult.
It is simple, instead of inheriting from GenericAssert you inherit from AbstractAssert and invert the parameter order in the constructor.
in Fest 1.4 :
public DateTimeAssert(DateTime actual) {
super(DateTimeAssert.class, actual);
}
in AssertJ :
public DateTimeAssert(DateTime actual) {
super(actual, DateTimeAssert.class);
}
In Fest 1.4 :
throw failure(concat("expecting ", objectName, " value not to be null"));
In AssertJ :
Fail.fail(String.format("expecting %s value not to be null", objectName));
We think that when using fail in a test, one should always set a meaningful failure message, thus the removing of no arg fail() method. Since fail() was mainly used when expecting an exception, you can replace it by : failBecauseExceptionWasNotThrown(Exception class).
For example, executing :
failBecauseExceptionWasNotThrown(FileNotFoundException.class)
will throw an AssertionError with message "Expected FileNotFoundException to be thrown"
All fail methods are available from the Assertions or the Fail classes.
In FEST 1.4 :
assertThat(fellowshipOfTheRing).onProperty("name").contains("Gandalf", "Frodo", "Legolas");
In AssertJ :
assertThat(fellowshipOfTheRing).extracting("name").contains("Gandalf", "Frodo", "Legolas");
Moreover extracting is able to extract both properties and fields while Fest can only extract properties.