Skip to content

Commit 89ef372

Browse files
committed
test: Add/refactor test for base package calculation
1 parent 0c57214 commit 89ef372

File tree

1 file changed

+25
-9
lines changed

1 file changed

+25
-9
lines changed

components/sbm-core/src/test/java/org/springframework/sbm/build/impl/JavaSourceSetImplTest.java

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
package org.springframework.sbm.build.impl;
1717

1818
import org.springframework.sbm.build.api.JavaSourceSet;
19+
import org.springframework.sbm.engine.context.ProjectContext;
1920
import org.springframework.sbm.java.api.JavaSource;
2021
import org.springframework.sbm.java.api.JavaSourceLocation;
2122
import org.springframework.sbm.project.resource.SbmApplicationProperties;
@@ -29,6 +30,25 @@
2930

3031
class JavaSourceSetImplTest {
3132

33+
@Test
34+
void getBasePackageShouldUseDefaultPackageApplicationPropertyWhenNoSourcesExist() {
35+
SbmApplicationProperties sbmApplicationProperties = new SbmApplicationProperties();
36+
sbmApplicationProperties.setDefaultBasePackage("some.default.packagename");
37+
38+
ProjectContext context = TestProjectContext.buildProjectContext()
39+
.withApplicationProperties(sbmApplicationProperties)
40+
.build();
41+
42+
String packageName = context
43+
.getApplicationModules()
44+
.getRootModule()
45+
.getMainJavaSourceSet()
46+
.getJavaSourceLocation()
47+
.getPackageName();
48+
49+
assertThat(packageName).isEqualTo("some.default.packagename");
50+
}
51+
3252
@Test
3353
void testGetBasePackageShouldReturnDistinctRootPackageIfExists() {
3454
final String sourceCode1 =
@@ -53,32 +73,28 @@ void testGetBasePackageShouldReturnDistinctRootPackageIfExists() {
5373
}
5474

5575
@Test
56-
void getBasePackageShouldReturnDefaultIfNoDistinctRootPackageExists() {
76+
void getBasePackageShouldReturnEmptyPackageIfNoOtherCommonBasePackageExists() {
5777
final String sourceCode1 =
58-
"package org.springframework.sbm.level1; " +
78+
"package org1.springframework.sbm.level1; " +
5979
"public class Class1 { " +
6080
"} " +
6181
"";
6282
final String sourceCode2 =
63-
"package org.springframework.sbm.anotherLevel1; " +
83+
"package org2.springframework.sbm.anotherLevel1; " +
6484
"public class Class2 { " +
6585
"} " +
6686
"";
6787

68-
SbmApplicationProperties sbmApplicationProperties = new SbmApplicationProperties();
69-
sbmApplicationProperties.setDefaultBasePackage("org.springframework.sbm");
70-
7188
JavaSourceSet sut = TestProjectContext.buildProjectContext()
7289
.withDummyRootBuildFile()
73-
.withApplicationProperties(sbmApplicationProperties)
7490
.withJavaSources(sourceCode1, sourceCode2)
7591
.build()
7692
.getApplicationModules()
7793
.getRootModule()
7894
.getMainJavaSourceSet();
7995

8096
JavaSourceLocation location = sut.getJavaSourceLocation();
81-
assertThat(location.getPackageName()).isEqualTo("org.springframework.sbm");
97+
assertThat(location.getPackageName()).isEqualTo("");
8298
assertThat(location.getSourceFolder()).isEqualTo(TestProjectContext.getDefaultProjectRoot().resolve("src/main/java"));
8399
}
84100

@@ -113,7 +129,7 @@ void testGetBasePackageWithDefaultPackageAsRootShouldReturnDefaultPackage() {
113129
"public class Class1 {}";
114130
final String sourceCode2 =
115131
"package org.springframework.sbm.level1; " +
116-
"public class Class2 {}";
132+
"public class Class2 {}";
117133

118134
JavaSourceSet sut = TestProjectContext.buildProjectContext()
119135
.withJavaSources(sourceCode1, sourceCode2)

0 commit comments

Comments
 (0)