[dart-sdk] remove moduleContextFactory
TEST=
- fx set x64 --packages topaz/packages/buildbot
- fx run-host-tests
Change-Id: I0e0f55b89b460a7ffc00c8de62f0459eec976bc7
diff --git a/public/dart/fuchsia_modular/lib/src/module/internal/_module_impl.dart b/public/dart/fuchsia_modular/lib/src/module/internal/_module_impl.dart
index 7a621e6..2db24bf 100644
--- a/public/dart/fuchsia_modular/lib/src/module/internal/_module_impl.dart
+++ b/public/dart/fuchsia_modular/lib/src/module/internal/_module_impl.dart
@@ -31,17 +31,22 @@
IntentHandlerImpl _intentHandlerImpl;
/// Returns the [fidl.ModuleContext] for the running module.
- /// We allow injecting this method for testing purposes.
- fidl.ModuleContext Function() _getContext;
+ /// This varible should not be used directly. Use the
+ /// [getContext()] method instead
+ fidl.ModuleContext _moduleContext;
/// The default constructor for this instance.
+ ///
+ /// the [moduleContext] is an optional parameter that
+ /// can be supplied to override the default module context.
+ /// This is mainly useful in testing scenarios.
ModuleImpl({
@required IntentHandlerImpl intentHandlerImpl,
Lifecycle lifecycle,
- fidl.ModuleContextProxy Function() moduleContextFactory,
- }) : assert(intentHandlerImpl != null) {
+ fidl.ModuleContext moduleContext,
+ }) : _moduleContext = moduleContext,
+ assert(intentHandlerImpl != null) {
(lifecycle ??= Lifecycle()).addTerminateListener(_terminate);
- _getContext = moduleContextFactory ?? getModuleContext;
_intentHandlerImpl = intentHandlerImpl
..onHandleIntent = _proxyIntentToIntentHandler;
}
@@ -109,6 +114,8 @@
_intentHandler = intentHandler;
}
+ fidl.ModuleContext _getContext() => _moduleContext ??= getModuleContext();
+
void _proxyIntentToIntentHandler(Intent intent) {
if (_intentHandler == null) {
throw ModuleStateException(
diff --git a/public/dart/fuchsia_modular/test/module/internal/module_impl_integ_test.dart b/public/dart/fuchsia_modular/test/module/internal/module_impl_integ_test.dart
index 6aa1530..9ba5ebc 100644
--- a/public/dart/fuchsia_modular/test/module/internal/module_impl_integ_test.dart
+++ b/public/dart/fuchsia_modular/test/module/internal/module_impl_integ_test.dart
@@ -35,8 +35,8 @@
when(context.addModuleToStory(any, any, any, any))
.thenAnswer((_) => Future.value(fidl.StartModuleStatus.success));
- final moduleImpl = ModuleImpl(
- intentHandlerImpl: handlerImpl, moduleContextFactory: () => context);
+ final moduleImpl =
+ ModuleImpl(intentHandlerImpl: handlerImpl, moduleContext: context);
final ctrl = await moduleImpl.addModuleToStory(
name: 'testMod', intent: _emptyIntent);
@@ -50,8 +50,8 @@
when(context.addModuleToStory(any, any, any, any))
.thenAnswer((_) => Future.value(fidl.StartModuleStatus.noModulesFound));
- final moduleImpl = ModuleImpl(
- intentHandlerImpl: handlerImpl, moduleContextFactory: () => context);
+ final moduleImpl =
+ ModuleImpl(intentHandlerImpl: handlerImpl, moduleContext: context);
expect(moduleImpl.addModuleToStory(name: 'testMod', intent: _emptyIntent),
throwsA(const TypeMatcher<ModuleResolutionException>()));
@@ -63,8 +63,8 @@
when(context.addModuleToStory(any, any, any, any))
.thenAnswer((_) => Future.value(fidl.StartModuleStatus(-99)));
- final moduleImpl = ModuleImpl(
- intentHandlerImpl: handlerImpl, moduleContextFactory: () => context);
+ final moduleImpl =
+ ModuleImpl(intentHandlerImpl: handlerImpl, moduleContext: context);
expect(moduleImpl.addModuleToStory(name: 'testMod', intent: _emptyIntent),
throwsA(const TypeMatcher<ModuleStateException>()));
@@ -77,8 +77,8 @@
when(context.embedModule(any, any, any, any))
.thenAnswer((_) => Future.value(fidl.StartModuleStatus.noModulesFound));
- final moduleImpl = ModuleImpl(
- intentHandlerImpl: handlerImpl, moduleContextFactory: () => context);
+ final moduleImpl =
+ ModuleImpl(intentHandlerImpl: handlerImpl, moduleContext: context);
expect(moduleImpl.embedModule(name: 'testMod', intent: _emptyIntent),
throwsA(const TypeMatcher<ModuleResolutionException>()));
@@ -89,8 +89,8 @@
when(context.embedModule(any, any, any, any))
.thenAnswer((_) => Future.value(fidl.StartModuleStatus.success));
- final moduleImpl = ModuleImpl(
- intentHandlerImpl: handlerImpl, moduleContextFactory: () => context);
+ final moduleImpl =
+ ModuleImpl(intentHandlerImpl: handlerImpl, moduleContext: context);
expect(moduleImpl.embedModule(name: '', intent: _emptyIntent),
throwsArgumentError);
@@ -101,8 +101,8 @@
when(context.embedModule(any, any, any, any))
.thenAnswer((_) => Future.value(fidl.StartModuleStatus(-99)));
- final moduleImpl = ModuleImpl(
- intentHandlerImpl: handlerImpl, moduleContextFactory: () => context);
+ final moduleImpl =
+ ModuleImpl(intentHandlerImpl: handlerImpl, moduleContext: context);
expect(moduleImpl.embedModule(name: 'testMod', intent: _emptyIntent),
throwsA(const TypeMatcher<ModuleStateException>()));