private void injectTestResult(final ITestResult testResult) throws ReflectiveOperationException {

    final Object testInstance = testResult.getInstance();
    if (testInstance == null) {
      return;
    }

    final Class<?> testClass = testInstance.getClass();
    if (TESTS.containsKey(testClass)) {
      return;
    }

    final Dagger dagger = testClass.getAnnotation(Dagger.class);
    if (dagger == null) {
      return;
    }

    final Class<?>[] moduleClasses = dagger.modules();
    final Object[] moduleInstances = new Object[moduleClasses.length];
    for (int i = 0; i < moduleClasses.length; i++) {
      final Class<?> moduleClass = moduleClasses[i];
      if (moduleClass.getAnnotation(Module.class) == null) {
        continue;
      }
      moduleInstances[i] = MODULES.get(moduleClass);
      if (moduleInstances[i] == null) {
        moduleInstances[i] = moduleClass.newInstance();
        MODULES.put(moduleClass, moduleInstances[i]);
      }
    }

    ObjectGraph.create(moduleInstances).inject(testInstance);

    TESTS.put(testClass, testInstance);
  }
Beispiel #2
0
  private void inject() {
    // ObjectGraph.creat()方法需要一个Module类,作用是让ObjectGraph对象知道哪些类需要注入
    ObjectGraph objectGraph = ObjectGraph.create(getModules().toArray());
    objectGraph.inject(this);

    System.out.print("");
  }
 @Override
 public void onCreate() {
   super.onCreate();
   ActiveAndroid.initialize(this);
   mObjectGraph = ObjectGraph.create();
   mObjectGraph.inject(this);
 }
  @Override
  public void onCreate() {
    super.onCreate();

    self = this;

    objectGraph = ObjectGraph.create(getModules().toArray());
  }
  @Override
  public void onCreate() {
    super.onCreate();

    applicationGraph = ObjectGraph.create(getModules().toArray());

    applicationGraph.inject(this);
  }
  @Override
  public void run(DataConfiguration configuration, Environment environment)
      throws ClassNotFoundException {
    JmxReporter.forRegistry(environment.metrics()).build().start();

    ObjectGraph objectGraph = ObjectGraph.create(new DataModule(environment, configuration));
    environment.healthChecks().register("data", objectGraph.get(DataHealthCheck.class));
    environment.jersey().register(objectGraph.get(TodoResource.class));
  }
Beispiel #7
0
  @Before
  public void setUp() {
    initMocks(this);
    given(dataAccessFactory.people(any(Context.class))).willReturn(dataAccess);

    ObjectGraph.create(new AndroidModule(Robolectric.application), new TestModule()).inject(this);

    activity.onCreate(new Bundle());
  }
 private void setUpManager(long expiry, boolean isDPMEnabled) {
   ObjectGraph objectGraph = ObjectGraph.create(new TestPipelineManagerModule(expiry));
   RuntimeInfo info = objectGraph.get(RuntimeInfo.class);
   info.setDPMEnabled(isDPMEnabled);
   pipelineStoreTask = objectGraph.get(PipelineStoreTask.class);
   pipelineStateStore = objectGraph.get(PipelineStateStore.class);
   pipelineManager = new StandaloneAndClusterPipelineManager(objectGraph);
   pipelineManager.init();
 }
 @Override
 public void onCreate() {
   super.onCreate();
   objectGraph =
       ObjectGraph.create(
           new Object[] {
             new AppModule(MovieCheckApplication.this), new ApiModule(), new DaoModule()
           });
 }
Beispiel #10
0
 @Override
 public void onCreate() {
   super.onCreate();
   initData();
   initJPush();
   applicationGraph = ObjectGraph.create(new AndroidModule(this));
   applicationGraph.inject(this);
   notificationEventManager.register();
 }
 @Test
 public void testViaDagger() {
   DNSApiManager manager =
       ObjectGraph.create(
               provide(new Route53Provider()),
               new Route53Provider.Module(),
               credentials("accesskey", "secretkey"))
           .get(DNSApiManager.class);
   assertThat(manager.api().zones()).isInstanceOf(Route53ZoneApi.class);
 }
  @Override
  public void onCreate() {
    super.onCreate();

    // Setup debugging for butterknife
    ButterKnife.setDebug(BuildConfig.DEBUG);

    // Create ability to get instance
    sInstance = this;

    // Setup DI
    mGraph = ObjectGraph.create(getModules().toArray());
  }
  @Override
  public void setUp() throws Exception {
    super.setUp();

    System.setProperty("dexmaker.dexcache", getContext().getCacheDir().getPath());
    setupMocks();

    _app = new TestApplication();
    _app.setObjectGraph(ObjectGraph.create(new TestModule()));
    _app.inject(this);
    _bus.register(this);

    _command = new OruxMapsServiceCommand();
  }
  @Override
  public Object getSystemService(String name) {
    if (rootScope == null) {
      rootScope =
          MortarScope.buildRootScope()
              .withService(
                  ObjectGraphService.SERVICE_NAME, ObjectGraph.create(new ApplicationModule(this)))
              .build("Root");
    }

    if (rootScope.hasService(name)) return rootScope.getService(name);

    return super.getSystemService(name);
  }
  @Override
  public void setUp() throws Exception {
    super.setUp();

    System.setProperty("dexmaker.dexcache", getContext().getCacheDir().getPath());

    _app = new TestApplication();
    _app.setObjectGraph(ObjectGraph.create(TestModule.class));
    _app.inject(this);
    _bus.register(this);

    setupMocks();

    _pebbleDataReceiver = new PebbleDataReceiver();
    _stateLatch = new CountDownLatch(1);
  }
  @Override
  public void onCreate() {
    super.onCreate();

    applicationGraph = ObjectGraph.create(getModules().toArray());

    applicationGraph.inject(this);

    userProvider.fetch();

    /*UserProvider.get(new MemoryUserDataSource(
        Arrays.asList(new User[]{
            new User.Builder()
                    .setFirstName("John")
                    .setLastName("Brunton")
                    .getInstance()})
    )).fetch();*/
  }
Beispiel #17
0
  @Override
  public void onCreate() {
    super.onCreate();

    System.out.println(
        "JCC: APP STARTED ----------------------------------------------------------------------------------------------------");

    objectGraph = ObjectGraph.create(new ApplicationModule(this));
    objectGraph =
        objectGraph.plus(
            new PojoEventBusModule(),
            new DomainEventBusModule(this),
            new LoginEventBusModule(this));

    objectGraph.inject(this);

    UIComponentCache = new UIComponentCache();
  }
  private void setupMockServer(HashMap<String, String> override_map) {
    HashMap<String, String> map = new HashMap<>(Util.RESPONSE_MAP);

    if (override_map != null) {
      for (String key : override_map.keySet()) {
        map.put(key, override_map.get(key));
      }
    }

    Instrumentation instrumentation = InstrumentationRegistry.getInstrumentation();
    AndroidApplication app =
        (AndroidApplication) instrumentation.getTargetContext().getApplicationContext();

    // setup objectGraph to inject Mock API
    List modules = Collections.singletonList(new DummyAPIModule(map));
    ObjectGraph graph = ObjectGraph.create(modules.toArray());
    app.setObjectGraph(graph);
    app.getObjectGraph().inject(app);
  }
  @Override
  public void onCreate() {
    super.onCreate();
    // Parse.initialize(this, "64LrLB3jNDJQq8sSApLLHUWbjv2wmiACyemSLfN3",
    // "u1rLwcDJzwZuNYa06M0ODtsMqmNbYU9MPKwnjG3E");

    mPlusClient =
        new GoogleApiClient.Builder(this)
            .addApi(Plus.API, null)
            .addScope(Plus.SCOPE_PLUS_LOGIN)
            .addScope(Plus.SCOPE_PLUS_PROFILE)
            .build();
    mPlusClient.connect();

    graph = ObjectGraph.create(getModules().toArray());
    for (final Object obj : injectList) {
      graph.inject(obj);
    }
    injectList.clear();
  }
  @Override
  public void onCreate() {
    super.onCreate();
    AndroidThreeTen.init(this);
    LeakCanary.install(this);

    if (BuildConfig.DEBUG) {
      Timber.plant(new DebugTree());
    } else {
      // TODO Crashlytics.start(this);
      // TODO Timber.plant(new CrashlyticsTree());
    }

    objectGraph = ObjectGraph.create(Modules.list(this));
    objectGraph.inject(this);

    lumberYard.cleanUp();
    Timber.plant(lumberYard.tree());

    registerActivityLifecycleCallbacks(activityHierarchyServer);
  }
  @Override
  protected void setUp() throws Exception {
    super.setUp();

    this.getInstrumentation()
        .waitForIdleSync(); // this is needed for emulator versions 2.3 as the application is
                            // instantiated on a separate thread.
    TestApplication app =
        (TestApplication) this.getInstrumentation().getTargetContext().getApplicationContext();

    app.setObjectGraph(ObjectGraph.create(new TestModule()));
    app.inject(this);

    setupMocks();

    setActivityInitialTouchMode(false);

    _activity = getActivity();

    startFragment(new SpeedFragment());

    _speedLabel = (TextView) _activity.findViewById(R.id.speed_label);
    _speedText = (TextView) _activity.findViewById(R.id.speed_text);
    _speedUnitsLabel = (TextView) _activity.findViewById(R.id.speed_units_label);

    _timeLabel = (TextView) _activity.findViewById(R.id.time_label);
    _timeText = (TextView) _activity.findViewById(R.id.time_text);

    _distanceLabel = (TextView) _activity.findViewById(R.id.distance_label);
    _distanceText = (TextView) _activity.findViewById(R.id.distance_text);
    _distanceUnitsLabel = (TextView) _activity.findViewById(R.id.distance_units_label);

    _avgspeedLabel = (TextView) _activity.findViewById(R.id.avgspeed_label);
    _avgspeedText = (TextView) _activity.findViewById(R.id.avgspeed_text);
    _avgspeedUnitsLabel = (TextView) _activity.findViewById(R.id.avgspeed_units_label);
  }
 /* (non-Javadoc)
  * @see android.app.Application#onCreate()
  */
 @Override
 public void onCreate() {
   super.onCreate();
   // Initialize dependency graph.
   objectGraph = ObjectGraph.create(new ContainerModule());
 }
 @BeforeClass
 public static void setupSilkDi() {
   ObjectGraph objectGraph = ObjectGraph.create(new DependencyModule());
   AncientBattleShipApp ancientBattleShipApp = objectGraph.get(AncientBattleShipApp.class);
   oceanEventService = ancientBattleShipApp.getOceanService();
 }
 public MusicVisualizer() {
   ObjectGraph objectGraph = ObjectGraph.create(new DaggerModule(this));
   objectGraph.inject(this);
 }
Beispiel #25
0
 public static void main(String[] args) {
   ObjectGraph.create(new TestModule()).get(TestApp.class).run();
 }
 @Override
 public void run(ServiceConfiguration serviceConfiguration, Environment environment)
     throws Exception {
   ObjectGraph objectGraph = ObjectGraph.create(new DaggerModule());
   environment.addResource(objectGraph.get(HelloWorldService.class));
 }
 private void initializeDagger() {
   objectGraph = ObjectGraph.create(new ProductListModule());
 }
Beispiel #28
0
 public void inject() {
   ObjectGraph.create(new TestModule(Robolectric.application.getApplicationContext()))
       .inject(this);
 }
Beispiel #29
0
 @VisibleForTesting
 protected Main(Class moduleClass) {
   this(ObjectGraph.create(moduleClass), null);
 }
 private void buildObjectGraphAndInject() {
   objectGraph = ObjectGraph.create(Modules.list(this));
   objectGraph.inject(this);
 }