-
-
Notifications
You must be signed in to change notification settings - Fork 353
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Enable creation of packages with repeated simple names in qualif…
…ied name (#4770)
- Loading branch information
Showing
2 changed files
with
32 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
src/test/java/spoon/reflect/factory/PackageFactoryTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package spoon.reflect.factory; | ||
|
||
import static org.hamcrest.CoreMatchers.equalTo; | ||
import static org.hamcrest.CoreMatchers.sameInstance; | ||
import static org.hamcrest.MatcherAssert.assertThat; | ||
|
||
import spoon.Launcher; | ||
import spoon.reflect.declaration.CtPackage; | ||
import spoon.test.GitHubIssue; | ||
|
||
class PackageFactoryTest { | ||
|
||
@GitHubIssue(issueNumber = 4764, fixed = true) | ||
void getOrCreate_returnsNestedPackageStructure_whenQualifiedNameRepeatsSimpleName() { | ||
// contract: A qualified name that is simply repetitions of a single simple name results in the expected | ||
// nested package structure | ||
|
||
PackageFactory factory = new Launcher().getFactory().Package(); | ||
String topLevelPackageName = "spoon"; | ||
String nestedPackageName = topLevelPackageName + "." + topLevelPackageName; | ||
|
||
CtPackage packageWithDuplicatedSimpleNames = factory.getOrCreate(nestedPackageName); | ||
CtPackage topLevelPackage = factory.get(topLevelPackageName); | ||
|
||
assertThat(topLevelPackage.getQualifiedName(), equalTo(topLevelPackageName)); | ||
assertThat(packageWithDuplicatedSimpleNames.getQualifiedName(), equalTo(nestedPackageName)); | ||
|
||
assertThat(topLevelPackage.getPackage(topLevelPackageName), sameInstance(packageWithDuplicatedSimpleNames)); | ||
assertThat(packageWithDuplicatedSimpleNames.getParent(), sameInstance(topLevelPackage)); | ||
} | ||
} |