public static ProcessEntryPoint createForArguments(String[] args) { Props props = ConfigurationUtils.loadPropsFromCommandLineArgs(args); ProcessCommands commands = new DefaultProcessCommands( props.nonNullValueAsFile(PROPERTY_SHARED_PATH), Integer.parseInt(props.nonNullValue(PROPERTY_PROCESS_INDEX))); return new ProcessEntryPoint(props, new SystemExit(), commands); }
@Test public void loadPropsFromCommandLineArgs_missing_argument() { try { ConfigurationUtils.loadPropsFromCommandLineArgs(new String[0]); fail(); } catch (IllegalArgumentException e) { assertThat(e.getMessage()).startsWith("Only a single command-line argument is accepted"); } }
@Test public void loadPropsFromCommandLineArgs_load_properties_from_file() throws Exception { File propsFile = temp.newFile(); FileUtils.write(propsFile, "foo=bar"); Props result = ConfigurationUtils.loadPropsFromCommandLineArgs(new String[] {propsFile.getAbsolutePath()}); assertThat(result.value("foo")).isEqualTo("bar"); assertThat(result.rawProperties()).hasSize(1); }
@Test public void loadPropsFromCommandLineArgs_file_does_not_exist() throws Exception { File propsFile = temp.newFile(); FileUtils.deleteQuietly(propsFile); try { ConfigurationUtils.loadPropsFromCommandLineArgs(new String[] {propsFile.getAbsolutePath()}); fail(); } catch (IllegalStateException e) { assertThat(e) .hasMessage("Could not read properties from file: " + propsFile.getAbsolutePath()); } }