package dev.caskeleton.buildlogic; import java.util.ArrayList; import java.util.Collection; import java.util.List; /** One rule for proving that a named test selector actually executed. */ public final class RequiredTestExecution { private static final List SUB_IDENTITY_SEPARATORS = List.of("$", "(", "["); private RequiredTestExecution() {} public static boolean satisfies(String executed, String required) { if (executed == null || required == null) { return false; } if (executed.equals(required)) { return true; } return SUB_IDENTITY_SEPARATORS.stream() .anyMatch(separator -> executed.startsWith(required + separator)); } public static List absent( Collection required, Collection executed) { if (required == null || required.isEmpty()) { return List.of(); } Collection observed = executed == null ? List.of() : executed; List absent = new ArrayList<>(); for (String requiredSelector : required) { boolean satisfied = observed.stream().anyMatch(executedSelector -> satisfies(executedSelector, requiredSelector)); if (!satisfied) { absent.add(requiredSelector); } } return List.copyOf(absent); } }