Polish "Fix handling of empty/null arguments"

Closes gh-9916
This commit is contained in:
Stephane Nicoll 2017-09-19 15:02:08 +02:00
parent 0867ac5777
commit 8351042469
2 changed files with 12 additions and 6 deletions

View File

@ -18,11 +18,10 @@ package org.springframework.boot.maven;
import java.util.Arrays; import java.util.Arrays;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.Objects;
import org.codehaus.plexus.util.cli.CommandLineUtils; import org.codehaus.plexus.util.cli.CommandLineUtils;
import org.springframework.util.StringUtils;
/** /**
* Parse and expose arguments specified in a single string. * Parse and expose arguments specified in a single string.
* *
@ -41,7 +40,7 @@ class RunArguments {
RunArguments(String[] args) { RunArguments(String[] args) {
if (args != null) { if (args != null) {
Arrays.stream(args).filter(StringUtils::hasLength).forEach(this.args::add); Arrays.stream(args).filter(Objects::nonNull).forEach(this.args::add);
} }
} }

View File

@ -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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -43,9 +43,16 @@ public class RunArgumentsTests {
@Test @Test
public void parseArrayContainingNullValue() { public void parseArrayContainingNullValue() {
String[] args = new RunArguments(new String[]{null}).asArray(); String[] args = new RunArguments(new String[]{"foo", null, "bar"}).asArray();
assertThat(args).isNotNull(); assertThat(args).isNotNull();
assertThat(args.length).isEqualTo(0); 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 @Test