chorus = new Chorus(args.split(" ")); } catch (InterpreterPropertyException e) { throw new RuntimeException("Error with Chorus command line " + e.getMessage());
public static void main(String[] args) { boolean proceed = handleVersionOrHelpSwitches(args); if ( proceed ) { boolean success = false; try { Chorus chorus = new Chorus(args); success = chorus.run(); } catch (InterpreterPropertyException e) { ChorusOut.err.println(e.getMessage()); ChorusOut.err.print(ChorusConfigProperty.getHelpText()); } catch (Throwable t) { ChorusOut.err.println("Chorus encountered an error and had to exit"); ChorusOut.err.print(t.toString()); } //We should exit with a code between 0-255 since this is the valid range for unix exit statuses //(windows supports signed integer exit status, unix does not) //choosing the most obvious, 0 = success, 1 = failure, we could expand on this if needed int exitCode = success ? 0 : 1; System.exit(exitCode); } }
@Test public void testCannotSetMoreThanMaxValues() { ConfigurationProperty propertyWithMinValues = new TestProperty(TestConfigProperty.HANDLER_PACKAGES) { public int getMaxValueCount() { return 1; } }; ConfigReader c = new ConfigReader(Collections.singletonList(propertyWithMinValues), new String[] { "-h", "onevalue", "twovalues" }); try { c.readConfiguration(); } catch (InterpreterPropertyException e) { assertTrue("contains At Most 1", e.getMessage().contains("At most 1 value(s) must be supplied")); return; } fail("Must complain when more than max vals set"); }
@Test public void testCannotSetLessThanMinimumValues() { ConfigurationProperty propertyWithMinValues = new TestProperty(TestConfigProperty.HANDLER_PACKAGES) { public int getMinValueCount() { return 2; } }; ConfigReader c = new ConfigReader(Collections.singletonList(propertyWithMinValues), new String[] { "-h", "onevalue" }); try { c.readConfiguration(); } catch (InterpreterPropertyException e) { assertTrue("contains At Least 2", e.getMessage().contains("At least 2 value(s) must be supplied")); return; } fail("Must complain when less than min vals set"); }
@Test public void mandatoryPropertyMustBeSet() { System.clearProperty(TestConfigProperty.FEATURE_PATHS.getSystemProperty()); //in case set String[] switches = new String[] { "-d" }; ConfigReader c = new ConfigReader(TestConfigProperty.getAll(), switches); try { c.readConfiguration(); } catch (InterpreterPropertyException e) { assertTrue(e.getMessage().contains("Mandatory property featurePaths was not set")); return; } fail("Must require mandatory -f property value"); }