Skip to content

Commit

Permalink
inject services before activity is launched
Browse files Browse the repository at this point in the history
  • Loading branch information
avalax committed Dec 13, 2017
1 parent ca6def8 commit a1d4484
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import android.support.test.runner.AndroidJUnit4;

import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
Expand All @@ -22,6 +23,11 @@ public class FitbuddyAcceptanceTest {
public FitbuddyActivityTestRule activityRule = new FitbuddyActivityTestRule(
MainActivity.class);

@Before
public void setUp() throws Exception {
activityRule.launchActivity(null);
}

@Test
public void initialStart_shouldShowEmptyStartFragment() throws Exception {
application.showsStartBottomNavAsActive();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package de.avalax.fitbuddy.runner;

import android.support.test.InstrumentationRegistry;
import android.support.test.rule.ActivityTestRule;

import java.util.List;
Expand All @@ -25,14 +26,14 @@ public class FitbuddyActivityTestRule extends ActivityTestRule<MainActivity> {
FinishedWorkoutApplicationService finishedWorkoutApplicationService;

public FitbuddyActivityTestRule(Class<MainActivity> activityClass) {
super(activityClass);
super(activityClass, false, false);
TestFitbuddyApplication application = (TestFitbuddyApplication) InstrumentationRegistry.getTargetContext().getApplicationContext();
((TestComponent) application.getComponent()).inject(this);
}

@Override
protected void afterActivityLaunched() {
super.afterActivityLaunched();
TestFitbuddyApplication application = (TestFitbuddyApplication) getActivity().getApplication();
((TestComponent) application.getComponent()).inject(this);
}

public void deleteWorkouts() throws Exception {
Expand Down

0 comments on commit a1d4484

Please sign in to comment.