@Test public void wrap_error() { expected.expect(IllegalStateException.class); expected.expectMessage("Unsupported mode: BOOM"); SimpleConverter wrappedConverter = new SimpleConverter(null); String configKey = "sonar.slang.converter.validation"; ASTConverterValidation.wrap(wrappedConverter, new SimpleConfig(configKey, "BOOM")); }
public static ASTConverter wrap(ASTConverter converter, Configuration configuration) { String mode = configuration.get("sonar.slang.converter.validation").orElse(null); if (mode == null) { return converter; } else if (mode.equals("throw")) { return new ASTConverterValidation(converter, ValidationMode.THROW_EXCEPTION); } else if (mode.equals("log")) { return new ASTConverterValidation(converter, ValidationMode.LOG_ERROR); } else { throw new IllegalStateException("Unsupported mode: " + mode); } }
ASTConverterValidation implements ASTConverter { public static ASTConverter wrap(ASTConverter converter, Configuration configuration) { String mode = configuration.get("sonar.slang.converter.validation").orElse(null); if (mode == null) { return converter; } else if (mode.equals("throw")) { return new ASTConverterValidation(converter, ValidationMode.THROW_EXCEPTION); } else if (mode.equals("log")) { return new ASTConverterValidation(converter, ValidationMode.LOG_ERROR); } else { throw new IllegalStateException("Unsupported mode: " + mode); } } }
ASTConverterValidation implements ASTConverter { public static ASTConverter wrap(ASTConverter converter, Configuration configuration) { String mode = configuration.get("sonar.slang.converter.validation").orElse(null); if (mode == null) { return converter; } else if (mode.equals("throw")) { return new ASTConverterValidation(converter, ValidationMode.THROW_EXCEPTION); } else if (mode.equals("log")) { return new ASTConverterValidation(converter, ValidationMode.LOG_ERROR); } else { throw new IllegalStateException("Unsupported mode: " + mode); } } ASTConverterValidation(ASTConverter wrapped, ValidationMode mode); }
ASTConverterValidation implements ASTConverter { public static ASTConverter wrap(ASTConverter converter, Configuration configuration) { String mode = configuration.get("sonar.slang.converter.validation").orElse(null); if (mode == null) { return converter; } else if (mode.equals("throw")) { return new ASTConverterValidation(converter, ValidationMode.THROW_EXCEPTION); } else if (mode.equals("log")) { return new ASTConverterValidation(converter, ValidationMode.LOG_ERROR); } else { throw new IllegalStateException("Unsupported mode: " + mode); } } ASTConverterValidation(ASTConverter wrapped, ValidationMode mode); static ASTConverter wrap(ASTConverter converter, Configuration configuration); @Override Tree parse(String content); @Override void terminate(); }
ASTConverterValidation implements ASTConverter { public static ASTConverter wrap(ASTConverter converter, Configuration configuration) { String mode = configuration.get("sonar.slang.converter.validation").orElse(null); if (mode == null) { return converter; } else if (mode.equals("throw")) { return new ASTConverterValidation(converter, ValidationMode.THROW_EXCEPTION); } else if (mode.equals("log")) { return new ASTConverterValidation(converter, ValidationMode.LOG_ERROR); } else { throw new IllegalStateException("Unsupported mode: " + mode); } } ASTConverterValidation(ASTConverter wrapped, ValidationMode mode); static ASTConverter wrap(ASTConverter converter, Configuration configuration); @Override Tree parse(String content); @Override void terminate();  }