Skip to content

Commit cf1a6e3

Browse files
committed
✨ Add new method to PathOrUrl called toUnixString().
This is related to issue #32. It will be used in the rest-services.client code.
1 parent 8697a0e commit cf1a6e3

2 files changed

Lines changed: 27 additions & 2 deletions

File tree

fluentforms/core/src/main/java/com/_4point/aem/fluentforms/api/PathOrUrl.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,20 @@ public String toString() {
293293
}
294294
}
295295

296+
public String toUnixString() {
297+
if (this.isPath()) {
298+
String stringVersion = this.path.toString();
299+
return this.path.getFileSystem().getSeparator().equals("\\") ? stringVersion.replace('\\', '/')
300+
: stringVersion;
301+
} else if (this.isUrl()) {
302+
return this.url.toString();
303+
} else if (this.isCrxUrl()) {
304+
return urlToCrx(this.url);
305+
} else {
306+
throw new IllegalStateException("PathOrUrl object is neither Path nor URL!"); // Should never happen.
307+
}
308+
}
309+
296310
/**
297311
* Convert a crx Url into a file: URL for storage.
298312
*

fluentforms/core/src/test/java/com/_4point/aem/fluentforms/api/PathOrUrlTest.java

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@
1616
import org.junit.jupiter.api.condition.EnabledOnOs;
1717
import org.junit.jupiter.api.condition.OS;
1818
import org.junit.jupiter.params.ParameterizedTest;
19-
import org.junit.jupiter.params.provider.EnumSource;
20-
import org.junit.jupiter.params.provider.ValueSource;
19+
import org.junit.jupiter.params.provider.*;
2120

2221
import com._4point.aem.fluentforms.impl.CrxUrlHandler;
2322

@@ -314,4 +313,16 @@ void test_convertRelativePathToRelativeUrl_Abs() throws Exception {
314313
assertThat(msg, containsStringIgnoringCase("Path must be relative"));
315314
}
316315

316+
@ParameterizedTest
317+
@CsvSource( { "C:/foo/bar,C:/foo/bar", "foo,foo", "foo/bar,foo/bar", "C:\\foo\\bar,C:/foo/bar", "\\\\foo\\bar,//foo/bar/", "C:/foo/bar/,C:/foo/bar", "\\\\foo\\bar\\,//foo/bar/" })
318+
void testToUnixString(String path, String expected) {
319+
PathOrUrl result = PathOrUrl.from(Path.of(path));
320+
assertTrue(result.isPath(), "Expected that isPath() would be true");
321+
assertFalse(result.isUrl(), "Expected that isUrl() would be false");
322+
assertFalse(result.isCrxUrl(), "Expected that isCrxUrl() would be false");
323+
// Path expected = Paths.get(path);
324+
assertEquals(expected, result.toUnixString());
325+
}
326+
327+
317328
}

0 commit comments

Comments
 (0)