Top Description Fields Constructors Methods
org.assertj.core.condition

public Class NestableCondition<ACTUAL, NESTED>

extends Join<ACTUAL>
Class Inheritance
Type Parameters
<ACTUAL>
the type of object this condition accepts (Customer in the example)
<NESTED>
the type of object nested into ACTUAL (Address in the example)
Static Imports
java.util.Arrays.stream, java.util.stream.Collectors.toList

Building block to define precise conditions on complex objects.

It allows to create readable assertions and produces beautiful assertion error messages.

Example:

 import static org.assertj.core.condition.NestableCondition.nestable;
import static org.assertj.core.condition.VerboseCondition.verboseCondition;

class Customer {
   final String name;
   final Address address;

   Customer(String name, Address address) {
     this.name = name;
     this.address = address;
   }
}

class Address {
   final String firstLine;
   final String postcode;

   Address(String firstLine, String postcode) {
     this.firstLine = firstLine;
     this.postcode = postcode;
   }
 }

static Condition<Customer> name(String expected) {
  return new Condition<>(
     it -> expected.equals(it.name),
     "name: " + expected
  );
}

static Condition<Customer> customer(Condition<Customer>... conditions) {
  return nestable("person", conditions);
}

static Condition<Address> firstLine(String expected) {
  return new Condition<>(
     it -> expected.equals(it.firstLine),
     "first line: " + expected
  );
}

static Condition<Address> postcode(String expected) {
  return new Condition<>(
     it -> expected.equals(it.postcode),
     "postcode: " + expected
  );
}

static Condition<Customer> address(Condition<Address>... conditions) {
  return nestable(
     "address",
     customer -> customer.address,
     conditions
  );
}
And assertions can be written like:
 assertThat(customer).is(
  customer(
    name("John"),
    address(
      firstLine("3"),
      postcode("KM3 8SP")
    )
  )
); 
leads to an easy-to-read assertion error:
 Expecting actual:
  org.assertj.core.condition.Customer@27ff5d15
to be:
  [✗] person:[
      [✓] name: John,
      [✗] address:[
        [✗] first line: 3,
        [✓] postcode: KM3 8SP
      ]
  ]
For an even better assertion error, see VerboseCondition.
Author
Alessandro Ciccimarra

Field Summary

Modifier and TypeField and Description
private final String
Inherited from org.assertj.core.condition.Join:
conditionsPREFIX_DELIMITERSUFFIX_DELIMITER

Constructor Summary

AccessConstructor and Description
private
NestableCondition(String descriptionPrefix, Stream<? extends Condition<? super NESTED>> conditions, Function<? super ACTUAL, ? extends NESTED> extractor)

private
NestableCondition(String descriptionPrefix, Stream<? extends Condition<? super ACTUAL>> conditions)

Method Summary

Modifier and TypeMethod and Description
private static <ACTUAL, NESTED> List<Condition<? super ACTUAL>>
compose(Stream<? extends Condition<? super NESTED>> conditions, Function<? super ACTUAL, ? extends NESTED> extractor)

private static <ACTUAL, NESTED> Condition<ACTUAL>
compose(Condition<? super NESTED> condition, Function<? super ACTUAL, ? extends NESTED> extractor)

public String
descriptionPrefix()

Implements abstract org.assertj.core.condition.Join.descriptionPrefix.

method used to prefix the subclass join description, ex: "all of"
public boolean
matches(ACTUAL
the value to verify.
value
)

Overrides org.assertj.core.api.Condition.matches.

Verifies that the given value satisfies this condition.
public static <
the type of object the resulting condition accepts
ACTUAL
,
the type of object nested into K
NESTED
>
Condition<ACTUAL>

Returns:

the nestable condition
nestable
(String
the prefix to use to build the description
descriptionPrefix
,
Function<? super ACTUAL, ? extends NESTED>
a function to extract the nested object of type T from an object fo type K
extractor
,
Condition<? super NESTED>...
conditions to be checked
conditions
)

Creates a new NestableCondition

public static <
the type of object the resulting condition accepts
ACTUAL
>
Condition<ACTUAL>

Returns:

the nestable condition
nestable
(String
the prefix to use to build the description
descriptionPrefix
,
Condition<? super ACTUAL>...
conditions to be checked
conditions
)

Creates a new NestableCondition

Inherited from org.assertj.core.condition.Join:
conditionDescriptionWithStatusconditionsdescription

Field Detail

descriptionPrefixback to summary
private final String descriptionPrefix

Constructor Detail

NestableConditionback to summary
private NestableCondition(String descriptionPrefix, Stream<? extends Condition<? super NESTED>> conditions, Function<? super ACTUAL, ? extends NESTED> extractor)
NestableConditionback to summary
private NestableCondition(String descriptionPrefix, Stream<? extends Condition<? super ACTUAL>> conditions)

Method Detail

composeback to summary
private static <ACTUAL, NESTED> List<Condition<? super ACTUAL>> compose(Stream<? extends Condition<? super NESTED>> conditions, Function<? super ACTUAL, ? extends NESTED> extractor)
composeback to summary
private static <ACTUAL, NESTED> Condition<ACTUAL> compose(Condition<? super NESTED> condition, Function<? super ACTUAL, ? extends NESTED> extractor)
descriptionPrefixback to summary
public String descriptionPrefix()

Implements abstract org.assertj.core.condition.Join.descriptionPrefix.

Doc from org.assertj.core.condition.Join.descriptionPrefix.

method used to prefix the subclass join description, ex: "all of"

Returns:String

the prefix to use to build the description.

Annotations
@Override
matchesback to summary
public boolean matches(ACTUAL value)

Overrides org.assertj.core.api.Condition.matches.

Doc from org.assertj.core.api.Condition.matches.

Verifies that the given value satisfies this condition.

Parameters
value:ACTUAL

the value to verify.

Returns:boolean

true if the given value satisfies this condition; false otherwise.

Annotations
@Override
nestableback to summary
public static <ACTUAL, NESTED> Condition<ACTUAL> nestable(String descriptionPrefix, Function<? super ACTUAL, ? extends NESTED> extractor, Condition<? super NESTED>... conditions)

Creates a new NestableCondition

Parameters
<ACTUAL>
the type of object the resulting condition accepts
<NESTED>
the type of object nested into K
descriptionPrefix:String

the prefix to use to build the description

extractor:Function<? super ACTUAL, ? extends NESTED>

a function to extract the nested object of type T from an object fo type K

conditions:Condition<? super NESTED>[]

conditions to be checked

Returns:Condition<ACTUAL>

the nestable condition

Annotations
@SafeVarargs
nestableback to summary
public static <ACTUAL> Condition<ACTUAL> nestable(String descriptionPrefix, Condition<? super ACTUAL>... conditions)

Creates a new NestableCondition

Parameters
<ACTUAL>
the type of object the resulting condition accepts
descriptionPrefix:String

the prefix to use to build the description

conditions:Condition<? super ACTUAL>[]

conditions to be checked

Returns:Condition<ACTUAL>

the nestable condition

Annotations
@SafeVarargs