mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-13 11:19:04 +01:00
Moved test utility classes into test package.
This commit is contained in:
@@ -1,14 +0,0 @@
|
||||
package org.briarproject.bramble;
|
||||
|
||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||
|
||||
import java.util.concurrent.Executor;
|
||||
|
||||
@NotNullByDefault
|
||||
public class ImmediateExecutor implements Executor {
|
||||
|
||||
@Override
|
||||
public void execute(Runnable r) {
|
||||
r.run();
|
||||
}
|
||||
}
|
||||
@@ -1,57 +0,0 @@
|
||||
package org.briarproject.bramble;
|
||||
|
||||
import org.briarproject.bramble.api.crypto.SecretKey;
|
||||
import org.briarproject.bramble.api.db.DatabaseConfig;
|
||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
@NotNullByDefault
|
||||
public class TestDatabaseConfig implements DatabaseConfig {
|
||||
|
||||
private final File dir;
|
||||
private final long maxSize;
|
||||
private volatile SecretKey key = new SecretKey(new byte[SecretKey.LENGTH]);
|
||||
|
||||
public TestDatabaseConfig(File dir, long maxSize) {
|
||||
this.dir = dir;
|
||||
this.maxSize = maxSize;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean databaseExists() {
|
||||
if (!dir.isDirectory()) return false;
|
||||
File[] files = dir.listFiles();
|
||||
return files != null && files.length > 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public File getDatabaseDirectory() {
|
||||
return dir;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setEncryptionKey(SecretKey key) {
|
||||
this.key = key;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SecretKey getEncryptionKey() {
|
||||
return key;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setLocalAuthorName(String nickname) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getLocalAuthorName() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getMaxSize() {
|
||||
return maxSize;
|
||||
}
|
||||
}
|
||||
@@ -1,38 +0,0 @@
|
||||
package org.briarproject.bramble;
|
||||
|
||||
import org.briarproject.bramble.api.db.DatabaseConfig;
|
||||
import org.briarproject.bramble.api.db.DatabaseExecutor;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.concurrent.Executor;
|
||||
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import dagger.Module;
|
||||
import dagger.Provides;
|
||||
|
||||
@Module
|
||||
public class TestDatabaseModule {
|
||||
|
||||
private final DatabaseConfig config;
|
||||
|
||||
public TestDatabaseModule() {
|
||||
this(new File("."));
|
||||
}
|
||||
|
||||
public TestDatabaseModule(File dir) {
|
||||
config = new TestDatabaseConfig(dir, Long.MAX_VALUE);
|
||||
}
|
||||
|
||||
@Provides
|
||||
DatabaseConfig provideDatabaseConfig() {
|
||||
return config;
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
@DatabaseExecutor
|
||||
Executor provideDatabaseExecutor() {
|
||||
return new ImmediateExecutor();
|
||||
}
|
||||
}
|
||||
@@ -1,13 +0,0 @@
|
||||
package org.briarproject.bramble;
|
||||
|
||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||
import org.briarproject.bramble.api.system.SeedProvider;
|
||||
|
||||
@NotNullByDefault
|
||||
public class TestSeedProvider implements SeedProvider {
|
||||
|
||||
@Override
|
||||
public byte[] getSeed() {
|
||||
return TestUtils.getRandomBytes(32);
|
||||
}
|
||||
}
|
||||
@@ -1,18 +0,0 @@
|
||||
package org.briarproject.bramble;
|
||||
|
||||
import org.briarproject.bramble.api.system.SeedProvider;
|
||||
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import dagger.Module;
|
||||
import dagger.Provides;
|
||||
|
||||
@Module
|
||||
public class TestSeedProviderModule {
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
SeedProvider provideSeedProvider() {
|
||||
return new TestSeedProvider();
|
||||
}
|
||||
}
|
||||
@@ -1,35 +0,0 @@
|
||||
package org.briarproject.bramble;
|
||||
|
||||
import org.briarproject.bramble.api.client.ClientHelper;
|
||||
import org.briarproject.bramble.api.data.MetadataEncoder;
|
||||
import org.briarproject.bramble.api.identity.AuthorFactory;
|
||||
import org.briarproject.bramble.api.sync.ClientId;
|
||||
import org.briarproject.bramble.api.sync.Group;
|
||||
import org.briarproject.bramble.api.sync.GroupId;
|
||||
import org.briarproject.bramble.api.sync.Message;
|
||||
import org.briarproject.bramble.api.sync.MessageId;
|
||||
import org.briarproject.bramble.api.system.Clock;
|
||||
|
||||
public abstract class ValidatorTestCase extends BrambleMockTestCase {
|
||||
|
||||
protected final ClientHelper clientHelper =
|
||||
context.mock(ClientHelper.class);
|
||||
protected final MetadataEncoder metadataEncoder =
|
||||
context.mock(MetadataEncoder.class);
|
||||
protected final Clock clock = context.mock(Clock.class);
|
||||
protected final AuthorFactory authorFactory =
|
||||
context.mock(AuthorFactory.class);
|
||||
|
||||
protected final MessageId messageId =
|
||||
new MessageId(TestUtils.getRandomId());
|
||||
protected final GroupId groupId = new GroupId(TestUtils.getRandomId());
|
||||
protected final long timestamp = 1234567890 * 1000L;
|
||||
protected final byte[] raw = TestUtils.getRandomBytes(123);
|
||||
protected final Message message =
|
||||
new Message(messageId, groupId, timestamp, raw);
|
||||
protected final ClientId clientId =
|
||||
new ClientId(TestUtils.getRandomString(123));
|
||||
protected final byte[] descriptor = TestUtils.getRandomBytes(123);
|
||||
protected final Group group = new Group(groupId, clientId, descriptor);
|
||||
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
package org.briarproject.bramble.api.data;
|
||||
|
||||
import org.briarproject.bramble.BrambleTestCase;
|
||||
import org.briarproject.bramble.api.Bytes;
|
||||
import org.briarproject.bramble.test.BrambleTestCase;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.Collections;
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
package org.briarproject.bramble.api.data;
|
||||
|
||||
import org.briarproject.bramble.BrambleTestCase;
|
||||
import org.briarproject.bramble.api.Bytes;
|
||||
import org.briarproject.bramble.api.FormatException;
|
||||
import org.briarproject.bramble.test.BrambleTestCase;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package org.briarproject.bramble;
|
||||
package org.briarproject.bramble.test;
|
||||
|
||||
import org.jmock.Mockery;
|
||||
import org.junit.After;
|
||||
@@ -1,4 +1,4 @@
|
||||
package org.briarproject.bramble;
|
||||
package org.briarproject.bramble.test;
|
||||
|
||||
import java.lang.Thread.UncaughtExceptionHandler;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package org.briarproject.bramble;
|
||||
package org.briarproject.bramble.test;
|
||||
|
||||
import org.briarproject.bramble.api.UniqueId;
|
||||
import org.briarproject.bramble.api.crypto.SecretKey;
|
||||
Reference in New Issue
Block a user