### Question:
OperatorPolicyValidator implements RabbitClusterValidator { @Override public List<String> validate(final ClusterSpec clusterSpec) { final List<OperatorPolicySpec> policies = clusterSpec.getOperatorPolicies(); final List<String> errors = new ArrayList<>(); policies.forEach(policy -> { try { Pattern.compile(policy.getPattern()); } catch (final PatternSyntaxException ex) { errors.add(String.format("Invalid pattern for policy %s: %s", policy.getName(), ex.getMessage())); } if (!policy.getApplyTo().equals("queues")) { errors.add(String.format("Operator policy applyTo value must be 'queues', but operator policy %s had applyTo: %s", policy.getName(), policy.getApplyTo())); } }); return errors; }  @Override List<String> validate(final ClusterSpec clusterSpec);  }### Answer:
@Test public void testValidate_validSpec() { final List<OperatorPolicySpec> policies = Lists.newArrayList( new OperatorPolicySpec("vhost1", "name1", "pattern", "queues", POLICY_DEFINITION, 1L), new OperatorPolicySpec(" ); final ClusterSpec clusterSpec = buildClusterSpec(policies); assertTrue(validator.validate(clusterSpec).isEmpty()); }
@Test public void testValidate_invalidPattern() { final List<OperatorPolicySpec> policies = Lists.newArrayList( new OperatorPolicySpec("vhost1", "name1", "[[[[[[", "queues", POLICY_DEFINITION, 1L) ); final ClusterSpec clusterSpec = buildClusterSpec(policies); final List<String> errors = validator.validate(clusterSpec); assertEquals(1, errors.size()); assertTrue(errors.get(0).contains("pattern")); }
@Test public void testValidate_invalidApplyTo() { final List<OperatorPolicySpec> policies = Lists.newArrayList( new OperatorPolicySpec("vhost1", "name1", "pattern", "exchanges", POLICY_DEFINITION, 1L) ); final ClusterSpec clusterSpec = buildClusterSpec(policies); final List<String> errors = validator.validate(clusterSpec); assertEquals(1, errors.size()); assertTrue(errors.get(0).contains("applyTo")); }
@Test public void testValidate_multipleInvalid() { final List<OperatorPolicySpec> policies = Lists.newArrayList( new OperatorPolicySpec("vhost1", "name1", "[[[[[[", "queues", POLICY_DEFINITION, 1L), new OperatorPolicySpec("vhost1", "name1", "pattern", "exchanges", POLICY_DEFINITION, 1L) ); final ClusterSpec clusterSpec = buildClusterSpec(policies); final List<String> errors = validator.validate(clusterSpec); assertEquals(2, errors.size()); }