/*
 * Copyright (C) 2015 Karumi.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.github.katasuperheroes;

import android.support.test.InstrumentationRegistry;
import android.support.test.rule.ActivityTestRule;
import android.support.test.runner.AndroidJUnit4;
import android.test.suitebuilder.annotation.LargeTest;
import com.github.katasuperheroes.di.MainComponent;
import com.github.katasuperheroes.di.MainModule;
import com.github.katasuperheroes.model.SuperHeroesRepository;
import com.github.katasuperheroes.ui.view.MainActivity;
import github.com.katasuperheroes.R;
import it.cosenonjaviste.daggermock.DaggerMockRule;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;

import static android.support.test.espresso.Espresso.onView;
import static android.support.test.espresso.assertion.ViewAssertions.matches;
import static android.support.test.espresso.matcher.ViewMatchers.isDisplayed;
import static android.support.test.espresso.matcher.ViewMatchers.withId;

@RunWith(AndroidJUnit4.class) @LargeTest public class MainActivityTest {

  @Rule public DaggerMockRule<MainComponent> daggerRule =
      new DaggerMockRule<>(MainComponent.class, new MainModule()).set(
          new DaggerMockRule.ComponentSetter<MainComponent>() {
            @Override public void setComponent(MainComponent component) {
              SuperHeroesApplication app =
                  (SuperHeroesApplication) InstrumentationRegistry.getInstrumentation()
                      .getTargetContext()
                      .getApplicationContext();
              app.setComponent(component);
            }
          });

  @Rule public ActivityTestRule<MainActivity> activityRule =
      new ActivityTestRule<>(MainActivity.class);

  @Mock SuperHeroesRepository repository;

  @Test public void test1() {
    activityRule.getActivity();

    onView(withId(R.id.recycler_view)).check(matches(isDisplayed()));
  }
}
@@ -928,24 +928,75 @@
 MainModule;%0A
+import com.github.katasuperheroes.model.SuperHero;%0A
 import com.g
@@ -1042,24 +1042,24 @@
 Repository;%0A
-
 import com.g
@@ -1187,24 +1187,54 @@
 erMockRule;%0A
+import java.util.Collections;%0A
 import org.j
@@ -1615,16 +1615,56 @@
 .withId;
+%0Aimport static org.mockito.Mockito.when;
 %0A%0A@RunWi
@@ -2399,16 +2399,30 @@
 ty.class
+, false, false
 );%0A%0A  @M
@@ -2486,24 +2486,103 @@
 d test1() %7B%0A
+    when(repository.getAll()).thenReturn(Collections.%3CSuperHero%3EemptyList());%0A%0A
     activity
@@ -2586,19 +2586,22 @@
 ityRule.
-get
+launch
 Activity
@@ -2601,16 +2601,20 @@
 ctivity(
+null
 );%0A%0A    

Change activityRule to do not launch activity by default