mirror of
https://gitee.com/dcren/initializr.git
synced 2025-07-17 19:37:35 +08:00
Polish "Identify reserved keywords in package name"
See gh-1018
This commit is contained in:
parent
e72b187d17
commit
9143e96b01
@ -16,14 +16,9 @@
|
|||||||
|
|
||||||
package io.spring.initializr.metadata;
|
package io.spring.initializr.metadata;
|
||||||
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.stream.Stream;
|
|
||||||
|
|
||||||
import io.spring.initializr.generator.version.Version;
|
import io.spring.initializr.generator.version.Version;
|
||||||
import io.spring.initializr.metadata.InitializrConfiguration.Env.Kotlin;
|
import io.spring.initializr.metadata.InitializrConfiguration.Env.Kotlin;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.jupiter.params.ParameterizedTest;
|
|
||||||
import org.junit.jupiter.params.provider.MethodSource;
|
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
|
||||||
@ -35,14 +30,6 @@ import static org.assertj.core.api.Assertions.assertThat;
|
|||||||
*/
|
*/
|
||||||
class InitializrConfigurationTests {
|
class InitializrConfigurationTests {
|
||||||
|
|
||||||
// Taken from https://docs.oracle.com/javase/specs/jls/se8/html/jls-3.html#jls-3.9
|
|
||||||
private static final String[] RESERVED_KEYWORDS = { "abstract", "assert", "boolean", "break", "byte", "case",
|
|
||||||
"catch", "char", "class", "const", "continue", "default", "do", "double", "else", "enum", "extends",
|
|
||||||
"false", "final", "finally", "float", "for", "goto", "if", "implements", "import", "instanceof", "int",
|
|
||||||
"interface", "long", "native", "new", "null", "package", "private", "protected", "public", "return",
|
|
||||||
"short", "static", "strictfp", "super", "switch", "synchronized", "this", "throw", "throws", "transient",
|
|
||||||
"try", "true", "void", "volatile", "while" };
|
|
||||||
|
|
||||||
private final InitializrConfiguration properties = new InitializrConfiguration();
|
private final InitializrConfiguration properties = new InitializrConfiguration();
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -185,35 +172,24 @@ class InitializrConfigurationTests {
|
|||||||
assertThat(this.properties.cleanPackageName("org.springframework", "com.example")).isEqualTo("com.example");
|
assertThat(this.properties.cleanPackageName("org.springframework", "com.example")).isEqualTo("com.example");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ParameterizedTest
|
@Test
|
||||||
@MethodSource("reservedKeywords")
|
void generatePackageNameReservedKeywordsMiddleOfPackageName() {
|
||||||
void generatePackageNameReservedKeywordsMiddleOfPackageName(final String keyword) {
|
assertThat(this.properties.cleanPackageName("com.return.foo", "com.example")).isEqualTo("com.example");
|
||||||
final String badPackageName = String.format("com.%s.foo", keyword);
|
|
||||||
assertThat(this.properties.cleanPackageName(badPackageName, "com.example")).isEqualTo("com.example");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ParameterizedTest
|
@Test
|
||||||
@MethodSource("reservedKeywords")
|
void generatePackageNameReservedKeywordsStartOfPackageName() {
|
||||||
void generatePackageNameReservedKeywordsStartOfPackageName(final String keyword) {
|
assertThat(this.properties.cleanPackageName("false.com.foo", "com.example")).isEqualTo("com.example");
|
||||||
final String badPackageName = String.format("%s.com.foo", keyword);
|
|
||||||
assertThat(this.properties.cleanPackageName(badPackageName, "com.example")).isEqualTo("com.example");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ParameterizedTest
|
@Test
|
||||||
@MethodSource("reservedKeywords")
|
void generatePackageNameReservedKeywordsEndOfPackageName() {
|
||||||
void generatePackageNameReservedKeywordsEndOfPackageName(final String keyword) {
|
assertThat(this.properties.cleanPackageName("com.foo.null", "com.example")).isEqualTo("com.example");
|
||||||
final String badPackageName = String.format("com.foo.%s", keyword);
|
|
||||||
assertThat(this.properties.cleanPackageName(badPackageName, "com.example")).isEqualTo("com.example");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ParameterizedTest
|
@Test
|
||||||
@MethodSource("reservedKeywords")
|
void generatePackageNameReservedKeywordsEntirePackageName() {
|
||||||
void generatePackageNameReservedKeywordsEntirePackageName(final String keyword) {
|
assertThat(this.properties.cleanPackageName("public", "com.example")).isEqualTo("com.example");
|
||||||
assertThat(this.properties.cleanPackageName(keyword, "com.example")).isEqualTo("com.example");
|
|
||||||
}
|
|
||||||
|
|
||||||
private static Stream<String> reservedKeywords() {
|
|
||||||
return Arrays.stream(RESERVED_KEYWORDS);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
Loading…
Reference in New Issue
Block a user