@Override
    public void validate(Element element, ConfigElementImplementationRegistry registry) {
        XPathFactory xPathFactory = XPathFactory.instance();
        List<String> tasks = ConfigUtil.allTasks(registry);
        for (String task : tasks) {
            List<Element> taskNodes = xPathFactory.compile("//" + task, Filters.element()).evaluate(element);
            for (Element taskNode : taskNodes) {
                List<Element> list = xPathFactory.compile("oncancel", Filters.element()).evaluate(taskNode);
                if (list.size() > 1) {
                    throw new RuntimeException("Task [" + task + "] should not contain more than 1 oncancel task");
                }
            }
        }
    }
@Test
    public void shouldNotFailWithExceptionWhenThereAreNoOnCancelTasksForABuiltInTask() throws Exception {
        ConfigElementImplementationRegistry registry = mock(ConfigElementImplementationRegistry.class);
        when(registry.implementersOf(Task.class)).thenReturn(tasks(ExecTask.class));

        String content =
                """
                        <cruise>
                          <pipeline>
                            <stage>
                              <jobs>
                                <job>
                                  <tasks>
                                    <exec command="install_addons.sh">
                                      <runif status="passed" />
                                    </exec>
                                  </tasks>
                                </job>
                              </jobs>
                            </stage>
                          </pipeline>
                        </cruise>
                        """;

        UniqueOnCancelValidator validator = new UniqueOnCancelValidator();
        validator.validate(elementFor(content), registry);
    }