AssertJ Neo4j assertions

Provides assertions for Neo4j 3 or higher.

This module have been written by Florent Biville, huge thanks to him! Great Work!
If you need additional assertions, just fill a ticket in AssertJ Neo4j issue tracker.

AssertJ Neo4j is hosted on github :

To quickly start using Neo4j assertions, follow the steps below.


You also need to provide Neo4j 3+ dependencies.

If you use another dependency tool, please check this page to find the relevant assertj dependency declaration for your tool.

... and use your preferred IDE code completion after assertThat.

Example from and

import static org.assertj.neo4j.api.Assertions.assertThat;

try (Transaction ignored = graphDatabaseService.beginTx()) {
   // path assertion example
   Node tienShinhan = dragonBallGraph.findUniqueCharacter("Tien Shinhan");
   Node doctorGero = dragonBallGraph.findUniqueCharacter("Dr. Gero");
   Node bulmaNode = dragonBallGraph.findUniqueCharacter("Bulma");
   Node masterRoshiNode = dragonBallGraph.findCharacter("Master Roshi");
   Relationship masterShenTraining = dragonBallGraph.findUniqueTraining("Master Shen");
   Relationship trainingFromSonGoku = dragonBallGraph.findUniqueTraining("Son Goku");

   Path bulmaToMasterRoshiPath = dragonBallGraph.findShortestPathBetween(
                                    "Master Roshi");

    * You can test several Path properties such as:
    *  - length
    *  - start/end node
    *  - last relationship

    * Cypher execution result (of Result type) is just an iterable of Map<String, Object>
    * ResultAssertion is just a convenient wrapper of the usual Map assertions :)
   Result result = graphDatabaseService.execute(
          "MATCH (character:Character) " +
          "WHERE =~ 'Master.*' " +
          "RETURN AS name ORDER BY name ASC");

                     .containsExactly(Maps.newHashMap("name", "Master Mutaito"),
                                      Maps.newHashMap("name", "Master Roshi"),
                                      Maps.newHashMap("name", "Master Shen"));

assertThat and entry are static imports from the Assertions class.

Note that you can find more working examples in neo4j package of assertj-examples project.

Release date : 2017-10-05

Neo4j required minimum version is now 3.0.0!

  • Path assertions
    • doesNotStartWithNode
    • doesNotEndWithNode
    • doesNotEndWithRelationship
  • Relationship assertions
    • doesNotStartWithNode
    • doesNotEndWithNode
  • Result assertions

Release date : 2014-01-02

  • Node assertions
  • Path assertions
  • Relationship assertions
  • PropertyContainer assertions

Latest javadoc release : AssertJ Neo4j javadoc.

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

import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.neo4j.api.Assertions.assertThat;

// initialization omitted for brevity ...
Node firstDisciple = ...;

// assertThat comes from org.assertj.neo4j.api.Assertions.assertThat static import
                         .hasProperty("name", "Son Goku")
                         .doesNotHaveProperty("name", "Bulma");

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

If you have any questions, please use AssertJ google group.

AssertJ Neo4j is hosted on github :

Please report bugs or missing features in AssertJ Neo4j issue tracker.

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

Special thanks to Florent Biville AssertJ Neo4j main contributor.