package com.android.support.lifecycle;

import static com.android.support.lifecycle.Lifecycle.CREATED;
import static com.android.support.lifecycle.Lifecycle.DESTROYED;
import static com.android.support.lifecycle.Lifecycle.FINISHED;
import static com.android.support.lifecycle.Lifecycle.INITIALIZED;
import static com.android.support.lifecycle.Lifecycle.PAUSED;
import static com.android.support.lifecycle.Lifecycle.RESUMED;
import static com.android.support.lifecycle.Lifecycle.STARTED;
import static com.android.support.lifecycle.Lifecycle.STOPPED;

import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.reset;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;

@RunWith(JUnit4.class)
public class ReflectiveGenericLifecycleObserverTest {
    LifecycleProvider provider;
    Lifecycle lifecycle;

    @Before
    public void initMocks() {
        provider = mock(LifecycleProvider.class);
        lifecycle = mock(Lifecycle.class);
        when(provider.getLifecycle()).thenReturn(lifecycle);
    }

    @Test
    public void anyState() {
        AnyStateListener obj = mock(AnyStateListener.class);
        ReflectiveGenericLifecycleObserver observer = new ReflectiveGenericLifecycleObserver(obj);
        when(lifecycle.getCurrentState()).thenReturn(STARTED);
        observer.onStateChanged(provider, CREATED);
        verify(obj).onAnyState();
        reset(obj);

        observer.onStateChanged(provider, STARTED);
        verify(obj).onAnyState();
        reset(obj);

        observer.onStateChanged(provider, RESUMED);
        verify(obj).onAnyState();
        reset(obj);

        observer.onStateChanged(provider, PAUSED);
        verify(obj).onAnyState();
        reset(obj);

        observer.onStateChanged(provider, STOPPED);
        verify(obj).onAnyState();
        reset(obj);

        observer.onStateChanged(provider, DESTROYED);
        verify(obj).onAnyState();
        reset(obj);

        observer.onStateChanged(provider, FINISHED);
        verify(obj).onAnyState();
        reset(obj);
    }

    private static class AnyStateListener implements LifecycleObserver {
        @OnState(Lifecycle.ANY)
        public void onAnyState() {

        }
    }

    @Test
    public void onCreated() {
        CreatedStateListener obj = mock(CreatedStateListener.class);
        ReflectiveGenericLifecycleObserver observer = new ReflectiveGenericLifecycleObserver(obj);
        when(lifecycle.getCurrentState()).thenReturn(CREATED);
        observer.onStateChanged(provider, INITIALIZED);
        verify(obj).onCreated();
        verify(obj).onCreated(provider);
        verify(obj).onCreated(provider, INITIALIZED);
    }

    private static class CreatedStateListener implements LifecycleObserver {
        @OnState(Lifecycle.CREATED)
        public void onCreated() {

        }
        @OnState(Lifecycle.CREATED)
        public void onCreated(LifecycleProvider provider) {

        }
        @OnState(Lifecycle.CREATED)
        public void onCreated(LifecycleProvider provider, int prevState) {

        }
    }
}

@@ -2360,32 +2360,35 @@
 public void 
-onCreate
+singleMetho
 d() %7B%0A      
@@ -2893,34 +2893,24 @@
    @OnState(
-Lifecycle.
 CREATED)%0A   
@@ -2964,34 +2964,24 @@
    @OnState(
-Lifecycle.
 CREATED)%0A   
@@ -3065,26 +3065,16 @@
 OnState(
-Lifecycle.
 CREATED)
@@ -3146,24 +3146,24 @@
 evState) %7B%0A%0A
-
         %7D%0A  
@@ -3165,11 +3165,1902 @@
  %7D%0A    %7D
+%0A%0A    @Test%0A    public void eachEvent() %7B%0A        AllMethodsListener obj = mock(AllMethodsListener.class);%0A        ReflectiveGenericLifecycleObserver observer = new ReflectiveGenericLifecycleObserver(obj);%0A        when(lifecycle.getCurrentState()).thenReturn(CREATED);%0A%0A        observer.onStateChanged(provider, CREATED);%0A        verify(obj).created();%0A        reset(obj);%0A%0A        when(lifecycle.getCurrentState()).thenReturn(STARTED);%0A        observer.onStateChanged(provider, CREATED);%0A        verify(obj).started();%0A        reset(obj);%0A%0A        when(lifecycle.getCurrentState()).thenReturn(RESUMED);%0A        observer.onStateChanged(provider, STARTED);%0A        verify(obj).resumed();%0A        reset(obj);%0A%0A        when(lifecycle.getCurrentState()).thenReturn(PAUSED);%0A        observer.onStateChanged(provider, RESUMED);%0A        verify(obj).paused();%0A        reset(obj);%0A%0A        when(lifecycle.getCurrentState()).thenReturn(STOPPED);%0A        observer.onStateChanged(provider, PAUSED);%0A        verify(obj).stopped();%0A        reset(obj);%0A%0A        when(lifecycle.getCurrentState()).thenReturn(DESTROYED);%0A        observer.onStateChanged(provider, STOPPED);%0A        verify(obj).destroyed();%0A        reset(obj);%0A%0A        when(lifecycle.getCurrentState()).thenReturn(FINISHED);%0A        observer.onStateChanged(provider, DESTROYED);%0A        verify(obj).finished();%0A        reset(obj);%0A    %7D%0A%0A%0A    private static class AllMethodsListener implements LifecycleObserver %7B%0A        @OnState(CREATED)%0A        public void created() %7B%7D%0A%0A        @OnState(STARTED)%0A        public void started() %7B%7D%0A%0A        @OnState(RESUMED)%0A        public void resumed() %7B%7D%0A%0A        @OnState(PAUSED)%0A        public void paused() %7B%7D%0A%0A        @OnState(STOPPED)%0A        public void stopped() %7B%7D%0A%0A        @OnState(DESTROYED)%0A        public void destroyed() %7B%7D%0A%0A        @OnState(FINISHED)%0A        public void finished() %7B%7D%0A    %7D
 %0A%7D%0A

Extend reflective lifecycle coverage.