DefaultOperatorContext implements OperatorContext { @Override public void register(Operator operator) { log.info("Registering operator " + operator.getName() + " which will respond to suffixes " + Arrays .toString(operator.getTokens())); for (Operator item : operators) { for (String token : item.getTokens()) { for (String newToken : operator.getTokens()) { if (newToken.equals(token)) { throw new DuplicateOperatorException(item, token); } } } } operators.add(operator); } DefaultOperatorContext();  DefaultOperatorContext(boolean registerDefaults); @Override void register(Operator operator); @Override Operator getBySuffix(String suffix);  }
@Test(expectedExceptions = DuplicateOperatorException.class) public void testRegisteringDuplicates() { final DefaultOperatorContext context = new DefaultOperatorContext(); context.register(new ImmutableOperator("x", 1, null, "X", "A")); context.register(new ImmutableOperator("y", 1, null, "B", "A")); }