CommandLineArguments { static CommandLineArguments build(String[] args) { CommandLineArguments cmdArgs; try { cmdArgs = SingleCommand.singleCommand(CommandLineArguments.class).parse(args); } catch (Exception e) { System.err.println(e.getMessage()); System.err.println("Use --help to show usage.\n"); return null; } if (cmdArgs.helpOption.showHelpIfRequested()) { return null; } if (cmdArgs.endpointArg != null) { if (cmdArgs.hostArg != null) { System.err.println("Cannot set both '--host' and '--endpoint' "); return null; } try { URL url = new URL(cmdArgs.endpointArg); } catch (MalformedURLException e) { e.printStackTrace(System.err); return null; } } else { if (cmdArgs.hostArg == null) { System.err.println("'--host' or '--endpoint' not set."); return null; } } if (cmdArgs.priorityArg != null && ! checkPriorityFlag(cmdArgs.priorityArg)) { return null; } for (String header : cmdArgs.headers) { try { cmdArgs.parsedHeaders.add(BasicLineParser.parseHeader(header, null)); } catch (ParseException e) { System.err.printf("Invalid header: '%s' (%s)%n", header, e.getMessage()); return null; } } if (cmdArgs.privateKeyPath == null && cmdArgs.certificatePath != null || cmdArgs.privateKeyPath != null && cmdArgs.certificatePath == null) { System.err.println("Both '--privateKey' and '--certificate' must be set"); return null; } return cmdArgs; }  String getFile(); boolean getVerbose(); boolean getAddRootElementToXml();  }
@Test public void testRequiredFlags() { assertThat(CommandLineArguments.build(asArray()), is(nullValue())); add("file", "fileValue"); assertThat(CommandLineArguments.build(asArray()), is(nullValue())); args.clear(); addMinimum(); assertThat(CommandLineArguments.build(asArray()), is(not(nullValue()))); }
@Test public void testStreaming() { add("host", "hostValue"); add("file", null); assertThat(CommandLineArguments.build(asArray()), is(nullValue())); }
@Test public void testBrokenFlags() { addMinimum(); args.add("FOO"); assertThat(CommandLineArguments.build(asArray()), is(nullValue())); }
@Test public void testBadPriority() { addMinimum(); add("priority", "non existing"); assertThat(CommandLineArguments.build(asArray()), is(nullValue())); }
@Test public void testEndpointAndHost() { add("host", "myhost"); add("port", "2345"); add("endpoint", "http: CommandLineArguments arguments = CommandLineArguments.build(asArray()); assertThat(arguments, is(nullValue())); }