### Question:
BlueprintValidatorUtil { public static void validateHostGroupsMatch(Set<HostGroup> hostGroupsInRequest, Set<String> hostGroupsInBlueprint) { Set<String> hostGroupNamesInRequest = hostGroupsInRequest.stream().map(HostGroup::getName).collect(Collectors.toSet()); Set<String> missingFromRequest = Set.copyOf(Sets.difference(hostGroupsInBlueprint, hostGroupNamesInRequest)); Set<String> unknownHostGroups = Set.copyOf(Sets.difference(hostGroupNamesInRequest, hostGroupsInBlueprint)); if (!missingFromRequest.isEmpty()) { throw new BlueprintValidationException("The following host groups are missing from the request: " + String.join(", ", missingFromRequest)); } if (!unknownHostGroups.isEmpty()) { throw new BlueprintValidationException("Unknown host groups are present in the request: " + String.join(", ", unknownHostGroups)); } } private  BlueprintValidatorUtil(); static void validateHostGroupsMatch(Set<HostGroup> hostGroupsInRequest, Set<String> hostGroupsInBlueprint); static void validateInstanceGroups(Collection<HostGroup> hostGroups, Collection<InstanceGroup> instanceGroups); static Map<String, HostGroup> createHostGroupMap(Iterable<HostGroup> hostGroups); static void validateHostGroupCardinality(Set<HostGroup> hostGroups, Map<String, InstanceCount> blueprintHostGroupCardinality);  }### Answer:
@Test public void rejectsMissingHostGroup() { Set<HostGroup> request = Set.of( hostGroup("master", 1), hostGroup("worker", 2) ); Map<String, InstanceCount> requirements = Map.of( "master", InstanceCount.EXACTLY_ONE, "worker", InstanceCount.atLeast(3), "compute", InstanceCount.ZERO_OR_MORE ); Exception e = assertThrows(BlueprintValidationException.class, () -> validateHostGroupsMatch(request, requirements.keySet())); assertTrue(e.getMessage().contains("compute")); Set.of("master", "worker").forEach(hostGroup -> assertFalse(e.getMessage().contains(hostGroup), hostGroup)); }
@Test public void rejectsUnknownHostGroup() { Set<HostGroup> request = Set.of( hostGroup(">OK<", 1), hostGroup("unknown", 2) ); Map<String, InstanceCount> requirements = Map.of( ">OK<", InstanceCount.ONE_OR_MORE ); Exception e = assertThrows(BlueprintValidationException.class, () -> validateHostGroupsMatch(request, requirements.keySet())); assertTrue(e.getMessage().contains("unknown")); assertFalse(e.getMessage().contains(">OK<")); }