Commit 3da94064 authored by Stephane Nicoll's avatar Stephane Nicoll

Merge pull request #9916 from bjornlindstrom:gh-9713

* pr/9916:
  Polish "Fix handling of empty/null arguments"
  Fix handling of empty/null arguments
parents 0e46d0f5 83510424
......@@ -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() {
......
/*
* 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(" ");
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment