10
10
11
11
package org .junit .platform .engine .support .descriptor ;
12
12
13
+ import static org .apiguardian .api .API .Status .EXPERIMENTAL ;
13
14
import static org .apiguardian .api .API .Status .STABLE ;
14
15
15
16
import java .io .File ;
@@ -44,7 +45,7 @@ public class FileSource implements FileSystemSource {
44
45
* @param file the source file; must not be {@code null}
45
46
*/
46
47
public static FileSource from (File file ) {
47
- return canonicalized (file , null );
48
+ return from (file , null );
48
49
}
49
50
50
51
/**
@@ -55,20 +56,14 @@ public static FileSource from(File file) {
55
56
* @param filePosition the position in the source file; may be {@code null}
56
57
*/
57
58
public static FileSource from (File file , @ Nullable FilePosition filePosition ) {
58
- return canonicalized (file , filePosition );
59
- }
60
-
61
- /**
62
- * Create a new {@code FileSource} from an existing instance but with a different
63
- * {@link FilePosition}. This avoids redundant canonical path resolution.
64
- *
65
- * @param source the existing {@code FileSource}; must not be {@code null}
66
- * @param filePosition the new {@code FilePosition}; may be {@code null}
67
- * @return a new {@code FileSource} with same file and updated position
68
- */
69
- public static FileSource withPosition (FileSource source , @ Nullable FilePosition filePosition ) {
70
- Preconditions .notNull (source , "source must not be null" );
71
- return direct (source .file , filePosition );
59
+ Preconditions .notNull (file , "file must not be null" );
60
+ try {
61
+ File canonicalFile = file .getCanonicalFile ();
62
+ return new FileSource (canonicalFile , filePosition );
63
+ }
64
+ catch (IOException ex ) {
65
+ throw new JUnitException ("Failed to retrieve canonical path for file: " + file , ex );
66
+ }
72
67
}
73
68
74
69
private final File file ;
@@ -80,21 +75,6 @@ private FileSource(File file, @Nullable FilePosition filePosition) {
80
75
this .file = file ;
81
76
this .filePosition = filePosition ;
82
77
}
83
-
84
- private static FileSource canonicalized (File file , @ Nullable FilePosition filePosition ) {
85
- Preconditions .notNull (file , "file must not be null" );
86
- try {
87
- return new FileSource (file .getCanonicalFile (), filePosition );
88
- }
89
- catch (IOException ex ) {
90
- throw new JUnitException ("Failed to retrieve canonical path for file: " + file , ex );
91
- }
92
- }
93
-
94
- private static FileSource direct (File file , @ Nullable FilePosition filePosition ) {
95
- Preconditions .notNull (file , "file must not be null" );
96
- return new FileSource (file , filePosition );
97
- }
98
78
99
79
/**
100
80
* Get the {@link URI} for the source {@linkplain #getFile file}.
@@ -123,6 +103,20 @@ public final Optional<FilePosition> getPosition() {
123
103
return Optional .ofNullable (this .filePosition );
124
104
}
125
105
106
+ /**
107
+ * Return a new {@code FileSource} based on this instance but with a different
108
+ * {@link FilePosition}. This avoids redundant canonical path resolution
109
+ * by reusing the already-canonical file.
110
+ *
111
+ * @param filePosition the new {@code FilePosition}; must not be {@code null}
112
+ * @return a new {@code FileSource} with the same file and updated position
113
+ */
114
+ @ API (status = EXPERIMENTAL , since = "1.14" )
115
+ public FileSource withPosition (FilePosition filePosition ) {
116
+ Preconditions .notNull (filePosition , "position must not be null" );
117
+ return new FileSource (this .file , filePosition );
118
+ }
119
+
126
120
@ Override
127
121
public boolean equals (Object o ) {
128
122
if (this == o ) {
0 commit comments