Merge pull request #9916 from bjornlindstrom:gh-9713

* pr/9916:
  Polish "Fix handling of empty/null arguments"
  Fix handling of empty/null arguments
pull/10338/merge
Stephane Nicoll 7 years ago
commit 3da9406435

@ -18,6 +18,7 @@ package org.springframework.boot.maven;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.Objects;
import org.codehaus.plexus.util.cli.CommandLineUtils;
@ -31,14 +32,16 @@ class RunArguments {
private static final String[] NO_ARGS = {};
private final LinkedList<String> args;
private final LinkedList<String> args = new LinkedList<>();
RunArguments(String arguments) {
this(parseArgs(arguments));
}
RunArguments(String[] args) {
this.args = new LinkedList<>(Arrays.asList(args));
if (args != null) {
Arrays.stream(args).filter(Objects::nonNull).forEach(this.args::add);
}
}
public LinkedList<String> getArgs() {

@ -1,5 +1,5 @@
/*
* Copyright 2012-2016 the original author or authors.
* Copyright 2012-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -34,6 +34,27 @@ public class RunArgumentsTests {
assertThat(args.length).isEqualTo(0);
}
@Test
public void parseNullArray() {
String[] args = new RunArguments((String[]) null).asArray();
assertThat(args).isNotNull();
assertThat(args.length).isEqualTo(0);
}
@Test
public void parseArrayContainingNullValue() {
String[] args = new RunArguments(new String[]{"foo", null, "bar"}).asArray();
assertThat(args).isNotNull();
assertThat(args).containsOnly("foo", "bar");
}
@Test
public void parseArrayContainingEmptyValue() {
String[] args = new RunArguments(new String[]{"foo", "", "bar"}).asArray();
assertThat(args).isNotNull();
assertThat(args).containsOnly("foo", "", "bar");
}
@Test
public void parseEmpty() {
String[] args = parseArgs(" ");

Loading…
Cancel
Save