Exception tests modernized and some code cleanup.

This commit is contained in:
offa committed 2021-07-01 17:14:43 +02:00
1 parent 2f612fcac9
commit 7ff32dcf3b
6 files changed
+99 -180

No files matched your search

+36 -45
View File
@@ -164,49 +164,44 @@ public class FilePathTest {
private List<Future<Integer>> whenFileIsCopied100TimesConcurrently(final File file) throws InterruptedException {
List<Callable<Integer>> r = new ArrayList<>();
for (int i=0; i<100; i++) {
r.add(new Callable<Integer>() {
@Override
public Integer call() throws Exception {
class Sink extends OutputStream {
private Exception closed;
private final AtomicInteger count = new AtomicInteger();
r.add(() -> {
class Sink extends OutputStream {
private Exception closed;
private final AtomicInteger count = new AtomicInteger();
private void checkNotClosed() throws IOException {
if (closed != null)
throw new IOException(closed);
}
@Override
public void write(int b) throws IOException {
count.incrementAndGet();
checkNotClosed();
}
@Override
public void write(byte[] b) throws IOException {
count.addAndGet(b.length);
checkNotClosed();
}
@Override
public void write(byte[] b, int off, int len) throws IOException {
count.addAndGet(len);
checkNotClosed();
}
@Override
public void close() throws IOException {
closed = new Exception();
//if (size!=count)
// fail();
}
private void checkNotClosed() throws IOException {
if (closed != null)
throw new IOException(closed);
}
FilePath f = new FilePath(channels.french, file.getPath());
Sink sink = new Sink();
f.copyTo(sink);
return sink.count.get();
@Override
public void write(int b) throws IOException {
count.incrementAndGet();
checkNotClosed();
}
@Override
public void write(byte[] b) throws IOException {
count.addAndGet(b.length);
checkNotClosed();
}
@Override
public void write(byte[] b, int off, int len) throws IOException {
count.addAndGet(len);
checkNotClosed();
}
@Override
public void close() throws IOException {
closed = new Exception();
}
}
FilePath f = new FilePath(channels.french, file.getPath());
Sink sink = new Sink();
f.copyTo(sink);
return sink.count.get();
});
}
@@ -789,12 +784,8 @@ public class FilePathTest {
File f = temp.newFolder("folder");
FilePath fp = new FilePath(f);
int invalidMode = 01770; // Full permissions for owner and group plus sticky bit.
try {
chmodAndMode(fp, invalidMode);
fail("Setting sticky bit should fail");
} catch (IOException e) {
assertEquals("Invalid mode: " + invalidMode, e.getMessage());
}
final IOException e = assertThrows("Setting sticky bit should fail", IOException.class, () -> chmodAndMode(fp, invalidMode));
assertEquals("Invalid mode: " + invalidMode, e.getMessage());
}
private int chmodAndMode(FilePath path, int mode) throws Exception {