@Test public void testComputeTestMethodsShouldCallGenerateExplodedTestMethodsAndCacheResultIfCalledTheFirstTime() { // Given: underTest.computedTestMethods = null; doReturn(new ArrayList<FrameworkMethod>()) .when(underTest) .generateExplodedTestMethodsFor(anyListOf(FrameworkMethod.class)); // When: List<FrameworkMethod> result = underTest.computeTestMethods(); // Then: assertThat(result).isEqualTo(underTest.computedTestMethods); InOrder inOrder = inOrder(underTest); inOrder.verify(underTest).computeTestMethods(); inOrder.verify(underTest).invokeBeforeClass(); inOrder.verify(underTest).generateExplodedTestMethodsFor(anyListOf(FrameworkMethod.class)); verifyNoMoreInteractions(underTest); }
@Test public void testComputeTestMethodsShouldNotCallGenerateExplodedTestMethodsAndUseCachedResultIfCalledTheSecondTime() { // Given: final List<FrameworkMethod> expected = new ArrayList<FrameworkMethod>(); underTest.computedTestMethods = expected; doReturn(expected) .when(underTest) .generateExplodedTestMethodsFor(anyListOf(FrameworkMethod.class)); // When: List<FrameworkMethod> result = underTest.computeTestMethods(); // Then: assertThat(result).isSameAs(expected); assertThat(underTest.computedTestMethods).isSameAs(expected); verify(underTest).computeTestMethods(); verifyNoMoreInteractions(underTest); }