Suppose i have players which form a team which participates at a tournament. I want to test, that the tournament has at least one team with name T1 with a player named Paul.
package org.example;
import java.util.List;
public class Tournament {
List<Team> teams;
public Tournament(){
}
public void create(){
}
public List<Team> getTeams() {
return this.teams;
}
}
package org.example;
import java.util.List;
public class Team {
List<Player> players;
private String name;
public Team(String name, List<Player> players){
this.players = players;
this.name = name;
}
public List<Player> getPlayers(){
return this.players;
}
public String getName() {
return this.name;
}
}
package org.example;
public class Player {
String firstName;
public Player(String firstName){
this.firstName = firstName;
}
public String getFirstName(){
return this.firstName;
}
}
The test should look like this:
Tournament tournament = new Tournament();
tournament.create();
assertThat(tournament)
.hasAtLeastOneTeam()
.withName("T1")
.withAPlayer()
.named("Paul")
How is it possible to do this with AssertJ?