package com.soundcloud.lightcycle;

import static org.mockito.Mockito.verify;

import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;

import android.app.Activity;
import android.app.Fragment;
import android.os.Bundle;
import android.view.View;

@RunWith(MockitoJUnitRunner.class)
public class FragmentLightCycleDispatcherTest {
    @Mock private FragmentLightCycle<Fragment> lifeCycleComponent1;
    @Mock private FragmentLightCycle<Fragment> lifeCycleComponent2;
    @Mock private Fragment fragment;
    @Mock private Activity activity;
    private FragmentLightCycleDispatcher<Fragment> dispatcher;

    @Before
    public void setUp() throws Exception {
        dispatcher = new FragmentLightCycleDispatcher<>();
        dispatcher.bind(lifeCycleComponent1);
        dispatcher.bind(lifeCycleComponent2);
    }

    @Test
    public void shouldNotifyOnAttach() {
        dispatcher.onAttach(fragment, activity);

        verify(lifeCycleComponent1).onAttach(fragment, activity);
        verify(lifeCycleComponent2).onAttach(fragment, activity);
    }

    @Test
    public void shouldNotifyOnCreate() {
        final Bundle bundle = new Bundle();

        dispatcher.onCreate(fragment, bundle);

        verify(lifeCycleComponent1).onCreate(fragment, bundle);
        verify(lifeCycleComponent2).onCreate(fragment, bundle);
    }

    @Test
    public void shouldNotifyOnStart() {
        dispatcher.onStart(fragment);

        verify(lifeCycleComponent1).onStart(fragment);
        verify(lifeCycleComponent2).onStart(fragment);
    }

    @Test
    public void shouldNotifyOnResume() {
        dispatcher.onResume(fragment);

        verify(lifeCycleComponent1).onResume(fragment);
        verify(lifeCycleComponent2).onResume(fragment);
    }

    @Test
    public void shouldNotifyOnPause() {
        dispatcher.onPause(fragment);

        verify(lifeCycleComponent1).onPause(fragment);
        verify(lifeCycleComponent2).onPause(fragment);
    }

    @Test
    public void shouldNotifyOnStop() {
        dispatcher.onStop(fragment);

        verify(lifeCycleComponent1).onStop(fragment);
        verify(lifeCycleComponent2).onStop(fragment);
    }

    @Test
    public void shouldNotifyOnSaveInstanceState() {
        final Bundle bundle = new Bundle();

        dispatcher.onSaveInstanceState(fragment, bundle);

        verify(lifeCycleComponent1).onSaveInstanceState(fragment, bundle);
        verify(lifeCycleComponent2).onSaveInstanceState(fragment, bundle);
    }

    @Test
    public void shouldNotifyOnRestoreInstanceState() {
        final Bundle bundle = new Bundle();

        dispatcher.onRestoreInstanceState(fragment, bundle);

        verify(lifeCycleComponent1).onRestoreInstanceState(fragment, bundle);
        verify(lifeCycleComponent2).onRestoreInstanceState(fragment, bundle);
    }

    @Test
    public void shouldNotifyOnDestroy() {
        dispatcher.onDestroy(fragment);

        verify(lifeCycleComponent1).onDestroy(fragment);
        verify(lifeCycleComponent2).onDestroy(fragment);
    }

    @Test
    public void shouldNotifyOnDetach() {
        dispatcher.onDetach(fragment);

        verify(lifeCycleComponent1).onDetach(fragment);
        verify(lifeCycleComponent2).onDetach(fragment);
    }

    @Test
    public void shouldNotifyOnViewCreated() {
        final Bundle bundle = new Bundle();
        final View view = new View(activity);

        dispatcher.onViewCreated(fragment, view, bundle);

        verify(lifeCycleComponent1).onViewCreated(fragment, view, bundle);
        verify(lifeCycleComponent2).onViewCreated(fragment, view, bundle);
    }

    @Test
    public void shouldNotifyOnDestroyView() {
        dispatcher.onDestroyView(fragment);

        verify(lifeCycleComponent1).onDestroyView(fragment);
        verify(lifeCycleComponent2).onDestroyView(fragment);
    }
}

@@ -29,16 +29,56 @@
 cycle;%0A%0A
+import static org.mockito.Mockito.mock;%0A
 import s
@@ -111,16 +111,16 @@
 verify;%0A
-
 %0Aimport 
@@ -1263,37 +1263,37 @@
 dle bundle =
- new
  Bundle
-()
+.EMPTY
 ;%0A%0A        d
@@ -2377,37 +2377,37 @@
 dle bundle =
- new
  Bundle
-()
+.EMPTY
 ;%0A%0A        d
@@ -2707,29 +2707,29 @@
 bundle =
- new
  Bundle
-()
+.EMPTY
 ;%0A%0A     
@@ -3461,21 +3461,21 @@
 le =
- new
  Bundle
-()
+.EMPTY
 ;%0A  
@@ -3502,25 +3502,23 @@
 w = 
-new View(activity
+mock(View.class
 );%0A%0A

Update native fragment tests after merging PR “Add support for native fragments”.