Move source file extension to Language abstraction

Closes gh-995
This commit is contained in:
Stephane Nicoll
2019-08-31 08:39:13 +02:00
parent cff60c397d
commit 595050258c
21 changed files with 126 additions and 85 deletions

View File

@@ -40,12 +40,11 @@ public abstract class AbstractJvmModuleAssert<SELF extends AbstractJvmModuleAsse
private final String sourceFileExtension;
protected AbstractJvmModuleAssert(Path projectDirectory, Language language, String sourceFileExtension,
Class<?> selfType) {
protected AbstractJvmModuleAssert(Path projectDirectory, Language language, Class<?> selfType) {
super(projectDirectory, selfType);
this.mainDirectory = new SourceStructure(projectDirectory.resolve("src/main/"), language.id());
this.testDirectory = new SourceStructure(projectDirectory.resolve("src/test/"), language.id());
this.sourceFileExtension = sourceFileExtension;
this.mainDirectory = new SourceStructure(projectDirectory.resolve("src/main/"), language);
this.testDirectory = new SourceStructure(projectDirectory.resolve("src/test/"), language);
this.sourceFileExtension = language.sourceFileExtension();
}
/**

View File

@@ -37,16 +37,15 @@ public abstract class AbstractModuleAssert<SELF extends AbstractModuleAssert<SEL
/**
* Return a {@link JvmModuleAssert JVM module} assertion for the specified
* {@link Language} and file source extension, to allow chaining of jvm
* module-specific assertions from this call.
* {@link Language}, to allow chaining of jvm module-specific assertions from this
* call.
* <p>
* Does not validate that the module has source code for the specified language.
* @param language the language of the module
* @param sourceFileExtension the source file extension
* @return a {@link JvmModuleAssert} for the specified language
*/
public JvmModuleAssert asJvmModule(Language language, String sourceFileExtension) {
return new JvmModuleAssert(this.actual, language, sourceFileExtension);
public JvmModuleAssert asJvmModule(Language language) {
return new JvmModuleAssert(this.actual, language);
}
/**

View File

@@ -27,8 +27,8 @@ import io.spring.initializr.generator.language.Language;
*/
public class JvmModuleAssert extends AbstractJvmModuleAssert<JvmModuleAssert> {
public JvmModuleAssert(Path projectDirectory, Language language, String sourceFileExtension) {
super(projectDirectory, language, sourceFileExtension, JvmModuleAssert.class);
public JvmModuleAssert(Path projectDirectory, Language language) {
super(projectDirectory, language, JvmModuleAssert.class);
}
}

View File

@@ -137,7 +137,7 @@ class JvmModuleAssertTests {
}
private AssertProvider<AbstractJvmModuleAssert> forJavaProject(Path root) {
return () -> new JvmModuleAssert(root, JAVA_LANGUAGE, "java");
return () -> new JvmModuleAssert(root, JAVA_LANGUAGE);
}
private void createFile(Path root, String path) throws IOException {

View File

@@ -127,7 +127,7 @@ class ModuleAssertTests {
@Test
void asJavaProject(@TempDir Path dir) throws IOException {
createFiles(dir, "src/main/java/com/example/Test.java");
assertThat(forDirectory(dir)).asJvmModule(new JavaLanguage(), "java").hasMainPackage("com.example")
assertThat(forDirectory(dir)).asJvmModule(new JavaLanguage()).hasMainPackage("com.example")
.hasMainSource("com.example", "Test");
}