/assertj-guava

AssertJ Joda Time is a library of assertions specific to Guava types like Multimap, Optional or Table

Primary LanguageJavaApache License 2.0Apache-2.0

AssertJ Assertions for Guava

AssertJ assertions for Guava provides assertions for Guava types like Multimap, Table or Optional.

To start using Guava assertions

1 - Add this dependency snippet to your project

 <dependency>
   <groupId>org.assertj</groupId>
   <artifactId>assertj-guava</artifactId>
   <version>1.0.0</version>
   <scope>test</scope>
 </dependency>

2 - statically import org.assertj.guava.api.Assertions.assertThat and use your preferred IDE code completion after assertThat..

Example :

import static org.assertj.guava.api.Assertions.assertThat;
import static org.assertj.guava.api.Assertions.entry;

// Multimap assertions
Multimap<String, String> actual = ArrayListMultimap.create();
actual.putAll("Lakers", newArrayList("Kobe Bryant", "Magic Johnson", "Kareem Abdul Jabbar"));
actual.putAll("Spurs", newArrayList("Tony Parker", "Tim Duncan", "Manu Ginobili"));

assertThat(actual).containsKeys("Lakers", "Spurs");
assertThat(actual).contains(entry("Lakers", "Kobe Bryant"), entry("Spurs", "Tim Duncan"));

// Optional assertions
Optional<String> optional = Optional.of("Test");
assertThat(optional).isPresent().contains("Test");

assertThat and entry are static imports from the Assertions class.

Note that you can find working examples in assertj-examples guava package.

2013-03-26 : 1.0.0 release, the first release after Fest fork.

New features since Fest fork :

  • Guava Table assertions

Latest javadoc release : AssertJ Guava javadoc.

AssertJ Assertions for Guava is a fork form FEST Guava assertions and is part of AssertJ assertions portfolio. The main reason for this fork is that FEST will only provide a small core of assertions in the future whereas I felt on the contrary that it should have provided more assertions. Another reason is that AssertJ projects are also more opened to community contributions than FEST ones.

Migrating from Fest Guava to AssertJ Guava Assertions is super easy, you only have to change your static import.

Just replace :

import static org.fest.assertions.api.GUAVA

by :

import static org.assertj.guava.api.Assertions

You will have to make two static import : one for org.assertj.core.api.Assertions.assertThat to get core assertions and one org.assertj.guava.api.Assertions.assertThat for Guava assertions.

import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.guava.api.Assertions.assertThat;
...
// assertThat comes from org.assertj.guava.api.Assertions.assertThat static import
Multimap<String, String> actual = ArrayListMultimap.create();
actual.putAll("Lakers", newArrayList("Kobe Bryant", "Magic Johnson", "Kareem Abdul Jabbar"));
actual.putAll("Spurs", newArrayList("Tony Parker", "Tim Duncan", "Manu Ginobili"));

assertThat(actual).hasSize(6);
assertThat(actual).containsKeys("Lakers", "Spurs");

// assertThat comes from org.assertj.core.api.Assertions.assertThat static import
assertThat("hello world").startsWith("hello");

Thanks for your interest ! Please check our contributor's guidelines.