@@ -53,17 +53,17 @@ public class ResourceHarness {
53
53
File folderDontUseDirectly ;
54
54
55
55
/** Returns the root folder (canonicalized to fix OS X issue) */
56
- protected File rootFolder () {
56
+ public File rootFolder () {
57
57
return Errors .rethrow ().get (() -> folderDontUseDirectly .getCanonicalFile ());
58
58
}
59
59
60
60
/** Returns a new child of the root folder. */
61
- protected File newFile (String subpath ) {
61
+ public File newFile (String subpath ) {
62
62
return new File (rootFolder (), subpath );
63
63
}
64
64
65
65
/** Creates and returns a new child-folder of the root folder. */
66
- protected File newFolder (String subpath ) throws IOException {
66
+ public File newFolder (String subpath ) throws IOException {
67
67
File targetDir = newFile (subpath );
68
68
if (!targetDir .mkdir ()) {
69
69
throw new IOException ("Failed to create " + targetDir );
@@ -77,7 +77,7 @@ protected File newFolder(String subpath) throws IOException {
77
77
* @return the list of resources in that directory on the classpath, unix-style file separators
78
78
* @throws IOException
79
79
*/
80
- protected List <String > listTestResources (String path ) throws IOException {
80
+ public List <String > listTestResources (String path ) throws IOException {
81
81
// add leading slash if required, otherwise resources won't be found
82
82
if (!path .startsWith ("/" )) {
83
83
path = path + "/" ;
@@ -102,19 +102,19 @@ protected List<String> listTestResources(String path) throws IOException {
102
102
return filenames ;
103
103
}
104
104
105
- protected String relativeToRoot (String path ) {
105
+ public String relativeToRoot (String path ) {
106
106
return new File (path ).toPath ().relativize (rootFolder ().toPath ()).toString ();
107
107
}
108
108
109
- protected String read (String path ) throws IOException {
109
+ public String read (String path ) throws IOException {
110
110
return read (newFile (path ).toPath (), StandardCharsets .UTF_8 );
111
111
}
112
112
113
- protected String read (Path path , Charset encoding ) throws IOException {
113
+ public String read (Path path , Charset encoding ) throws IOException {
114
114
return new String (Files .readAllBytes (path ), encoding );
115
115
}
116
116
117
- protected void replace (String path , String toReplace , String replaceWith ) throws IOException {
117
+ public void replace (String path , String toReplace , String replaceWith ) throws IOException {
118
118
String before = read (path );
119
119
String after = before .replace (toReplace , replaceWith );
120
120
if (before .equals (after )) {
@@ -124,15 +124,15 @@ protected void replace(String path, String toReplace, String replaceWith) throws
124
124
}
125
125
126
126
/** Returns the contents of the given file from the src/test/resources directory. */
127
- protected static String getTestResource (String filename ) {
127
+ public static String getTestResource (String filename ) {
128
128
Optional <URL > resourceUrl = getTestResourceUrl (filename );
129
129
if (resourceUrl .isPresent ()) {
130
130
return ThrowingEx .get (() -> LineEnding .toUnix (Resources .toString (resourceUrl .get (), StandardCharsets .UTF_8 )));
131
131
}
132
132
throw new IllegalArgumentException ("No such resource " + filename );
133
133
}
134
134
135
- protected static boolean existsTestResource (String filename ) {
135
+ public static boolean existsTestResource (String filename ) {
136
136
return getTestResourceUrl (filename ).isPresent ();
137
137
}
138
138
@@ -142,7 +142,7 @@ private static Optional<URL> getTestResourceUrl(String filename) {
142
142
}
143
143
144
144
/** Returns Files (in a temporary folder) which has the contents of the given file from the src/test/resources directory. */
145
- protected List <File > createTestFiles (String ... filenames ) {
145
+ public List <File > createTestFiles (String ... filenames ) {
146
146
List <File > files = new ArrayList <>(filenames .length );
147
147
for (String filename : filenames ) {
148
148
files .add (createTestFile (filename ));
@@ -151,15 +151,15 @@ protected List<File> createTestFiles(String... filenames) {
151
151
}
152
152
153
153
/** Returns a File (in a temporary folder) which has the contents of the given file from the src/test/resources directory. */
154
- protected File createTestFile (String filename ) {
154
+ public File createTestFile (String filename ) {
155
155
return createTestFile (filename , UnaryOperator .identity ());
156
156
}
157
157
158
158
/**
159
159
* Returns a File (in a temporary folder) which has the contents, possibly processed, of the given file from the
160
160
* src/test/resources directory.
161
161
*/
162
- protected File createTestFile (String filename , UnaryOperator <String > fileContentsProcessor ) {
162
+ public File createTestFile (String filename , UnaryOperator <String > fileContentsProcessor ) {
163
163
int lastSlash = filename .lastIndexOf ('/' );
164
164
String name = lastSlash >= 0 ? filename .substring (lastSlash ) : filename ;
165
165
File file = newFile (name );
@@ -169,12 +169,12 @@ protected File createTestFile(String filename, UnaryOperator<String> fileContent
169
169
}
170
170
171
171
@ CheckReturnValue
172
- protected ReadAsserter assertFile (String path ) {
172
+ public ReadAsserter assertFile (String path ) {
173
173
return new ReadAsserter (newFile (path ));
174
174
}
175
175
176
176
@ CheckReturnValue
177
- protected ReadAsserter assertFile (File file ) {
177
+ public ReadAsserter assertFile (File file ) {
178
178
return new ReadAsserter (file );
179
179
}
180
180
@@ -207,7 +207,7 @@ public void matches(Consumer<AbstractCharSequenceAssert<?, String>> conditions)
207
207
}
208
208
}
209
209
210
- protected WriteAsserter setFile (String path ) {
210
+ public WriteAsserter setFile (String path ) {
211
211
return new WriteAsserter (newFile (path ));
212
212
}
213
213
0 commit comments