Search in sources :

Example 11 with ObjectGraph

use of dagger.ObjectGraph in project u2020 by JakeWharton.

the class OauthService method onCreate.

@Override
public void onCreate() {
    super.onCreate();
    ObjectGraph appGraph = Injector.obtain(getApplication());
    appGraph.inject(this);
}
Also used : ObjectGraph(dagger.ObjectGraph)

Example 12 with ObjectGraph

use of dagger.ObjectGraph in project u2020 by JakeWharton.

the class MainActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    LayoutInflater inflater = getLayoutInflater();
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        // Remove the status bar color. The DrawerLayout is responsible for drawing it from now on.
        setStatusBarColor(getWindow());
    }
    // Explicitly reference the application object since we don't want to match our own injector.
    ObjectGraph appGraph = Injector.obtain(getApplication());
    appGraph.inject(this);
    activityGraph = appGraph.plus(new MainActivityModule(this));
    ViewGroup container = viewContainer.forActivity(this);
    inflater.inflate(R.layout.main_activity, container);
    ButterKnife.bind(this, container);
    drawerLayout.setStatusBarBackgroundColor(statusBarColor);
    drawerLayout.setDrawerShadow(R.drawable.drawer_shadow, GravityCompat.START);
    drawer.setNavigationItemSelectedListener(item -> {
        switch(item.getItemId()) {
            case R.id.nav_search:
                Toast.makeText(MainActivity.this, "Search!", LENGTH_SHORT).show();
                break;
            case R.id.nav_trending:
                Toast.makeText(MainActivity.this, "Trending!", LENGTH_SHORT).show();
                break;
            default:
                throw new IllegalStateException("Unknown navigation item: " + item.getTitle());
        }
        drawerLayout.closeDrawers();
        return true;
    });
    inflater.inflate(R.layout.trending_view, content);
}
Also used : ViewGroup(android.view.ViewGroup) LayoutInflater(android.view.LayoutInflater) ObjectGraph(dagger.ObjectGraph)

Example 13 with ObjectGraph

use of dagger.ObjectGraph in project mortar by square.

the class ObjectGraphServiceTest method getActivityScopeWithOneModule.

@Test
public void getActivityScopeWithOneModule() {
    MortarScope root = createRootScope(ObjectGraph.create(new AppleModule()));
    String name = Bagel.class.getName();
    MortarScope activityScope = root.buildChild().withService(SERVICE_NAME, create(root, new BagelModule())).build(name);
    ObjectGraph objectGraph = getObjectGraph(activityScope);
    assertThat(objectGraph.get(HasApple.class).string).isEqualTo(Apple.class.getName());
    assertThat(objectGraph.get(HasBagel.class).string).isEqualTo(Bagel.class.getName());
    try {
        objectGraph.get(HasCarrot.class);
        fail("Expected IllegalArgumentException");
    } catch (IllegalArgumentException e) {
    // pass
    }
}
Also used : ObjectGraph(dagger.ObjectGraph) ObjectGraphService.getObjectGraph(mortar.dagger1support.ObjectGraphService.getObjectGraph) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.junit.Test)

Example 14 with ObjectGraph

use of dagger.ObjectGraph in project mortar by square.

the class ObjectGraphServiceTest method requireGrandchildWithMoreModules.

@Test
public void requireGrandchildWithMoreModules() {
    MortarScope root = createRootScope(ObjectGraph.create(new AppleModule()));
    MortarScope activityScope = root.buildChild().withService(SERVICE_NAME, create(root, new BagelModule())).build("activity");
    MortarScope child = activityScope.buildChild().withService(SERVICE_NAME, create(activityScope, new CarrotModule())).build("child");
    MortarScope grandchild = child.buildChild().withService(SERVICE_NAME, create(child, new DogfoodModule(), new EggplanModule())).build("grandchild");
    ObjectGraph objectGraph = getObjectGraph(grandchild);
    assertThat(objectGraph.get(HasApple.class).string).isEqualTo(Apple.class.getName());
    assertThat(objectGraph.get(HasBagel.class).string).isEqualTo(Bagel.class.getName());
    assertThat(objectGraph.get(HasCarrot.class).string).isEqualTo(Carrot.class.getName());
    assertThat(objectGraph.get(HasDogfood.class).string).isEqualTo(Dogfood.class.getName());
    assertThat(objectGraph.get(HasEggplant.class).string).isEqualTo(Eggplant.class.getName());
    try {
        objectGraph.get(String.class);
        fail("Expected IllegalArgumentException");
    } catch (IllegalArgumentException e) {
    // pass
    }
}
Also used : ObjectGraph(dagger.ObjectGraph) ObjectGraphService.getObjectGraph(mortar.dagger1support.ObjectGraphService.getObjectGraph) Test(org.junit.Test)

Example 15 with ObjectGraph

use of dagger.ObjectGraph in project mortar by square.

the class ObjectGraphServiceTest method requireGrandchildWithNoModules.

@Test
public void requireGrandchildWithNoModules() {
    MortarScope root = createRootScope(ObjectGraph.create(new AppleModule()));
    MortarScope activityScope = root.buildChild().withService(SERVICE_NAME, create(root, new BagelModule())).build("activity");
    MortarScope child = activityScope.buildChild().withService(SERVICE_NAME, create(activityScope, new CarrotModule())).build("child");
    MortarScope grandchild = child.buildChild().build("grandchild");
    ObjectGraph objectGraph = getObjectGraph(grandchild);
    assertThat(objectGraph.get(HasApple.class).string).isEqualTo(Apple.class.getName());
    assertThat(objectGraph.get(HasBagel.class).string).isEqualTo(Bagel.class.getName());
    assertThat(objectGraph.get(HasCarrot.class).string).isEqualTo(Carrot.class.getName());
    try {
        objectGraph.get(String.class);
        fail("Expected IllegalArgumentException");
    } catch (IllegalArgumentException e) {
    // pass
    }
}
Also used : ObjectGraph(dagger.ObjectGraph) ObjectGraphService.getObjectGraph(mortar.dagger1support.ObjectGraphService.getObjectGraph) Test(org.junit.Test)

Aggregations

ObjectGraph (dagger.ObjectGraph)19 Test (org.junit.Test)8 Before (org.junit.Before)7 TestModule (com.tevinjeffrey.rutgersct.TestModule)6 ObjectGraphService.getObjectGraph (mortar.dagger1support.ObjectGraphService.getObjectGraph)6 BaseUnitTest (org.thoughtcrime.securesms.BaseUnitTest)2 SignalServiceMessageSender (org.whispersystems.signalservice.api.SignalServiceMessageSender)2 SignalServiceAddress (org.whispersystems.signalservice.api.push.SignalServiceAddress)2 Context (android.content.Context)1 LayoutInflater (android.view.LayoutInflater)1 ViewGroup (android.view.ViewGroup)1 MainApplication (com.karumi.rosie.sample.main.MainApplication)1 IOException (java.io.IOException)1 LinkedList (java.util.LinkedList)1 Matchers.anyString (org.mockito.Matchers.anyString)1 NotFoundException (org.whispersystems.signalservice.api.push.exceptions.NotFoundException)1 PushNetworkException (org.whispersystems.signalservice.api.push.exceptions.PushNetworkException)1