Handle empty package name

Closes gh-830
This commit is contained in:
Stephane Nicoll 2019-02-14 10:00:58 +01:00
parent 75307eab0f
commit f18c08f88f
2 changed files with 15 additions and 0 deletions

View File

@ -108,6 +108,9 @@ public class InitializrConfiguration {
return defaultPackageName;
}
String candidate = cleanPackageName(packageName);
if (!StringUtils.hasText(candidate)) {
return defaultPackageName;
}
if (hasInvalidChar(candidate.replace(".", ""))
|| this.env.invalidPackageNames.contains(candidate)) {
return defaultPackageName;

View File

@ -163,6 +163,18 @@ class InitializrConfigurationTests {
.isEqualTo("com.example");
}
@Test
void generatePackageNameDot() {
assertThat(this.properties.cleanPackageName(".", "com.example"))
.isEqualTo("com.example");
}
@Test
void generatePackageNameWhitespaces() {
assertThat(this.properties.cleanPackageName(" ", "com.example"))
.isEqualTo("com.example");
}
@Test
void generatePackageNameInvalidStartCharacter() {
assertThat(this.properties.cleanPackageName("0com.foo", "com.example"))