MockspressoRuleImpl extends AbstractDelayedMockspresso implements Mockspresso.Rule { @Override public Statement apply(Statement base, FrameworkMethod method, Object target) { return mRuleConfig.buildRuleChain(new ImplRule()).apply(base, method, target); } MockspressoRuleImpl(
      MockspressoBuilderImpl originalBuilder,
      Provider<MockspressoBuilderImpl> builderProvider,
      RuleConfig ruleConfig); @Override Statement apply(Statement base, FrameworkMethod method, Object target);  }
@Test public void testBasicUsage() throws Throwable { Statement base = verifyChildDelegateStatement(); Statement result = mRule.apply(base, mFrameworkMethod, mTarget); result.evaluate(); InOrder inOrder = Mockito.inOrder(mConfig, mBuilderProvider, mBuilder, base, mConfig, mChildConfig); inOrder.verify(mBuilder).deepCopy(); inOrder.verify(mBuilder).testResourcesWithoutLifecycle(mTarget); inOrder.verify(mBuilder).buildInternal(); inOrder.verify(mConfig).setup(mOriginal); inOrder.verify(base).evaluate(); inOrder.verify(mConfig).teardown(); assertRuleNoLongerWorks(); }
@Test public void testEarlyBuildUponUsage() throws Throwable { Mockspresso mockspresso = mRule.buildUpon().build(); Statement base = verifyChildDelegateStatement(mockspresso, mChildMockspresso); Statement result = mRule.apply(base, mFrameworkMethod, mTarget); result.evaluate(); InOrder inOrder = Mockito.inOrder(mConfig, mBuilderProvider, mBuilder, base, mConfig, mChildConfig, mChildBuilder, mChildMockspresso); inOrder.verify(mBuilderProvider).get(); inOrder.verify(mBuilder).deepCopy(); inOrder.verify(mBuilder).testResourcesWithoutLifecycle(mTarget); inOrder.verify(mBuilder).buildInternal(); inOrder.verify(mConfig).setup(mOriginal); inOrder.verify(mChildBuilder).deepCopy(); inOrder.verify(mChildBuilder).buildInternal(); inOrder.verify(mChildConfig).setup(mChildMockspresso); inOrder.verify(base).evaluate(); inOrder.verify(mChildConfig).teardown(); inOrder.verify(mConfig).teardown(); assertMockspressoNoLongerWorks(mockspresso); assertRuleNoLongerWorks(); }
@Test public void testChainUsage() throws Throwable { Statement base = verifyChildDelegateStatement(); TestTestRule outerRule1 = spy(new TestTestRule()); TestMethodRule outerRule2 = spy(new TestMethodRule()); TestTestRule innerRule1 = spy(new TestTestRule()); TestMethodRule innerRule2 = spy(new TestMethodRule()); mRuleConfig.addOuterRule(outerRule1); mRuleConfig.addOuterRule(outerRule2); mRuleConfig.addInnerRule(innerRule1); mRuleConfig.addInnerRule(innerRule2); Statement result = mRule.apply(base, mFrameworkMethod, mTarget); result.evaluate(); InOrder inOrder = Mockito.inOrder( mConfig, mBuilderProvider, mBuilder, base, mConfig, innerRule1, innerRule1.returnStatement, innerRule2, innerRule2.returnStatement, outerRule1, outerRule1.returnStatement, outerRule2, outerRule2.returnStatement); inOrder.verify(innerRule2).apply(base, mFrameworkMethod, mTarget); inOrder.verify(innerRule1).apply(eq(innerRule2.returnStatement), any(Description.class)); inOrder.verify(outerRule2).apply(any(Statement.class), eq(mFrameworkMethod), eq(mTarget)); inOrder.verify(outerRule1).apply(eq(outerRule2.returnStatement), any(Description.class)); inOrder.verify(outerRule1.returnStatement).before(); inOrder.verify(outerRule2.returnStatement).before(); inOrder.verify(mBuilder).deepCopy(); inOrder.verify(mBuilder).testResourcesWithoutLifecycle(mTarget); inOrder.verify(mBuilder).buildInternal(); inOrder.verify(mConfig).setup(mOriginal); inOrder.verify(innerRule1.returnStatement).before(); inOrder.verify(innerRule2.returnStatement).before(); inOrder.verify(base).evaluate(); inOrder.verify(innerRule2.returnStatement).after(); inOrder.verify(innerRule1.returnStatement).after(); inOrder.verify(mConfig).teardown(); inOrder.verify(outerRule2.returnStatement).after(); inOrder.verify(outerRule1.returnStatement).after(); assertRuleNoLongerWorks(); }
@Test public void testChainUsageWithChildInstance() throws Throwable { Mockspresso mockspresso = mRule.buildUpon().build(); Statement base = verifyChildDelegateStatement(mockspresso, mChildMockspresso); TestTestRule outerRule1 = spy(new TestTestRule()); TestMethodRule outerRule2 = spy(new TestMethodRule()); TestTestRule innerRule1 = spy(new TestTestRule()); TestMethodRule innerRule2 = spy(new TestMethodRule()); mRuleConfig.addOuterRule(outerRule1); mRuleConfig.addOuterRule(outerRule2); mRuleConfig.addInnerRule(innerRule1); mRuleConfig.addInnerRule(innerRule2); Statement result = mRule.apply(base, mFrameworkMethod, mTarget); result.evaluate(); InOrder inOrder = Mockito.inOrder( mConfig, mBuilderProvider, mBuilder, base, mConfig, mChildConfig, innerRule1, innerRule1.returnStatement, innerRule2, innerRule2.returnStatement, mChildBuilder, outerRule1, outerRule1.returnStatement, outerRule2, outerRule2.returnStatement); inOrder.verify(mBuilderProvider).get(); inOrder.verify(innerRule2).apply(base, mFrameworkMethod, mTarget); inOrder.verify(innerRule1).apply(eq(innerRule2.returnStatement), any(Description.class)); inOrder.verify(outerRule2).apply(any(Statement.class), eq(mFrameworkMethod), eq(mTarget)); inOrder.verify(outerRule1).apply(eq(outerRule2.returnStatement), any(Description.class)); inOrder.verify(outerRule1.returnStatement).before(); inOrder.verify(outerRule2.returnStatement).before(); inOrder.verify(mBuilder).deepCopy(); inOrder.verify(mBuilder).testResourcesWithoutLifecycle(mTarget); inOrder.verify(mBuilder).buildInternal(); inOrder.verify(mConfig).setup(mOriginal); inOrder.verify(mChildBuilder).deepCopy(); inOrder.verify(mChildBuilder).buildInternal(); inOrder.verify(mChildConfig).setup(mChildMockspresso); inOrder.verify(innerRule1.returnStatement).before(); inOrder.verify(innerRule2.returnStatement).before(); inOrder.verify(base).evaluate(); inOrder.verify(innerRule2.returnStatement).after(); inOrder.verify(innerRule1.returnStatement).after(); inOrder.verify(mChildConfig).teardown(); inOrder.verify(mConfig).teardown(); inOrder.verify(outerRule2.returnStatement).after(); inOrder.verify(outerRule1.returnStatement).after(); assertRuleNoLongerWorks(); }