-
Notifications
You must be signed in to change notification settings - Fork 31
Expand file tree
/
Copy pathFileOpsTest.java
More file actions
557 lines (484 loc) · 23.3 KB
/
FileOpsTest.java
File metadata and controls
557 lines (484 loc) · 23.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
/*BEGIN_COPYRIGHT_BLOCK
*
* Copyright (c) 2001-2019, JavaPLT group at Rice University (drjava@rice.edu). All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the
* following conditions are met:
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the following
* disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the
* following disclaimer in the documentation and/or other materials provided with the distribution.
* * Neither the names of DrJava, the JavaPLT group, Rice University, nor the names of its contributors may be used
* to endorse or promote products derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software is Open Source Initiative approved Open Source Software. Open Source Initative Approved is a trademark
* of the Open Source Initiative.
*
* This file is part of DrJava. Download the current version of this project from http://www.drjava.org/ or
* http://sourceforge.net/projects/drjava/
*
* END_COPYRIGHT_BLOCK*/
package edu.rice.cs.util;
import java.io.*;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.Set;
import java.util.TreeSet;
import edu.rice.cs.drjava.DrJavaTestCase;
import edu.rice.cs.plt.concurrent.JVMBuilder;
import edu.rice.cs.util.FileOps;
/** Test cases for {@link FileOps}.
* @version $Id$
*/
@SuppressWarnings("deprecation")
public class FileOpsTest extends DrJavaTestCase {
private static final Log _log = new Log("FileOpsTest.txt", false);
public static final String TEXT = "hi, dude.";
public static final String PREFIX = "prefix";
public static final String SUFFIX = ".suffix";
public void testCreateTempDirectory() throws IOException {
File dir = FileOps.createTempDirectory(PREFIX);
try {
assertTrue("createTempDirectory result is a directory", dir.isDirectory());
assertTrue("temp directory has correct prefix", dir.getName().startsWith(PREFIX));
}
finally { assertTrue("delete directory", dir.delete()); }
}
public void testReadAndWriteTempFile() throws IOException {
File file = FileOps.writeStringToNewTempFile(PREFIX, SUFFIX, TEXT);
try {
assertTrue("temp file has correct prefix",
file.getName().startsWith(PREFIX));
assertTrue("temp file has correct suffix",
file.getName().endsWith(SUFFIX));
String read = FileOps.readFileAsString(file);
assertEquals("contents after read", TEXT, read);
}
finally {
assertTrue("delete file", file.delete());
}
}
public void testRecursiveDirectoryDelete() throws IOException {
final File baseDir = FileOps.createTempDirectory(PREFIX);
File parentDir = baseDir;
boolean ret;
// create a bunch of subdirs and some files.
for (int i = 0; i < 5; i++) {
File subdir = new File(parentDir, "subdir" + i);
ret = subdir.mkdir();
assertTrue("create directory " + subdir, ret);
for (int j = 0; j < 2; j++) {
File file = new File(parentDir, "file" + i + "-" + j);
FileOps.writeStringToFile(file,
"Some text for file " + file.getAbsolutePath());
assertTrue(file + " exists", file.exists());
}
parentDir = subdir;
}
// OK, now try to delete base.
ret = FileOps.deleteDirectory(baseDir);
assertTrue("delete directory result", ret);
assertEquals("directory exists after deleting it", false, baseDir.exists());
}
/** This method checks that backups are made correctly, that when a save fails,
* no data is lost, and that when a save is attempted on a write-protected file,
* the save fails (bug #782963).
* @throws IOException if an IO operation fails
*/
public void testSaveFile() throws IOException {
File writeTo = File.createTempFile("fileops", ".test").getCanonicalFile();
writeTo.deleteOnExit();
File backup = new File(writeTo.getPath() + "~");
FileOps.saveFile(new FileOps.DefaultFileSaver(writeTo) {
public void saveTo(OutputStream os) throws IOException {
String output = "version 1";
os.write(output.getBytes());
}
public boolean shouldBackup() {
return false;
}
});
assertEquals("save w/o backup", "version 1", FileOps.readFileAsString(writeTo));
assertEquals("save w/o backup did not backup", false, backup.exists());
FileOps.saveFile(new FileOps.DefaultFileSaver(writeTo) {
public void saveTo(OutputStream os) throws IOException {
String output = "version 2";
os.write(output.getBytes());
}
});
assertEquals("save2 w backup", "version 2", FileOps.readFileAsString(writeTo));
assertEquals("save2 w backup did backup", "version 1",
FileOps.readFileAsString(backup));
FileOps.saveFile(new FileOps.DefaultFileSaver(writeTo) {
public void saveTo(OutputStream os) throws IOException {
String output = "version 3";
os.write(output.getBytes());
}
});
assertEquals("save3 w backup on", "version 3", FileOps.readFileAsString(writeTo));
assertEquals("save3 w backup on did not backup", "version 1",
FileOps.readFileAsString(backup));
/* Now see what happens when saving fails and we were not making a backup. Nothing should change. */
try {
FileOps.saveFile(new FileOps.DefaultFileSaver(writeTo) {
public void saveTo(OutputStream os) throws IOException {
String output = "version 4";
os.write(output.getBytes());
throw new IOException();
}
});
fail("IOException not propagated");
}
catch (IOException ioe){ }//do nothing, this is expected
assertEquals("failed save4 w/o backup", "version 3",
FileOps.readFileAsString(writeTo));
assertEquals("failed save4 w/o backup check original backup", "version 1",
FileOps.readFileAsString(backup));
/* Now see what happens when saving fails and we were making a backup */
try {
FileOps.saveFile(new FileOps.DefaultFileSaver(writeTo) {
public boolean shouldBackup () {
return true;
}
public void saveTo(OutputStream os) throws IOException {
String output = "version 5";
os.write(output.getBytes());
throw new IOException();
}
});
fail("IOException not propagated spot 2");
}
catch(IOException ioe){ } //do nothing, we expected this
assertEquals("failed save5 w backup", "version 3",
FileOps.readFileAsString(writeTo));
// Make sure that the backup file no longer exists since it was copied over the original
try {
FileOps.readFileAsString(backup);
fail("The backup file should no longer exist.");
}
catch(FileNotFoundException e) { } //do nothing, we expected this
// Test that save fails if the file is write-protected.
writeTo.setReadOnly();
try {
FileOps.saveFile(new FileOps.DefaultFileSaver(writeTo) {
public boolean shouldBackup () { return true; }
public void saveTo(OutputStream os) throws IOException {
String output = "version 6";
os.write(output.getBytes());
}
});
fail("The file to be saved was read-only!");
}
catch(IOException ioe){ } //do nothing, we expected this
assertEquals("failed save6 w backup", "version 3",
FileOps.readFileAsString(writeTo));
// Make sure that the backup file still doesn't exist since the file
// was read-only.
try {
FileOps.readFileAsString(backup);
fail("The backup file should no longer exist.");
}
catch(FileNotFoundException e) { } //do nothing, we expected this
}
/** This tests that packageExplore correctly runs through and returns
* non-empty packages
* @throws IOException if an IO operation fails
*/
public void testPackageExplore() throws IOException {
File rootDir = FileOps.createTempDirectory("fileOpsTest");
File subDir0 = new File(rootDir, "sub0");
subDir0.mkdir();
File subDir1 = new File(rootDir, "sub1");
subDir1.mkdir();
File subsubDir0 = new File(subDir0, "subsub0");
subsubDir0.mkdir();
File javasubsub = new File(subsubDir0, "aclass.java");
FileOps.writeStringToFile(javasubsub, "contents of this file are unimportant");
File javasub1 = new File(subDir1, "myclass.java");
FileOps.writeStringToFile(javasub1, "this file is pretty much empty");
File javaroot = new File(rootDir, "someclass.java");
FileOps.writeStringToFile(javaroot, "i can write anything i want here");
LinkedList<String> packages = FileOps.packageExplore("hello", rootDir);
assertEquals("package count a", 3, packages.size());
assertTrue("packages contents a0", packages.contains("hello.sub0.subsub0"));
assertTrue("packages contents a1", packages.contains("hello.sub1"));
assertTrue("packages contents a2", packages.contains("hello"));
//Now add a .java file to the root directory and check that the default directory
//is not added
packages = FileOps.packageExplore("", rootDir);
assertEquals("package count b", 2, packages.size());
assertTrue("packages contents b0", packages.contains("sub0.subsub0"));
assertTrue("packages contents b1", packages.contains("sub1"));
assertTrue("deleting temp directory", FileOps.deleteDirectory(rootDir));
}
/** Tests that non-empty directories can be deleted on exit.
* @throws IOException if an IO operation fails
* @throws InterruptedException if execution is interrupted unexpectedly
*/
public void testDeleteDirectoryOnExit() throws IOException, InterruptedException {
File tempDir = FileOps.createTempDirectory("DrJavaTestTempDir");
assertTrue("tempDir exists", tempDir.exists());
File dir1 = new File(tempDir, "dir1");
dir1.mkdir();
assertTrue("dir1 exists", dir1.exists());
assertTrue("dir1 is directory", dir1.isDirectory());
File file1 = new File(dir1, "file1");
file1.createNewFile(); // Should always succeed because dir1 was just created
assertTrue("file1 exists", file1.exists());
File dir2 = new File(dir1, "dir2");
dir2.mkdir();
assertTrue("dir2 exists", dir2.exists());
assertTrue("dir2 is directory", dir1.isDirectory());
File file2 = new File(dir2, "file2");
file2.createNewFile();
assertTrue("file2 exists", file2.exists());
edu.rice.cs.plt.io.IOUtil.deleteOnExitRecursively(tempDir);
Process process = JVMBuilder.DEFAULT.start(FileOpsTest.class.getName(), dir1.getAbsolutePath());
int status = process.waitFor();
assertEquals("Delete on exit test exited with an error!", 0, status);
assertTrue("dir1 should be deleted", ! dir1.exists());
assertTrue("file1 should be deleted", ! file1.exists());
assertTrue("dir2 should be deleted", ! dir2.exists());
assertTrue("file2 should be deleted", ! file2.exists());
/* If this test passes, tempDir should be deleted when the this JVM exits. */
}
public void testSplitFile() {
String[] parts = new String[]{"","home","username","dir"};
StringBuilder path1 = new StringBuilder();
for (String s : parts) {
path1.append(s);
path1.append(File.separator);
}
File f = new File(path1.toString());
String[] res = FileOps.splitFile(f);
assertTrue( "Inconsitent results. Expected " +
java.util.Arrays.asList(parts).toString() + ", but found " +
java.util.Arrays.asList(res).toString(),
java.util.Arrays.equals(parts,res));
}
private String fixPathFormat(String s){
return s.replace('\\', '/');
}
public void testMakeRelativeTo() throws IOException, SecurityException {
File base, abs;
base = new File("src/test1/test2/file.txt");
abs = new File("built/test1/test2/file.txt");
assertEquals("Wrong Relative Path 1", "../../../built/test1/test2/file.txt",
fixPathFormat(FileOps.stringMakeRelativeTo(abs,base)));
base = new File("file.txt");
abs = new File("built/test1/test2/file.txt");
assertEquals("Wrong Relative Path 2", "built/test1/test2/file.txt",
fixPathFormat(FileOps.stringMakeRelativeTo(abs,base)));
base = new File("built/test1/test2test/file.txt");
abs = new File("built/test1/test2/file.txt");
assertEquals("Wrong Relative Path 3", "../test2/file.txt",
fixPathFormat(FileOps.stringMakeRelativeTo(abs,base)));
base = new File("file.txt");
abs = new File("test.txt");
assertEquals("Wrong Relative Path 4", "test.txt",
fixPathFormat(FileOps.stringMakeRelativeTo(abs,base)));
}
/** Main method called by testDeleteDirectoryOnExit. Runs in new JVM so the files can be deleted. Exits with status
* 1 if wrong number of arguments are passed. Exits with status 2 if file doesn't exist.
* @param args should contain the file name of the directory to delete on exit
*/
public static void main(String[] args) {
if (args.length != 1) System.exit(1);
File dir = new File(args[0]);
if (! dir.exists()) System.exit(2);
FileOps.deleteDirectoryOnExit(dir);
// OK, exit cleanly
System.exit(0);
}
public void testConvertToAbsolutePathEntries() {
String ud = System.getProperty("user.dir");
String f = System.getProperty("file.separator");
String p = System.getProperty("path.separator");
String expected, actual, input;
input = "." + p + "drjava" + p+p+f + "home" + f + "foo" + f + "junit.jar";
expected = ud+f + "." + p+ud+f + "drjava" + p+ud+p+(new File(f + "home" + f + "foo" + f + "junit.jar")).getAbsolutePath();
actual = FileOps.convertToAbsolutePathEntries(input);
assertEquals("testConvertToAbsolutePathEntries for several paths failed, input = '" + input + "', expected = '" +
expected + "', actual = '" + actual + "'", expected, actual);
input = "";
expected = ud;
actual = FileOps.convertToAbsolutePathEntries(input);
assertEquals("testConvertToAbsolutePathEntries for empty path failed, input = '" + input + "', expected = '" +
expected + "', actual = '" + actual + "'", expected, actual);
input = p + p + p + ".";
expected = ud + p + ud + p + ud + p + ud + f + ".";
actual = FileOps.convertToAbsolutePathEntries(input);
assertEquals("testConvertToAbsolutePathEntries for several empty paths failed, input = '" + input +
"', expected = '" +expected + "', actual = '" + actual + "'", expected, actual);
input = p + p;
expected = ud + p + ud + p + ud;
actual = FileOps.convertToAbsolutePathEntries(input);
assertEquals("testConvertToAbsolutePathEntries for trailing empty paths failed, input = '" + input +
"', expected = '" + expected + "', actual = '" + actual + "'", expected, actual);
}
/** Tests getFilesInDir.
* @throws IOException if an IO operation fails
*/
public void testGetFiles() throws IOException {
File dir1 = FileOps.createTempDirectory("DrJavaTestTempDir");
assertTrue("dir1 exists", dir1.exists());
File file1a = File.createTempFile("DrJavaTest-", ".temp", dir1).getCanonicalFile();
assertTrue("file1a exists", file1a.exists());
File file1b = File.createTempFile("DrJava-", ".temp", dir1).getCanonicalFile();
assertTrue("file1b exists", file1b.exists());
File dir2 = FileOps.createTempDirectory("DrJavaTestDir-", dir1).getCanonicalFile();
assertTrue("dir2 exists", dir2.exists());
File file2 = File.createTempFile("DrJavaTest-", ".temp", dir2).getCanonicalFile();
assertTrue("file2 exists", file2.exists());
FileFilter ff = new FileFilter() {
public boolean accept(File f) {
if (f.isDirectory()) return true;
String name = f.getName();
return name.startsWith("DrJavaTest");
}
};
Set<File> res1 = new TreeSet<File>(Arrays.asList(new File[] {file1a}));
Set<File> res2 = new TreeSet<File>(Arrays.asList(new File[] {file1a, file2}));
Set<File> nrfiles = new TreeSet<File>();
for(File f : FileOps.getFilesInDir(dir1, false, ff)) {
nrfiles.add(f.getCanonicalFile());
}
Set<File> rfiles = new TreeSet<File>();
for(File f : FileOps.getFilesInDir(dir1, true, ff)) {
rfiles.add(f.getCanonicalFile());
}
assertEquals("non-recursive FilesInDir test", res1, nrfiles);
assertEquals("recursive FileInDir test", res2, rfiles);
edu.rice.cs.plt.io.IOUtil.deleteRecursively(dir1);
}
/** Tests for getShortFile. This test creates a file and writes to it using a long file name, then
* checks if the short file name is the same (canonical) file and that it contains the same data.
* @throws IOException if an IO operation fails
*/
public void testGetShortFile() throws IOException {
File dir1 = FileOps.createTempDirectory("DrJavaTestTempDir");
File dir2 = new File(dir1, "Documents and Settings" + File.separator + "User Name" + File.separator + "My Documents");
assertTrue("Couldn't create temp directory", dir2.mkdirs());
File longF = new File(dir2, "rt.concjunit.txt");
PrintWriter pw = new PrintWriter(new FileWriter(longF));
String s = new java.util.Date().toString() + " "+System.currentTimeMillis();
pw.println(s);
pw.close();
File shortF = FileOps.getShortFile(longF);
assertTrue("Short file name doesn't exist", shortF.exists());
BufferedReader br = new BufferedReader(new FileReader(shortF));
String line = br.readLine();
br.close();
assertEquals("File contents are not the same", s, line);
assertEquals("Files are not the same", longF.getCanonicalFile(), shortF.getCanonicalFile());
longF = new File(dir2, "prefix and space rt.concjunit.txt");
pw = new PrintWriter(new FileWriter(longF));
s = new java.util.Date().toString() + " "+System.currentTimeMillis();
pw.println(s);
pw.close();
shortF = FileOps.getShortFile(longF);
assertTrue("Short file name doesn't exist", shortF.exists());
br = new BufferedReader(new FileReader(shortF));
line = br.readLine();
br.close();
assertEquals("File contents are not the same", s, line);
assertEquals("Files are not the same", longF.getCanonicalFile(), shortF.getCanonicalFile());
longF = new File(dir2, "short.txt");
pw = new PrintWriter(new FileWriter(longF));
s = new java.util.Date().toString() + " "+System.currentTimeMillis();
pw.println(s);
pw.close();
shortF = FileOps.getShortFile(longF);
assertTrue("Short file name doesn't exist", shortF.exists());
br = new BufferedReader(new FileReader(shortF));
line = br.readLine();
br.close();
assertEquals("File contents are not the same", s, line);
assertEquals("Files are not the same", longF.getCanonicalFile(), shortF.getCanonicalFile());
File dir3 = new File(dir2, "Another Long Directory");
assertTrue("Couldn't create temp directory", dir3.mkdirs());
longF = new File(dir3, "rt.concjunit.txt");
pw = new PrintWriter(new FileWriter(longF));
s = new java.util.Date().toString() + " "+System.currentTimeMillis();
pw.println(s);
pw.close();
shortF = FileOps.getShortFile(longF);
assertTrue("Short file name doesn't exist", shortF.exists());
br = new BufferedReader(new FileReader(shortF));
line = br.readLine();
br.close();
assertEquals("File contents are not the same", s, line);
assertEquals("Files are not the same", longF.getCanonicalFile(), shortF.getCanonicalFile());
longF = new File(dir3, "prefix and space rt.concjunit.txt");
pw = new PrintWriter(new FileWriter(longF));
s = new java.util.Date().toString() + " "+System.currentTimeMillis();
pw.println(s);
pw.close();
shortF = FileOps.getShortFile(longF);
assertTrue("Short file name doesn't exist", shortF.exists());
br = new BufferedReader(new FileReader(shortF));
line = br.readLine();
br.close();
assertEquals("File contents are not the same", s, line);
assertEquals("Files are not the same", longF.getCanonicalFile(), shortF.getCanonicalFile());
longF = new File(dir3, "short.txt");
pw = new PrintWriter(new FileWriter(longF));
s = new java.util.Date().toString() + " "+System.currentTimeMillis();
pw.println(s);
pw.close();
shortF = FileOps.getShortFile(longF);
assertTrue("Short file name doesn't exist", shortF.exists());
br = new BufferedReader(new FileReader(shortF));
line = br.readLine();
br.close();
assertEquals("File contents are not the same", s, line);
assertEquals("Files are not the same", longF.getCanonicalFile(), shortF.getCanonicalFile());
File dir4 = new File(dir2, "shortdir");
assertTrue("Couldn't create temp directory", dir4.mkdirs());
longF = new File(dir4, "rt.concjunit.txt");
pw = new PrintWriter(new FileWriter(longF));
s = new java.util.Date().toString() + " "+System.currentTimeMillis();
pw.println(s);
pw.close();
shortF = FileOps.getShortFile(longF);
assertTrue("Short file name doesn't exist", shortF.exists());
br = new BufferedReader(new FileReader(shortF));
line = br.readLine();
br.close();
assertEquals("File contents are not the same", s, line);
assertEquals("Files are not the same", longF.getCanonicalFile(), shortF.getCanonicalFile());
longF = new File(dir4, "prefix and space rt.concjunit.txt");
pw = new PrintWriter(new FileWriter(longF));
s = new java.util.Date().toString() + " "+System.currentTimeMillis();
pw.println(s);
pw.close();
shortF = FileOps.getShortFile(longF);
assertTrue("Short file name doesn't exist", shortF.exists());
br = new BufferedReader(new FileReader(shortF));
line = br.readLine();
br.close();
assertEquals("File contents are not the same", s, line);
assertEquals("Files are not the same", longF.getCanonicalFile(), shortF.getCanonicalFile());
longF = new File(dir4, "short.txt");
pw = new PrintWriter(new FileWriter(longF));
s = new java.util.Date().toString() + " "+System.currentTimeMillis();
pw.println(s);
pw.close();
shortF = FileOps.getShortFile(longF);
assertTrue("Short file name doesn't exist", shortF.exists());
br = new BufferedReader(new FileReader(shortF));
line = br.readLine();
br.close();
assertEquals("File contents are not the same", s, line);
assertEquals("Files are not the same", longF.getCanonicalFile(), shortF.getCanonicalFile());
FileOps.deleteDirectory(dir1);
}
}