Replace default methods with helper classes.

This is a workaround for AbstractMethodErrors
thrown by on-device tests.
This commit is contained in:
akwizgran
2019-12-11 16:27:55 +00:00
parent 5ba64577bd
commit 5962d3c763
35 changed files with 182 additions and 144 deletions

View File

@@ -11,4 +11,14 @@ public interface BrambleAndroidEagerSingletons {
void inject(AndroidNetworkModule.EagerSingletons init); void inject(AndroidNetworkModule.EagerSingletons init);
void inject(ReportingModule.EagerSingletons init); void inject(ReportingModule.EagerSingletons init);
class Helper {
public static void injectEagerSingletons(
BrambleAndroidEagerSingletons c) {
c.inject(new AndroidBatteryModule.EagerSingletons());
c.inject(new AndroidNetworkModule.EagerSingletons());
c.inject(new ReportingModule.EagerSingletons());
}
}
} }

View File

@@ -18,10 +18,4 @@ import dagger.Module;
SocksModule.class SocksModule.class
}) })
public class BrambleAndroidModule { public class BrambleAndroidModule {
public static void initEagerSingletons(BrambleAndroidEagerSingletons c) {
c.inject(new AndroidBatteryModule.EagerSingletons());
c.inject(new AndroidNetworkModule.EagerSingletons());
c.inject(new ReportingModule.EagerSingletons());
}
} }

View File

@@ -39,18 +39,21 @@ public interface BrambleCoreEagerSingletons {
void inject(VersioningModule.EagerSingletons init); void inject(VersioningModule.EagerSingletons init);
default void injectBrambleCoreEagerSingletons() { class Helper {
inject(new ContactModule.EagerSingletons());
inject(new CryptoExecutorModule.EagerSingletons()); public static void injectEagerSingletons(BrambleCoreEagerSingletons c) {
inject(new DatabaseExecutorModule.EagerSingletons()); c.inject(new ContactModule.EagerSingletons());
inject(new IdentityModule.EagerSingletons()); c.inject(new CryptoExecutorModule.EagerSingletons());
inject(new LifecycleModule.EagerSingletons()); c.inject(new DatabaseExecutorModule.EagerSingletons());
inject(new RendezvousModule.EagerSingletons()); c.inject(new IdentityModule.EagerSingletons());
inject(new PluginModule.EagerSingletons()); c.inject(new LifecycleModule.EagerSingletons());
inject(new PropertiesModule.EagerSingletons()); c.inject(new RendezvousModule.EagerSingletons());
inject(new SystemModule.EagerSingletons()); c.inject(new PluginModule.EagerSingletons());
inject(new TransportModule.EagerSingletons()); c.inject(new PropertiesModule.EagerSingletons());
inject(new ValidationModule.EagerSingletons()); c.inject(new SystemModule.EagerSingletons());
inject(new VersioningModule.EagerSingletons()); c.inject(new TransportModule.EagerSingletons());
c.inject(new ValidationModule.EagerSingletons());
c.inject(new VersioningModule.EagerSingletons());
}
} }
} }

View File

@@ -50,8 +50,4 @@ import dagger.Module;
VersioningModule.class VersioningModule.class
}) })
public class BrambleCoreModule { public class BrambleCoreModule {
public static void initEagerSingletons(BrambleCoreEagerSingletons c) {
c.injectBrambleCoreEagerSingletons();
}
} }

View File

@@ -1,5 +1,6 @@
package org.briarproject.bramble.contact; package org.briarproject.bramble.contact;
import org.briarproject.bramble.BrambleCoreEagerSingletons;
import org.briarproject.bramble.api.Pair; import org.briarproject.bramble.api.Pair;
import org.briarproject.bramble.api.contact.Contact; import org.briarproject.bramble.api.contact.Contact;
import org.briarproject.bramble.api.contact.ContactManager; import org.briarproject.bramble.api.contact.ContactManager;
@@ -61,11 +62,11 @@ public class ContactExchangeIntegrationTest extends BrambleTestCase {
alice = DaggerContactExchangeIntegrationTestComponent.builder() alice = DaggerContactExchangeIntegrationTestComponent.builder()
.testDatabaseConfigModule( .testDatabaseConfigModule(
new TestDatabaseConfigModule(aliceDir)).build(); new TestDatabaseConfigModule(aliceDir)).build();
alice.injectBrambleCoreEagerSingletons(); BrambleCoreEagerSingletons.Helper.injectEagerSingletons(alice);
bob = DaggerContactExchangeIntegrationTestComponent.builder() bob = DaggerContactExchangeIntegrationTestComponent.builder()
.testDatabaseConfigModule(new TestDatabaseConfigModule(bobDir)) .testDatabaseConfigModule(new TestDatabaseConfigModule(bobDir))
.build(); .build();
bob.injectBrambleCoreEagerSingletons(); BrambleCoreEagerSingletons.Helper.injectEagerSingletons(bob);
// Set up the devices and get the identities // Set up the devices and get the identities
aliceIdentity = setUp(alice, "Alice"); aliceIdentity = setUp(alice, "Alice");
bobIdentity = setUp(bob, "Bob"); bobIdentity = setUp(bob, "Bob");

View File

@@ -1,5 +1,6 @@
package org.briarproject.bramble.sync; package org.briarproject.bramble.sync;
import org.briarproject.bramble.BrambleCoreEagerSingletons;
import org.briarproject.bramble.api.contact.ContactId; import org.briarproject.bramble.api.contact.ContactId;
import org.briarproject.bramble.api.crypto.SecretKey; import org.briarproject.bramble.api.crypto.SecretKey;
import org.briarproject.bramble.api.crypto.TransportCrypto; import org.briarproject.bramble.api.crypto.TransportCrypto;
@@ -72,7 +73,7 @@ public class SyncIntegrationTest extends BrambleTestCase {
SyncIntegrationTestComponent component = SyncIntegrationTestComponent component =
DaggerSyncIntegrationTestComponent.builder().build(); DaggerSyncIntegrationTestComponent.builder().build();
component.injectBrambleCoreEagerSingletons(); BrambleCoreEagerSingletons.Helper.injectEagerSingletons(component);
component.inject(this); component.inject(this);
contactId = getContactId(); contactId = getContactId();

View File

@@ -1,5 +1,6 @@
package org.briarproject.bramble.plugin.tor; package org.briarproject.bramble.plugin.tor;
import org.briarproject.bramble.BrambleCoreEagerSingletons;
import org.briarproject.bramble.api.battery.BatteryManager; import org.briarproject.bramble.api.battery.BatteryManager;
import org.briarproject.bramble.api.event.EventBus; import org.briarproject.bramble.api.event.EventBus;
import org.briarproject.bramble.api.lifecycle.IoExecutor; import org.briarproject.bramble.api.lifecycle.IoExecutor;
@@ -45,7 +46,7 @@ public class BridgeTest extends BrambleTestCase {
public static Iterable<String> data() { public static Iterable<String> data() {
BrambleJavaIntegrationTestComponent component = BrambleJavaIntegrationTestComponent component =
DaggerBrambleJavaIntegrationTestComponent.builder().build(); DaggerBrambleJavaIntegrationTestComponent.builder().build();
component.injectBrambleCoreEagerSingletons(); BrambleCoreEagerSingletons.Helper.injectEagerSingletons(component);
return component.getCircumventionProvider().getBridges(false); return component.getCircumventionProvider().getBridges(false);
} }
@@ -90,7 +91,7 @@ public class BridgeTest extends BrambleTestCase {
BrambleJavaIntegrationTestComponent component = BrambleJavaIntegrationTestComponent component =
DaggerBrambleJavaIntegrationTestComponent.builder().build(); DaggerBrambleJavaIntegrationTestComponent.builder().build();
component.injectBrambleCoreEagerSingletons(); BrambleCoreEagerSingletons.Helper.injectEagerSingletons(component);
component.inject(this); component.inject(this);
LocationUtils locationUtils = () -> "US"; LocationUtils locationUtils = () -> "US";

View File

@@ -1,8 +1,8 @@
package org.briarproject.briar.android; package org.briarproject.briar.android;
import org.briarproject.bramble.BrambleAndroidModule; import org.briarproject.bramble.BrambleAndroidEagerSingletons;
import org.briarproject.bramble.BrambleCoreModule; import org.briarproject.bramble.BrambleCoreEagerSingletons;
import org.briarproject.briar.BriarCoreModule; import org.briarproject.briar.BriarCoreEagerSingletons;
public class BriarTestComponentApplication extends BriarApplicationImpl { public class BriarTestComponentApplication extends BriarApplicationImpl {
@@ -12,10 +12,10 @@ public class BriarTestComponentApplication extends BriarApplicationImpl {
.appModule(new AppModule(this)).build(); .appModule(new AppModule(this)).build();
// We need to load the eager singletons directly after making the // We need to load the eager singletons directly after making the
// dependency graphs // dependency graphs
BrambleCoreModule.initEagerSingletons(component); // FIXME AbstractMethodError BrambleCoreEagerSingletons.Helper.injectEagerSingletons(component);
BrambleAndroidModule.initEagerSingletons(component); BrambleAndroidEagerSingletons.Helper.injectEagerSingletons(component);
BriarCoreModule.initEagerSingletons(component); BriarCoreEagerSingletons.Helper.injectEagerSingletons(component);
AndroidEagerSingletons.initEagerSingletons(component); AndroidEagerSingletons.Helper.injectEagerSingletons(component);
return component; return component;
} }

View File

@@ -73,7 +73,7 @@ import dagger.Component;
}) })
public interface AndroidComponent public interface AndroidComponent
extends BrambleCoreEagerSingletons, BrambleAndroidEagerSingletons, extends BrambleCoreEagerSingletons, BrambleAndroidEagerSingletons,
BriarCoreEagerSingletons { BriarCoreEagerSingletons, AndroidEagerSingletons {
// Exposed objects // Exposed objects
@CryptoExecutor @CryptoExecutor
@@ -176,7 +176,4 @@ public interface AndroidComponent
void inject(EmojiTextInputView textInputView); void inject(EmojiTextInputView textInputView);
void inject(BriarModelLoader briarModelLoader); void inject(BriarModelLoader briarModelLoader);
// Eager singleton load
void inject(AppModule.EagerSingletons init);
} }

View File

@@ -1,8 +1,13 @@
package org.briarproject.briar.android; package org.briarproject.briar.android;
class AndroidEagerSingletons { interface AndroidEagerSingletons {
static void initEagerSingletons(AndroidComponent c) { void inject(AppModule.EagerSingletons init);
c.inject(new AppModule.EagerSingletons());
class Helper {
static void injectEagerSingletons(AndroidEagerSingletons c) {
c.inject(new AppModule.EagerSingletons());
}
} }
} }

View File

@@ -17,9 +17,9 @@ import com.vanniktech.emoji.google.GoogleEmojiProvider;
import org.acra.ACRA; import org.acra.ACRA;
import org.acra.ReportingInteractionMode; import org.acra.ReportingInteractionMode;
import org.acra.annotation.ReportsCrashes; import org.acra.annotation.ReportsCrashes;
import org.briarproject.bramble.BrambleAndroidModule; import org.briarproject.bramble.BrambleAndroidEagerSingletons;
import org.briarproject.bramble.BrambleCoreModule; import org.briarproject.bramble.BrambleCoreEagerSingletons;
import org.briarproject.briar.BriarCoreModule; import org.briarproject.briar.BriarCoreEagerSingletons;
import org.briarproject.briar.BuildConfig; import org.briarproject.briar.BuildConfig;
import org.briarproject.briar.R; import org.briarproject.briar.R;
import org.briarproject.briar.android.logging.CachingLogHandler; import org.briarproject.briar.android.logging.CachingLogHandler;
@@ -133,10 +133,12 @@ public class BriarApplicationImpl extends Application
// We need to load the eager singletons directly after making the // We need to load the eager singletons directly after making the
// dependency graphs // dependency graphs
BrambleCoreModule.initEagerSingletons(androidComponent); BrambleCoreEagerSingletons.Helper
BrambleAndroidModule.initEagerSingletons(androidComponent); .injectEagerSingletons(androidComponent);
BriarCoreModule.initEagerSingletons(androidComponent); BrambleAndroidEagerSingletons.Helper
AndroidEagerSingletons.initEagerSingletons(androidComponent); .injectEagerSingletons(androidComponent);
BriarCoreEagerSingletons.Helper.injectEagerSingletons(androidComponent);
AndroidEagerSingletons.Helper.injectEagerSingletons(androidComponent);
return androidComponent; return androidComponent;
} }

View File

@@ -7,9 +7,9 @@ import android.preference.PreferenceManager;
import com.vanniktech.emoji.EmojiManager; import com.vanniktech.emoji.EmojiManager;
import com.vanniktech.emoji.google.GoogleEmojiProvider; import com.vanniktech.emoji.google.GoogleEmojiProvider;
import org.briarproject.bramble.BrambleAndroidModule; import org.briarproject.bramble.BrambleAndroidEagerSingletons;
import org.briarproject.bramble.BrambleCoreModule; import org.briarproject.bramble.BrambleCoreEagerSingletons;
import org.briarproject.briar.BriarCoreModule; import org.briarproject.briar.BriarCoreEagerSingletons;
import java.util.Collection; import java.util.Collection;
import java.util.logging.LogRecord; import java.util.logging.LogRecord;
@@ -42,10 +42,14 @@ public class TestBriarApplication extends Application
// We need to load the eager singletons directly after making the // We need to load the eager singletons directly after making the
// dependency graphs // dependency graphs
BrambleCoreModule.initEagerSingletons(applicationComponent); BrambleCoreEagerSingletons.Helper
BrambleAndroidModule.initEagerSingletons(applicationComponent); .injectEagerSingletons(applicationComponent);
BriarCoreModule.initEagerSingletons(applicationComponent); BrambleAndroidEagerSingletons.Helper
AndroidEagerSingletons.initEagerSingletons(applicationComponent); .injectEagerSingletons(applicationComponent);
BriarCoreEagerSingletons.Helper
.injectEagerSingletons(applicationComponent);
AndroidEagerSingletons.Helper
.injectEagerSingletons(applicationComponent);
EmojiManager.install(new GoogleEmojiProvider()); EmojiManager.install(new GoogleEmojiProvider());
} }

View File

@@ -27,4 +27,17 @@ public interface BriarCoreEagerSingletons {
void inject(SharingModule.EagerSingletons init); void inject(SharingModule.EagerSingletons init);
class Helper {
public static void injectEagerSingletons(BriarCoreEagerSingletons c) {
c.inject(new BlogModule.EagerSingletons());
c.inject(new FeedModule.EagerSingletons());
c.inject(new ForumModule.EagerSingletons());
c.inject(new GroupInvitationModule.EagerSingletons());
c.inject(new MessagingModule.EagerSingletons());
c.inject(new PrivateGroupModule.EagerSingletons());
c.inject(new SharingModule.EagerSingletons());
c.inject(new IntroductionModule.EagerSingletons());
}
}
} }

View File

@@ -28,15 +28,4 @@ import dagger.Module;
TestModule.class TestModule.class
}) })
public class BriarCoreModule { public class BriarCoreModule {
public static void initEagerSingletons(BriarCoreEagerSingletons c) {
c.inject(new BlogModule.EagerSingletons());
c.inject(new FeedModule.EagerSingletons());
c.inject(new ForumModule.EagerSingletons());
c.inject(new GroupInvitationModule.EagerSingletons());
c.inject(new MessagingModule.EagerSingletons());
c.inject(new PrivateGroupModule.EagerSingletons());
c.inject(new SharingModule.EagerSingletons());
c.inject(new IntroductionModule.EagerSingletons());
}
} }

View File

@@ -65,23 +65,23 @@ public class BlogManagerIntegrationTest
protected void createComponents() { protected void createComponents() {
BriarIntegrationTestComponent component = BriarIntegrationTestComponent component =
DaggerBriarIntegrationTestComponent.builder().build(); DaggerBriarIntegrationTestComponent.builder().build();
component.injectBriarEagerSingletons(); BriarIntegrationTestComponent.Helper.injectEagerSingletons(component);
component.inject(this); component.inject(this);
c0 = DaggerBriarIntegrationTestComponent.builder() c0 = DaggerBriarIntegrationTestComponent.builder()
.testDatabaseConfigModule(new TestDatabaseConfigModule(t0Dir)) .testDatabaseConfigModule(new TestDatabaseConfigModule(t0Dir))
.build(); .build();
c0.injectBriarEagerSingletons(); BriarIntegrationTestComponent.Helper.injectEagerSingletons(c0);
c1 = DaggerBriarIntegrationTestComponent.builder() c1 = DaggerBriarIntegrationTestComponent.builder()
.testDatabaseConfigModule(new TestDatabaseConfigModule(t1Dir)) .testDatabaseConfigModule(new TestDatabaseConfigModule(t1Dir))
.build(); .build();
c1.injectBriarEagerSingletons(); BriarIntegrationTestComponent.Helper.injectEagerSingletons(c1);
c2 = DaggerBriarIntegrationTestComponent.builder() c2 = DaggerBriarIntegrationTestComponent.builder()
.testDatabaseConfigModule(new TestDatabaseConfigModule(t2Dir)) .testDatabaseConfigModule(new TestDatabaseConfigModule(t2Dir))
.build(); .build();
c2.injectBriarEagerSingletons(); BriarIntegrationTestComponent.Helper.injectEagerSingletons(c2);
} }
@Test @Test

View File

@@ -38,7 +38,7 @@ public class FeedManagerIntegrationTest extends BriarTestCase {
DaggerFeedManagerIntegrationTestComponent.builder() DaggerFeedManagerIntegrationTestComponent.builder()
.testDatabaseConfigModule( .testDatabaseConfigModule(
new TestDatabaseConfigModule(testFile)).build(); new TestDatabaseConfigModule(testFile)).build();
component.injectFeedManagerEagerSingletons(); FeedManagerIntegrationTestComponent.Helper.injectEagerSingletons(component);
component.inject(this); component.inject(this);
IdentityManager identityManager = component.getIdentityManager(); IdentityManager identityManager = component.getIdentityManager();

View File

@@ -35,12 +35,6 @@ interface FeedManagerIntegrationTestComponent
void inject(FeedModule.EagerSingletons init); void inject(FeedModule.EagerSingletons init);
default void injectFeedManagerEagerSingletons() {
injectBrambleCoreEagerSingletons();
inject(new BlogModule.EagerSingletons());
inject(new FeedModule.EagerSingletons());
}
IdentityManager getIdentityManager(); IdentityManager getIdentityManager();
LifecycleManager getLifecycleManager(); LifecycleManager getLifecycleManager();
@@ -49,4 +43,13 @@ interface FeedManagerIntegrationTestComponent
BlogManager getBlogManager(); BlogManager getBlogManager();
class Helper {
public static void injectEagerSingletons(
FeedManagerIntegrationTestComponent c) {
BrambleCoreEagerSingletons.Helper.injectEagerSingletons(c);
c.inject(new BlogModule.EagerSingletons());
c.inject(new FeedModule.EagerSingletons());
}
}
} }

View File

@@ -56,23 +56,23 @@ public class ForumManagerTest
protected void createComponents() { protected void createComponents() {
BriarIntegrationTestComponent component = BriarIntegrationTestComponent component =
DaggerBriarIntegrationTestComponent.builder().build(); DaggerBriarIntegrationTestComponent.builder().build();
component.injectBriarEagerSingletons(); BriarIntegrationTestComponent.Helper.injectEagerSingletons(component);
component.inject(this); component.inject(this);
c0 = DaggerBriarIntegrationTestComponent.builder() c0 = DaggerBriarIntegrationTestComponent.builder()
.testDatabaseConfigModule(new TestDatabaseConfigModule(t0Dir)) .testDatabaseConfigModule(new TestDatabaseConfigModule(t0Dir))
.build(); .build();
c0.injectBriarEagerSingletons(); BriarIntegrationTestComponent.Helper.injectEagerSingletons(c0);
c1 = DaggerBriarIntegrationTestComponent.builder() c1 = DaggerBriarIntegrationTestComponent.builder()
.testDatabaseConfigModule(new TestDatabaseConfigModule(t1Dir)) .testDatabaseConfigModule(new TestDatabaseConfigModule(t1Dir))
.build(); .build();
c1.injectBriarEagerSingletons(); BriarIntegrationTestComponent.Helper.injectEagerSingletons(c1);
c2 = DaggerBriarIntegrationTestComponent.builder() c2 = DaggerBriarIntegrationTestComponent.builder()
.testDatabaseConfigModule(new TestDatabaseConfigModule(t2Dir)) .testDatabaseConfigModule(new TestDatabaseConfigModule(t2Dir))
.build(); .build();
c2.injectBriarEagerSingletons(); BriarIntegrationTestComponent.Helper.injectEagerSingletons(c2);
} }
private ForumPost createForumPost(GroupId groupId, private ForumPost createForumPost(GroupId groupId,

View File

@@ -54,7 +54,8 @@ public class IntroductionCryptoIntegrationTest extends BrambleTestCase {
public IntroductionCryptoIntegrationTest() { public IntroductionCryptoIntegrationTest() {
IntroductionIntegrationTestComponent component = IntroductionIntegrationTestComponent component =
DaggerIntroductionIntegrationTestComponent.builder().build(); DaggerIntroductionIntegrationTestComponent.builder().build();
component.injectBriarEagerSingletons(); IntroductionIntegrationTestComponent.Helper
.injectEagerSingletons(component);
component.inject(this); component.inject(this);
crypto = new IntroductionCryptoImpl(cryptoComponent, clientHelper); crypto = new IntroductionCryptoImpl(cryptoComponent, clientHelper);

View File

@@ -114,23 +114,24 @@ public class IntroductionIntegrationTest
protected void createComponents() { protected void createComponents() {
IntroductionIntegrationTestComponent component = IntroductionIntegrationTestComponent component =
DaggerIntroductionIntegrationTestComponent.builder().build(); DaggerIntroductionIntegrationTestComponent.builder().build();
component.injectBriarEagerSingletons(); IntroductionIntegrationTestComponent.Helper
.injectEagerSingletons(component);
component.inject(this); component.inject(this);
c0 = DaggerIntroductionIntegrationTestComponent.builder() c0 = DaggerIntroductionIntegrationTestComponent.builder()
.testDatabaseConfigModule(new TestDatabaseConfigModule(t0Dir)) .testDatabaseConfigModule(new TestDatabaseConfigModule(t0Dir))
.build(); .build();
c0.injectBriarEagerSingletons(); IntroductionIntegrationTestComponent.Helper.injectEagerSingletons(c0);
c1 = DaggerIntroductionIntegrationTestComponent.builder() c1 = DaggerIntroductionIntegrationTestComponent.builder()
.testDatabaseConfigModule(new TestDatabaseConfigModule(t1Dir)) .testDatabaseConfigModule(new TestDatabaseConfigModule(t1Dir))
.build(); .build();
c1.injectBriarEagerSingletons(); IntroductionIntegrationTestComponent.Helper.injectEagerSingletons(c1);
c2 = DaggerIntroductionIntegrationTestComponent.builder() c2 = DaggerIntroductionIntegrationTestComponent.builder()
.testDatabaseConfigModule(new TestDatabaseConfigModule(t2Dir)) .testDatabaseConfigModule(new TestDatabaseConfigModule(t2Dir))
.build(); .build();
c2.injectBriarEagerSingletons(); IntroductionIntegrationTestComponent.Helper.injectEagerSingletons(c2);
} }
@Test @Test

View File

@@ -74,7 +74,8 @@ public class MessageEncoderParserIntegrationTest extends BrambleTestCase {
public MessageEncoderParserIntegrationTest() { public MessageEncoderParserIntegrationTest() {
IntroductionIntegrationTestComponent component = IntroductionIntegrationTestComponent component =
DaggerIntroductionIntegrationTestComponent.builder().build(); DaggerIntroductionIntegrationTestComponent.builder().build();
component.injectBriarEagerSingletons(); IntroductionIntegrationTestComponent.Helper
.injectEagerSingletons(component);
component.inject(this); component.inject(this);
messageEncoder = new MessageEncoderImpl(clientHelper, messageFactory); messageEncoder = new MessageEncoderImpl(clientHelper, messageFactory);

View File

@@ -83,7 +83,8 @@ public class SessionEncoderParserIntegrationTest extends BrambleTestCase {
public SessionEncoderParserIntegrationTest() { public SessionEncoderParserIntegrationTest() {
IntroductionIntegrationTestComponent component = IntroductionIntegrationTestComponent component =
DaggerIntroductionIntegrationTestComponent.builder().build(); DaggerIntroductionIntegrationTestComponent.builder().build();
component.injectBriarEagerSingletons(); IntroductionIntegrationTestComponent.Helper
.injectEagerSingletons(component);
component.inject(this); component.inject(this);
sessionEncoder = new SessionEncoderImpl(clientHelper); sessionEncoder = new SessionEncoderImpl(clientHelper);

View File

@@ -44,7 +44,8 @@ public class MessageSizeIntegrationTest extends BriarTestCase {
public MessageSizeIntegrationTest() { public MessageSizeIntegrationTest() {
MessageSizeIntegrationTestComponent component = MessageSizeIntegrationTestComponent component =
DaggerMessageSizeIntegrationTestComponent.builder().build(); DaggerMessageSizeIntegrationTestComponent.builder().build();
component.injectMessageSizeEagerSingletons(); MessageSizeIntegrationTestComponent.Helper
.injectEagerSingletons(component);
component.inject(this); component.inject(this);
} }

View File

@@ -27,9 +27,13 @@ interface MessageSizeIntegrationTestComponent
void inject(MessagingModule.EagerSingletons init); void inject(MessagingModule.EagerSingletons init);
default void injectMessageSizeEagerSingletons() { class Helper {
injectBrambleCoreEagerSingletons();
inject(new ForumModule.EagerSingletons()); public static void injectEagerSingletons(
inject(new MessagingModule.EagerSingletons()); MessageSizeIntegrationTestComponent c) {
BrambleCoreEagerSingletons.Helper.injectEagerSingletons(c);
c.inject(new ForumModule.EagerSingletons());
c.inject(new MessagingModule.EagerSingletons());
}
} }
} }

View File

@@ -68,23 +68,23 @@ public class MessagingManagerIntegrationTest
protected void createComponents() { protected void createComponents() {
BriarIntegrationTestComponent component = BriarIntegrationTestComponent component =
DaggerBriarIntegrationTestComponent.builder().build(); DaggerBriarIntegrationTestComponent.builder().build();
component.injectBriarEagerSingletons(); BriarIntegrationTestComponent.Helper.injectEagerSingletons(component);
component.inject(this); component.inject(this);
c0 = DaggerBriarIntegrationTestComponent.builder() c0 = DaggerBriarIntegrationTestComponent.builder()
.testDatabaseConfigModule(new TestDatabaseConfigModule(t0Dir)) .testDatabaseConfigModule(new TestDatabaseConfigModule(t0Dir))
.build(); .build();
c0.injectBriarEagerSingletons(); BriarIntegrationTestComponent.Helper.injectEagerSingletons(c0);
c1 = DaggerBriarIntegrationTestComponent.builder() c1 = DaggerBriarIntegrationTestComponent.builder()
.testDatabaseConfigModule(new TestDatabaseConfigModule(t1Dir)) .testDatabaseConfigModule(new TestDatabaseConfigModule(t1Dir))
.build(); .build();
c1.injectBriarEagerSingletons(); BriarIntegrationTestComponent.Helper.injectEagerSingletons(c1);
c2 = DaggerBriarIntegrationTestComponent.builder() c2 = DaggerBriarIntegrationTestComponent.builder()
.testDatabaseConfigModule(new TestDatabaseConfigModule(t2Dir)) .testDatabaseConfigModule(new TestDatabaseConfigModule(t2Dir))
.build(); .build();
c2.injectBriarEagerSingletons(); BriarIntegrationTestComponent.Helper.injectEagerSingletons(c2);
} }
@Test @Test

View File

@@ -60,11 +60,13 @@ public class SimplexMessagingIntegrationTest extends BriarTestCase {
alice = DaggerSimplexMessagingIntegrationTestComponent.builder() alice = DaggerSimplexMessagingIntegrationTestComponent.builder()
.testDatabaseConfigModule( .testDatabaseConfigModule(
new TestDatabaseConfigModule(aliceDir)).build(); new TestDatabaseConfigModule(aliceDir)).build();
alice.injectSimplexMessagingEagerSingletons(); SimplexMessagingIntegrationTestComponent.Helper
.injectEagerSingletons(alice);
bob = DaggerSimplexMessagingIntegrationTestComponent.builder() bob = DaggerSimplexMessagingIntegrationTestComponent.builder()
.testDatabaseConfigModule(new TestDatabaseConfigModule(bobDir)) .testDatabaseConfigModule(new TestDatabaseConfigModule(bobDir))
.build(); .build();
bob.injectSimplexMessagingEagerSingletons(); SimplexMessagingIntegrationTestComponent.Helper
.injectEagerSingletons(bob);
} }
@Test @Test

View File

@@ -28,11 +28,6 @@ interface SimplexMessagingIntegrationTestComponent
void inject(MessagingModule.EagerSingletons init); void inject(MessagingModule.EagerSingletons init);
default void injectSimplexMessagingEagerSingletons() {
injectBrambleCoreEagerSingletons();
inject(new MessagingModule.EagerSingletons());
}
LifecycleManager getLifecycleManager(); LifecycleManager getLifecycleManager();
IdentityManager getIdentityManager(); IdentityManager getIdentityManager();
@@ -46,4 +41,13 @@ interface SimplexMessagingIntegrationTestComponent
EventBus getEventBus(); EventBus getEventBus();
ConnectionManager getConnectionManager(); ConnectionManager getConnectionManager();
class Helper {
public static void injectEagerSingletons(
SimplexMessagingIntegrationTestComponent c) {
BrambleCoreEagerSingletons.Helper.injectEagerSingletons(c);
c.inject(new MessagingModule.EagerSingletons());
}
}
} }

View File

@@ -70,23 +70,23 @@ public class PrivateGroupIntegrationTest
protected void createComponents() { protected void createComponents() {
BriarIntegrationTestComponent component = BriarIntegrationTestComponent component =
DaggerBriarIntegrationTestComponent.builder().build(); DaggerBriarIntegrationTestComponent.builder().build();
component.injectBriarEagerSingletons(); BriarIntegrationTestComponent.Helper.injectEagerSingletons(component);
component.inject(this); component.inject(this);
c0 = DaggerBriarIntegrationTestComponent.builder() c0 = DaggerBriarIntegrationTestComponent.builder()
.testDatabaseConfigModule(new TestDatabaseConfigModule(t0Dir)) .testDatabaseConfigModule(new TestDatabaseConfigModule(t0Dir))
.build(); .build();
c0.injectBriarEagerSingletons(); BriarIntegrationTestComponent.Helper.injectEagerSingletons(c0);
c1 = DaggerBriarIntegrationTestComponent.builder() c1 = DaggerBriarIntegrationTestComponent.builder()
.testDatabaseConfigModule(new TestDatabaseConfigModule(t1Dir)) .testDatabaseConfigModule(new TestDatabaseConfigModule(t1Dir))
.build(); .build();
c1.injectBriarEagerSingletons(); BriarIntegrationTestComponent.Helper.injectEagerSingletons(c1);
c2 = DaggerBriarIntegrationTestComponent.builder() c2 = DaggerBriarIntegrationTestComponent.builder()
.testDatabaseConfigModule(new TestDatabaseConfigModule(t2Dir)) .testDatabaseConfigModule(new TestDatabaseConfigModule(t2Dir))
.build(); .build();
c2.injectBriarEagerSingletons(); BriarIntegrationTestComponent.Helper.injectEagerSingletons(c2);
} }
@Test @Test

View File

@@ -59,23 +59,23 @@ public class PrivateGroupManagerIntegrationTest
protected void createComponents() { protected void createComponents() {
BriarIntegrationTestComponent component = BriarIntegrationTestComponent component =
DaggerBriarIntegrationTestComponent.builder().build(); DaggerBriarIntegrationTestComponent.builder().build();
component.injectBriarEagerSingletons(); BriarIntegrationTestComponent.Helper.injectEagerSingletons(component);
component.inject(this); component.inject(this);
c0 = DaggerBriarIntegrationTestComponent.builder() c0 = DaggerBriarIntegrationTestComponent.builder()
.testDatabaseConfigModule(new TestDatabaseConfigModule(t0Dir)) .testDatabaseConfigModule(new TestDatabaseConfigModule(t0Dir))
.build(); .build();
c0.injectBriarEagerSingletons(); BriarIntegrationTestComponent.Helper.injectEagerSingletons(c0);
c1 = DaggerBriarIntegrationTestComponent.builder() c1 = DaggerBriarIntegrationTestComponent.builder()
.testDatabaseConfigModule(new TestDatabaseConfigModule(t1Dir)) .testDatabaseConfigModule(new TestDatabaseConfigModule(t1Dir))
.build(); .build();
c1.injectBriarEagerSingletons(); BriarIntegrationTestComponent.Helper.injectEagerSingletons(c1);
c2 = DaggerBriarIntegrationTestComponent.builder() c2 = DaggerBriarIntegrationTestComponent.builder()
.testDatabaseConfigModule(new TestDatabaseConfigModule(t2Dir)) .testDatabaseConfigModule(new TestDatabaseConfigModule(t2Dir))
.build(); .build();
c2.injectBriarEagerSingletons(); BriarIntegrationTestComponent.Helper.injectEagerSingletons(c2);
} }
@Test @Test

View File

@@ -66,23 +66,23 @@ public class GroupInvitationIntegrationTest
protected void createComponents() { protected void createComponents() {
BriarIntegrationTestComponent component = BriarIntegrationTestComponent component =
DaggerBriarIntegrationTestComponent.builder().build(); DaggerBriarIntegrationTestComponent.builder().build();
component.injectBriarEagerSingletons(); BriarIntegrationTestComponent.Helper.injectEagerSingletons(component);
component.inject(this); component.inject(this);
c0 = DaggerBriarIntegrationTestComponent.builder() c0 = DaggerBriarIntegrationTestComponent.builder()
.testDatabaseConfigModule(new TestDatabaseConfigModule(t0Dir)) .testDatabaseConfigModule(new TestDatabaseConfigModule(t0Dir))
.build(); .build();
c0.injectBriarEagerSingletons(); BriarIntegrationTestComponent.Helper.injectEagerSingletons(c0);
c1 = DaggerBriarIntegrationTestComponent.builder() c1 = DaggerBriarIntegrationTestComponent.builder()
.testDatabaseConfigModule(new TestDatabaseConfigModule(t1Dir)) .testDatabaseConfigModule(new TestDatabaseConfigModule(t1Dir))
.build(); .build();
c1.injectBriarEagerSingletons(); BriarIntegrationTestComponent.Helper.injectEagerSingletons(c1);
c2 = DaggerBriarIntegrationTestComponent.builder() c2 = DaggerBriarIntegrationTestComponent.builder()
.testDatabaseConfigModule(new TestDatabaseConfigModule(t2Dir)) .testDatabaseConfigModule(new TestDatabaseConfigModule(t2Dir))
.build(); .build();
c2.injectBriarEagerSingletons(); BriarIntegrationTestComponent.Helper.injectEagerSingletons(c2);
} }
@Test @Test

View File

@@ -82,23 +82,23 @@ public class BlogSharingIntegrationTest
protected void createComponents() { protected void createComponents() {
BriarIntegrationTestComponent component = BriarIntegrationTestComponent component =
DaggerBriarIntegrationTestComponent.builder().build(); DaggerBriarIntegrationTestComponent.builder().build();
component.injectBriarEagerSingletons(); BriarIntegrationTestComponent.Helper.injectEagerSingletons(component);
component.inject(this); component.inject(this);
c0 = DaggerBriarIntegrationTestComponent.builder() c0 = DaggerBriarIntegrationTestComponent.builder()
.testDatabaseConfigModule(new TestDatabaseConfigModule(t0Dir)) .testDatabaseConfigModule(new TestDatabaseConfigModule(t0Dir))
.build(); .build();
c0.injectBriarEagerSingletons(); BriarIntegrationTestComponent.Helper.injectEagerSingletons(c0);
c1 = DaggerBriarIntegrationTestComponent.builder() c1 = DaggerBriarIntegrationTestComponent.builder()
.testDatabaseConfigModule(new TestDatabaseConfigModule(t1Dir)) .testDatabaseConfigModule(new TestDatabaseConfigModule(t1Dir))
.build(); .build();
c1.injectBriarEagerSingletons(); BriarIntegrationTestComponent.Helper.injectEagerSingletons(c1);
c2 = DaggerBriarIntegrationTestComponent.builder() c2 = DaggerBriarIntegrationTestComponent.builder()
.testDatabaseConfigModule(new TestDatabaseConfigModule(t2Dir)) .testDatabaseConfigModule(new TestDatabaseConfigModule(t2Dir))
.build(); .build();
c2.injectBriarEagerSingletons(); BriarIntegrationTestComponent.Helper.injectEagerSingletons(c2);
} }
@Test @Test

View File

@@ -99,23 +99,23 @@ public class ForumSharingIntegrationTest
protected void createComponents() { protected void createComponents() {
BriarIntegrationTestComponent component = BriarIntegrationTestComponent component =
DaggerBriarIntegrationTestComponent.builder().build(); DaggerBriarIntegrationTestComponent.builder().build();
component.injectBriarEagerSingletons(); BriarIntegrationTestComponent.Helper.injectEagerSingletons(component);
component.inject(this); component.inject(this);
c0 = DaggerBriarIntegrationTestComponent.builder() c0 = DaggerBriarIntegrationTestComponent.builder()
.testDatabaseConfigModule(new TestDatabaseConfigModule(t0Dir)) .testDatabaseConfigModule(new TestDatabaseConfigModule(t0Dir))
.build(); .build();
c0.injectBriarEagerSingletons(); BriarIntegrationTestComponent.Helper.injectEagerSingletons(c0);
c1 = DaggerBriarIntegrationTestComponent.builder() c1 = DaggerBriarIntegrationTestComponent.builder()
.testDatabaseConfigModule(new TestDatabaseConfigModule(t1Dir)) .testDatabaseConfigModule(new TestDatabaseConfigModule(t1Dir))
.build(); .build();
c1.injectBriarEagerSingletons(); BriarIntegrationTestComponent.Helper.injectEagerSingletons(c1);
c2 = DaggerBriarIntegrationTestComponent.builder() c2 = DaggerBriarIntegrationTestComponent.builder()
.testDatabaseConfigModule(new TestDatabaseConfigModule(t2Dir)) .testDatabaseConfigModule(new TestDatabaseConfigModule(t2Dir))
.build(); .build();
c2.injectBriarEagerSingletons(); BriarIntegrationTestComponent.Helper.injectEagerSingletons(c2);
} }
private void addForumForSharer() throws DbException { private void addForumForSharer() throws DbException {

View File

@@ -69,17 +69,6 @@ public interface BriarIntegrationTestComponent
void inject(SharingModule.EagerSingletons init); void inject(SharingModule.EagerSingletons init);
default void injectBriarEagerSingletons() {
injectBrambleCoreEagerSingletons();
inject(new BlogModule.EagerSingletons());
inject(new ForumModule.EagerSingletons());
inject(new GroupInvitationModule.EagerSingletons());
inject(new IntroductionModule.EagerSingletons());
inject(new MessagingModule.EagerSingletons());
inject(new PrivateGroupModule.EagerSingletons());
inject(new SharingModule.EagerSingletons());
}
LifecycleManager getLifecycleManager(); LifecycleManager getLifecycleManager();
EventBus getEventBus(); EventBus getEventBus();
@@ -121,4 +110,19 @@ public interface BriarIntegrationTestComponent
BlogFactory getBlogFactory(); BlogFactory getBlogFactory();
ConnectionManager getConnectionManager(); ConnectionManager getConnectionManager();
class Helper {
public static void injectEagerSingletons(
BriarIntegrationTestComponent c) {
BrambleCoreEagerSingletons.Helper.injectEagerSingletons(c);
c.inject(new BlogModule.EagerSingletons());
c.inject(new ForumModule.EagerSingletons());
c.inject(new GroupInvitationModule.EagerSingletons());
c.inject(new IntroductionModule.EagerSingletons());
c.inject(new MessagingModule.EagerSingletons());
c.inject(new PrivateGroupModule.EagerSingletons());
c.inject(new SharingModule.EagerSingletons());
}
}
} }

View File

@@ -6,8 +6,8 @@ import com.github.ajalt.clikt.parameters.options.default
import com.github.ajalt.clikt.parameters.options.flag import com.github.ajalt.clikt.parameters.options.flag
import com.github.ajalt.clikt.parameters.options.option import com.github.ajalt.clikt.parameters.options.option
import com.github.ajalt.clikt.parameters.types.int import com.github.ajalt.clikt.parameters.types.int
import org.briarproject.bramble.BrambleCoreModule import org.briarproject.bramble.BrambleCoreEagerSingletons
import org.briarproject.briar.BriarCoreModule import org.briarproject.briar.BriarCoreEagerSingletons
import org.slf4j.impl.SimpleLogger.DEFAULT_LOG_LEVEL_KEY import org.slf4j.impl.SimpleLogger.DEFAULT_LOG_LEVEL_KEY
import org.spongycastle.util.encoders.Base64.toBase64String import org.spongycastle.util.encoders.Base64.toBase64String
import java.io.File import java.io.File
@@ -70,8 +70,8 @@ private class Main : CliktCommand(
DaggerBriarHeadlessApp.builder().headlessModule(HeadlessModule(dataDir)).build() DaggerBriarHeadlessApp.builder().headlessModule(HeadlessModule(dataDir)).build()
// We need to load the eager singletons directly after making the // We need to load the eager singletons directly after making the
// dependency graphs // dependency graphs
BrambleCoreModule.initEagerSingletons(app) BrambleCoreEagerSingletons.Helper.injectEagerSingletons(app)
BriarCoreModule.initEagerSingletons(app) BriarCoreEagerSingletons.Helper.injectEagerSingletons(app)
val authToken = getOrCreateAuthToken(dataDir, app.getSecureRandom()) val authToken = getOrCreateAuthToken(dataDir, app.getSecureRandom())

View File

@@ -3,9 +3,9 @@ package org.briarproject.briar.headless
import io.javalin.Javalin import io.javalin.Javalin
import io.javalin.core.util.Header.AUTHORIZATION import io.javalin.core.util.Header.AUTHORIZATION
import khttp.responses.Response import khttp.responses.Response
import org.briarproject.bramble.BrambleCoreModule import org.briarproject.bramble.BrambleCoreEagerSingletons
import org.briarproject.bramble.api.crypto.CryptoComponent import org.briarproject.bramble.api.crypto.CryptoComponent
import org.briarproject.briar.BriarCoreModule import org.briarproject.briar.BriarCoreEagerSingletons
import org.briarproject.briar.api.test.TestDataCreator import org.briarproject.briar.api.test.TestDataCreator
import org.junit.jupiter.api.AfterAll import org.junit.jupiter.api.AfterAll
import org.junit.jupiter.api.BeforeAll import org.junit.jupiter.api.BeforeAll
@@ -32,8 +32,8 @@ abstract class IntegrationTest {
val app = DaggerBriarHeadlessTestApp.builder() val app = DaggerBriarHeadlessTestApp.builder()
.headlessTestModule(HeadlessTestModule(dataDir)) .headlessTestModule(HeadlessTestModule(dataDir))
.build() .build()
BrambleCoreModule.initEagerSingletons(app) BrambleCoreEagerSingletons.Helper.injectEagerSingletons(app)
BriarCoreModule.initEagerSingletons(app) BriarCoreEagerSingletons.Helper.injectEagerSingletons(app)
router = app.getRouter() router = app.getRouter()
crypto = app.getCryptoComponent() crypto = app.getCryptoComponent()
testDataCreator = app.getTestDataCreator() testDataCreator = app.getTestDataCreator()