@@ -0,0 +1,2994 @@
+package com.episode6.hackit.mockspresso.internal;%0A%0Aimport com.episode6.hackit.mockspresso.DefaultTestRunner;%0Aimport com.episode6.hackit.mockspresso.Mockspresso;%0Aimport org.junit.After;%0Aimport org.junit.Before;%0Aimport org.junit.Test;%0Aimport org.junit.runner.RunWith;%0Aimport org.mockito.InOrder;%0Aimport org.mockito.Mock;%0Aimport org.mockito.Mockito;%0Aimport org.mockito.MockitoAnnotations;%0A%0Aimport java.util.ArrayList;%0Aimport java.util.List;%0A%0Aimport static org.mockito.Mockito.mock;%0Aimport static org.mockito.Mockito.verifyNoMoreInteractions;%0A%0A/**%0A * Tests %7B@link ResourcesLifecycleMethodManager%7D%0A */%0A@RunWith(DefaultTestRunner.class)%0Apublic class ResourcesLifecycleMethodManagerTest %7B%0A%0A  @Mock Mockspresso mMockspresso;%0A%0A  final SampleTestRes testRes1 = new SampleTestRes();%0A  final SampleTestResSubclass testRes2 = new SampleTestResSubclass();%0A  final SampleTestRes testRes3 = new SampleTestRes();%0A%0A  List%3CTestResource%3E mTestResources;%0A  ResourcesLifecycleMethodManager mResourcesLifecycleMethodManager;%0A%0A  @Before%0A  public void setup() %7B%0A    MockitoAnnotations.initMocks(this);%0A%0A    mTestResources = new ArrayList%3C%3E(3);%0A    mTestResources.add(new TestResource(testRes1, true));%0A    mTestResources.add(new TestResource(testRes2, true));%0A    mTestResources.add(new TestResource(testRes3, false));%0A%0A    mResourcesLifecycleMethodManager = new ResourcesLifecycleMethodManager(mTestResources);%0A  %7D%0A%0A  @Test%0A  public void testSetupOrder() %7B%0A    mResourcesLifecycleMethodManager.setup(mMockspresso);%0A%0A    InOrder inOrder = Mockito.inOrder(getMocks());%0A    inOrder.verify(testRes1.notifier).setup();%0A    inOrder.verify(testRes2.notifier).setup();%0A    inOrder.verify(testRes2.subclassNotifier).setup(mMockspresso);%0A    verifyNoMoreInteractions(getMocks());%0A  %7D%0A%0A  @Test%0A  public void testTeardownOrder() %7B%0A    mResourcesLifecycleMethodManager.teardown();%0A%0A    InOrder inOrder = Mockito.inOrder(getMocks());%0A    inOrder.verify(testRes2.subclassNotifier).teardown();%0A    inOrder.verify(testRes2.notifier).teardown();%0A    inOrder.verify(testRes1.notifier).teardown();%0A    verifyNoMoreInteractions(getMocks());%0A  %7D%0A%0A  private Object%5B%5D getMocks() %7B%0A    return new Object%5B%5D %7BtestRes1.notifier, testRes2.subclassNotifier, testRes2.notifier, testRes3.notifier%7D;%0A  %7D%0A%0A  interface Notifier %7B%0A    void setup();%0A    void setup(Mockspresso instance);%0A    void teardown();%0A  %7D%0A%0A  // since test resource methods are found via annotation, we cant mock or spy them%0A  private class SampleTestRes %7B%0A    Notifier notifier = mock(Notifier.class);%0A%0A    @Before%0A    public void setup() %7B%0A      notifier.setup();%0A    %7D%0A%0A    @After%0A    public void teardown() %7B%0A      notifier.teardown();%0A    %7D%0A  %7D%0A%0A  private class SampleTestResSubclass extends SampleTestRes %7B%0A    Notifier subclassNotifier = mock(Notifier.class);%0A%0A    @Before%0A    public void setupSubclass(Mockspresso mockspresso) %7B%0A      subclassNotifier.setup(mockspresso);%0A    %7D%0A%0A    @After%0A    public void teardownSubclass() %7B%0A      subclassNotifier.teardown();%0A    %7D%0A  %7D%0A%7D%0A

test the ResourcesLifecycleMethodManager