protected static void checkUniquenessOfChildKey(ProjectDefinition childProject, ProjectDefinition parentProject) {
    for (ProjectDefinition definition : parentProject.getSubProjects()) {
      if (definition.getKey().equals(childProject.getKey())) {
        throw MessageException.of("Project '" + parentProject.getKey() + "' can't have 2 modules with the following key: " + childProject.getKey());
      }
    }
  }
@Test
  public void shouldFailIf2ModulesWithSameKey() {
    Map<String, String> props = singletonMap("sonar.projectKey", "root");
    ProjectDefinition root = ProjectDefinition.create().setProperties(props);

    Map<String, String> props1 = singletonMap("sonar.projectKey", "mod1");
    root.addSubProject(ProjectDefinition.create().setProperties(props1));

    // Check uniqueness of a new module: OK
    Map<String, String> props2 = singletonMap("sonar.projectKey", "mod2");
    ProjectDefinition mod2 = ProjectDefinition.create().setProperties(props2);
    ProjectReactorBuilder.checkUniquenessOfChildKey(mod2, root);

    // Now, add it and check again
    root.addSubProject(mod2);

    assertThatThrownBy(() -> ProjectReactorBuilder.checkUniquenessOfChildKey(mod2, root))
      .isInstanceOf(MessageException.class)
      .hasMessage("Project 'root' can't have 2 modules with the following key: mod2");
  }