Refactored FileUtils.

Removed methods that are no longer needed for Java 6, moved the remaining method into the utils directory.
This commit is contained in:
akwizgran
2015-12-10 15:58:52 +00:00
parent 947da886bf
commit 912ba394c5
19 changed files with 274 additions and 366 deletions

View File

@@ -3,8 +3,6 @@ package org.briarproject;
import com.google.inject.AbstractModule;
import org.briarproject.api.db.DatabaseConfig;
import org.briarproject.api.system.FileUtils;
import org.briarproject.system.FileUtilsImpl;
import java.io.File;
@@ -26,6 +24,5 @@ public class TestDatabaseModule extends AbstractModule {
protected void configure() {
bind(DatabaseConfig.class).toInstance(config);
bind(FileUtils.class).to(FileUtilsImpl.class);
}
}

View File

@@ -1,11 +1,9 @@
package org.briarproject;
import org.briarproject.api.UniqueId;
import org.briarproject.util.FileUtils;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.PrintStream;
import java.util.Random;
import java.util.concurrent.atomic.AtomicInteger;
@@ -15,27 +13,13 @@ public class TestUtils {
new AtomicInteger((int) (Math.random() * 1000 * 1000));
private static final Random random = new Random();
public static void delete(File f) {
if (f.isDirectory()) for (File child : f.listFiles()) delete(child);
f.delete();
}
public static void createFile(File f, String s) throws IOException {
f.getParentFile().mkdirs();
PrintStream out = new PrintStream(new FileOutputStream(f));
out.print(s);
out.flush();
out.close();
}
public static File getTestDirectory() {
int name = nextTestDir.getAndIncrement();
File testDir = new File("test.tmp/" + name);
return testDir;
return new File("test.tmp/" + name);
}
public static void deleteTestDirectory(File testDir) {
delete(testDir);
FileUtils.deleteFileOrDir(testDir);
testDir.getParentFile().delete(); // Delete if empty
}

View File

@@ -19,7 +19,6 @@ import org.briarproject.api.messaging.Message;
import org.briarproject.api.messaging.MessageId;
import org.briarproject.api.transport.Endpoint;
import org.briarproject.api.transport.TemporarySecret;
import org.briarproject.system.FileUtilsImpl;
import org.briarproject.system.SystemClock;
import org.junit.After;
import org.junit.Before;
@@ -1611,7 +1610,7 @@ public class H2DatabaseTest extends BriarTestCase {
private Database<Connection> open(boolean resume) throws Exception {
Database<Connection> db = new H2Database(new TestDatabaseConfig(testDir,
MAX_SIZE), new FileUtilsImpl(), new SystemClock());
MAX_SIZE), new SystemClock());
if (!resume) TestUtils.deleteTestDirectory(testDir);
db.open();
return db;

View File

@@ -5,10 +5,8 @@ import org.briarproject.TestUtils;
import org.briarproject.api.ContactId;
import org.briarproject.api.plugins.TransportConnectionWriter;
import org.briarproject.api.plugins.simplex.SimplexPluginCallback;
import org.briarproject.api.system.FileUtils;
import org.briarproject.plugins.ImmediateExecutor;
import org.briarproject.plugins.file.RemovableDriveMonitor.Callback;
import org.briarproject.system.FileUtilsImpl;
import org.jmock.Expectations;
import org.jmock.Mockery;
import org.junit.After;
@@ -34,7 +32,6 @@ public class RemovableDrivePluginTest extends BriarTestCase {
private final File testDir = TestUtils.getTestDirectory();
private final ContactId contactId = new ContactId(234);
private final FileUtils fileUtils = new FileUtilsImpl();
@Before
public void setUp() {
@@ -61,7 +58,7 @@ public class RemovableDrivePluginTest extends BriarTestCase {
}});
RemovableDrivePlugin plugin = new RemovableDrivePlugin(executor,
fileUtils, callback, finder, monitor, 0);
callback, finder, monitor, 0);
plugin.start();
assertNull(plugin.createWriter(contactId));
@@ -96,7 +93,7 @@ public class RemovableDrivePluginTest extends BriarTestCase {
}});
RemovableDrivePlugin plugin = new RemovableDrivePlugin(executor,
fileUtils, callback, finder, monitor, 0);
callback, finder, monitor, 0);
plugin.start();
assertNull(plugin.createWriter(contactId));
@@ -133,7 +130,7 @@ public class RemovableDrivePluginTest extends BriarTestCase {
}});
RemovableDrivePlugin plugin = new RemovableDrivePlugin(executor,
fileUtils, callback, finder, monitor, 0);
callback, finder, monitor, 0);
plugin.start();
assertNull(plugin.createWriter(contactId));
@@ -172,7 +169,7 @@ public class RemovableDrivePluginTest extends BriarTestCase {
}});
RemovableDrivePlugin plugin = new RemovableDrivePlugin(executor,
fileUtils, callback, finder, monitor, 0);
callback, finder, monitor, 0);
plugin.start();
assertNull(plugin.createWriter(contactId));
@@ -211,7 +208,7 @@ public class RemovableDrivePluginTest extends BriarTestCase {
}});
RemovableDrivePlugin plugin = new RemovableDrivePlugin(executor,
fileUtils, callback, finder, monitor, 0);
callback, finder, monitor, 0);
plugin.start();
assertNotNull(plugin.createWriter(contactId));
@@ -254,7 +251,7 @@ public class RemovableDrivePluginTest extends BriarTestCase {
}});
RemovableDrivePlugin plugin = new RemovableDrivePlugin(executor,
fileUtils, callback, finder, monitor, 0);
callback, finder, monitor, 0);
plugin.start();
TransportConnectionWriter writer = plugin.createWriter(contactId);
@@ -293,7 +290,7 @@ public class RemovableDrivePluginTest extends BriarTestCase {
}});
RemovableDrivePlugin plugin = new RemovableDrivePlugin(executor,
fileUtils, callback, finder, monitor, 0);
callback, finder, monitor, 0);
plugin.start();
plugin.driveInserted(testDir);
@@ -313,7 +310,7 @@ public class RemovableDrivePluginTest extends BriarTestCase {
context.mock(RemovableDriveMonitor.class);
RemovableDrivePlugin plugin = new RemovableDrivePlugin(executor,
fileUtils, callback, finder, monitor, 0);
callback, finder, monitor, 0);
assertFalse(plugin.isPossibleConnectionFilename("abcdefg.dat"));
assertFalse(plugin.isPossibleConnectionFilename("abcdefghi.dat"));
@@ -341,8 +338,7 @@ public class RemovableDrivePluginTest extends BriarTestCase {
}});
RemovableDrivePlugin plugin = new RemovableDrivePlugin(
new ImmediateExecutor(), fileUtils, callback, finder, monitor,
0);
new ImmediateExecutor(), callback, finder, monitor, 0);
plugin.start();
File f = new File(testDir, "abcdefgh.dat");