Skip to content

Commit a4c2154

Browse files
committed
[Core] Rerun formatter returns / rather then .
When scanning `path/to/com/` containing a resource named `path/to/com/example/app/app.feature` the middle package `example/app` would be rendered as `example.app` as the implementation would use `determineSubpackageName` rather then `determineSubpackagePath`. Fixes #1892
1 parent 5dd3802 commit a4c2154

File tree

3 files changed

+85
-5
lines changed

3 files changed

+85
-5
lines changed

CHANGELOG.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
1010
### Added
1111
* [Core] CLI should search classpath root by default ([#1889](https://github.com/cucumber/cucumber-jvm/pull/1889) M.P. Korstanje)
1212
* [Core] Improve error message when incompatible Plugins are used
13+
1314
### Changed
1415

1516
### Deprecated
@@ -20,7 +21,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
2021
* [Core] TestCaseState should be PASSED by default ([#1888](https://github.com/cucumber/cucumber-jvm/pull/1888) M.P. Korstanje)
2122
* As a result `Scenario.getState` will return `PASSED` rather then
2223
`UNDEFINED` prior to the execution of the first step of a scenario.
23-
24+
* [Core] Rerun formatter returns `/` rather then `.` ([#1892](https://github.com/cucumber/cucumber-jvm/issues/1892) M.P. Korstanje)
25+
2426
## [5.2.0] (2020-02-06)
2527

2628
### Added

core/src/main/java/io/cucumber/core/resource/ClasspathSupport.java

+8-1
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,15 @@ static String determinePackageName(Path baseDir, String basePackageName, Path cl
8585
.collect(joining(PACKAGE_SEPARATOR_STRING));
8686
}
8787

88+
89+
private static String determineSubpackagePath(Path baseDir, Path resource) {
90+
Path relativePath = baseDir.relativize(resource.getParent());
91+
String pathSeparator = baseDir.getFileSystem().getSeparator();
92+
return relativePath.toString().replace(pathSeparator, RESOURCE_SEPARATOR_STRING);
93+
}
94+
8895
static URI determineClasspathResourceUri(Path baseDir, String basePackagePath, Path resource) {
89-
String subPackageName = determineSubpackageName(baseDir, resource);
96+
String subPackageName = determineSubpackagePath(baseDir, resource);
9097
String resourceName = resource.getFileName().toString();
9198
String classpathResourcePath = of(basePackagePath, subPackageName, resourceName)
9299
.filter(value -> !value.isEmpty()) // default package .

core/src/test/java/io/cucumber/core/resource/ClasspathSupportTest.java

+74-3
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ void packageName() {
1515
URI classpathResourceUri = URI.create("classpath:com/example");
1616
String packageName = ClasspathSupport.packageName(classpathResourceUri);
1717
assertEquals("com.example", packageName);
18-
1918
}
2019

2120
@Test
@@ -24,12 +23,84 @@ void packageNameOfResource() {
2423
assertEquals("com.example", packageName);
2524
}
2625

26+
@Test
27+
void determinePackageName() {
28+
Path baseDir = Paths.get("path", "to", "com", "example", "app");
29+
String basePackageName = "com.example.app";
30+
Path classFile = Paths.get("path", "to", "com", "example", "app", "App.class");
31+
String packageName = ClasspathSupport.determinePackageName(baseDir, basePackageName, classFile);
32+
assertEquals("com.example.app", packageName);
33+
}
34+
35+
@Test
36+
void determinePackageNameFromRootPackage() {
37+
Path baseDir = Paths.get("path", "to");
38+
String basePackageName = "";
39+
Path classFile = Paths.get("path", "to", "com", "example", "app", "App.class");
40+
String packageName = ClasspathSupport.determinePackageName(baseDir, basePackageName, classFile);
41+
assertEquals("com.example.app", packageName);
42+
}
43+
44+
@Test
45+
void determinePackageNameFromComPackage() {
46+
Path baseDir = Paths.get("path", "to", "com");
47+
String basePackageName = "com";
48+
Path classFile = Paths.get("path", "to", "com", "example", "app", "App.class");
49+
String packageName = ClasspathSupport.determinePackageName(baseDir, basePackageName, classFile);
50+
assertEquals("com.example.app", packageName);
51+
}
52+
2753
@Test
2854
void determineFullyQualifiedClassName() {
2955
Path baseDir = Paths.get("path", "to", "com", "example", "app");
30-
String basePackageName = "com.example";
56+
String basePackageName = "com.example.app";
57+
Path classFile = Paths.get("path", "to", "com", "example", "app", "App.class");
58+
String fqn = ClasspathSupport.determineFullyQualifiedClassName(baseDir, basePackageName, classFile);
59+
assertEquals("com.example.app.App", fqn);
60+
}
61+
62+
@Test
63+
void determineFullyQualifiedClassNameFromRootPackage() {
64+
Path baseDir = Paths.get("path", "to");
65+
String basePackageName = "";
66+
Path classFile = Paths.get("path", "to", "com", "example", "app", "App.class");
67+
String fqn = ClasspathSupport.determineFullyQualifiedClassName(baseDir, basePackageName, classFile);
68+
assertEquals("com.example.app.App", fqn);
69+
}
70+
71+
@Test
72+
void determineFullyQualifiedClassNameFromComPackage() {
73+
Path baseDir = Paths.get("path", "to", "com");
74+
String basePackageName = "com";
3175
Path classFile = Paths.get("path", "to", "com", "example", "app", "App.class");
3276
String fqn = ClasspathSupport.determineFullyQualifiedClassName(baseDir, basePackageName, classFile);
33-
assertEquals("com.example.App", fqn);
77+
assertEquals("com.example.app.App", fqn);
78+
}
79+
80+
@Test
81+
void determineFullyQualifiedResourceName() {
82+
Path baseDir = Paths.get("path", "to", "com", "example", "app");
83+
String basePackageName = "com/example/app";
84+
Path resourceFile = Paths.get("path", "to", "com", "example", "app", "app.feature");
85+
URI fqn = ClasspathSupport.determineClasspathResourceUri(baseDir, basePackageName, resourceFile);
86+
assertEquals(URI.create("classpath:com/example/app/app.feature"), fqn);
87+
}
88+
89+
@Test
90+
void determineFullyQualifiedResourceNameFromRootPackage() {
91+
Path baseDir = Paths.get("path", "to");
92+
String basePackageName = "";
93+
Path resourceFile = Paths.get("path", "to", "com", "example", "app", "app.feature");
94+
URI fqn = ClasspathSupport.determineClasspathResourceUri(baseDir, basePackageName, resourceFile);
95+
assertEquals(URI.create("classpath:com/example/app/app.feature"), fqn);
96+
}
97+
98+
@Test
99+
void determineFullyQualifiedResourceNameFromComPackage() {
100+
Path baseDir = Paths.get("path", "to", "com");
101+
String basePackageName = "com";
102+
Path resourceFile = Paths.get("path", "to", "com", "example", "app", "app.feature");
103+
URI fqn = ClasspathSupport.determineClasspathResourceUri(baseDir, basePackageName, resourceFile);
104+
assertEquals(URI.create("classpath:com/example/app/app.feature"), fqn);
34105
}
35106
}

0 commit comments

Comments
 (0)