/** * Generates the exploded list of methods that run tests. All methods annotated with {@code @Test} on this class and * super classes that are not overridden are checked if they use a {@code @}{@link DataProvider} or not. If yes, for * each row of the {@link DataProvider}s result a specific, parameterized test method will be added. If not, the * original test method is added. * <p> * Additionally, caches the result as {@link #computeTestMethods()} is call multiple times while test execution by * the JUnit framework (to validate, to filter, to execute, ...). * * @return the exploded list of test methods (never {@code null}) */ @Override protected List<FrameworkMethod> computeTestMethods() { if (computedTestMethods == null) { // Further method for generation is required due to stubbing of "super.computeTestMethods()" is not possible computedTestMethods = generateExplodedTestMethodsFor(super.computeTestMethods()); } return computedTestMethods; }
/** * Generates the exploded list of methods that run tests. All methods annotated with {@code @Test} on this class and * super classes that are not overridden are checked if they use a {@code @}{@link DataProvider} or not. If yes, for * each row of the {@link DataProvider}s result a specific, parameterized test method will be added. If not, the * original test method is added. * <p> * Additionally, caches the result as {@link #computeTestMethods()} is call multiple times while test execution by * the JUnit framework (to validate, to filter, to execute, ...). * * @return the exploded list of test methods (never {@code null}) */ @Override protected List<FrameworkMethod> computeTestMethods() { if (computedTestMethods == null) { // Further method for generation is required due to stubbing of "super.computeTestMethods()" is not possible computedTestMethods = generateExplodedTestMethodsFor(super.computeTestMethods()); } return computedTestMethods; }
/** * Generates the exploded list of methods that run tests. All methods annotated with {@code @Test} on this class and * super classes that are not overridden are checked if they use a {@code @}{@link DataProvider} or not. If yes, for * each row of the {@link DataProvider}s result a specific, parameterized test method will be added. If not, the * original test method is added. * <p> * Additionally, caches the result as {@link #computeTestMethods()} is call multiple times while test execution by * the JUnit framework (to validate, to filter, to execute, ...). * * @return the exploded list of test methods (never {@code null}) */ @Override protected List<FrameworkMethod> computeTestMethods() { if (computedTestMethods == null) { // Further method for generation is required due to stubbing of "super.computeTestMethods()" is not possible computedTestMethods = generateExplodedTestMethodsFor(super.computeTestMethods()); } return computedTestMethods; }
/** * Generates the exploded list of methods that run tests. All methods annotated with {@code @Test} on this class and * super classes that are not overridden are checked if they use a {@code @}{@link DataProvider} or not. If yes, for * each row of the {@link DataProvider}s result a specific, parameterized test method will be added. If not, the * original test method is added. * <p> * Additionally, caches the result as {@link #computeTestMethods()} is call multiple times while test execution by * the JUnit framework (to validate, to filter, to execute, ...). * * @return the exploded list of test methods (never {@code null}) */ @Override protected List<FrameworkMethod> computeTestMethods() { if (computedTestMethods == null) { // Further method for generation is required due to stubbing of "super.computeTestMethods()" is not possible computedTestMethods = generateExplodedTestMethodsFor(super.computeTestMethods()); } return computedTestMethods; }
@Test public void testGenerateExplodedTestMethodsForShouldReturnEmptyListIfArgumentIsEmptyList() { // Given: List<FrameworkMethod> testMethods = new ArrayList<FrameworkMethod>(); // When: List<FrameworkMethod> result = underTest.generateExplodedTestMethodsFor(testMethods); // Then: assertThat(result).isEmpty(); }
@Test public void testGenerateExplodedTestMethodsForShouldCallTestGeneratorWithNotFoundDataProviderMethodAndAddResult() { // Given: doReturn(singletonList(null)).when(underTest).getDataProviderMethods(testMethod); doReturn(asList(testMethod)).when(testGenerator).generateExplodedTestMethodsFor(testMethod, null); // When: List<FrameworkMethod> result = underTest.generateExplodedTestMethodsFor(asList(testMethod)); // Then: assertThat(result).containsOnly(testMethod); verify(testGenerator).generateExplodedTestMethodsFor(testMethod, null); verifyNoMoreInteractions(testGenerator); }
@Test public void testGenerateExplodedTestMethodsForShouldReturnEmptyListIfArgumentIsNull() { // Given: // When: List<FrameworkMethod> result = underTest.generateExplodedTestMethodsFor(null); // Then: assertThat(result).isEmpty(); }
@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).generateExplodedTestMethodsFor(anyListOf(FrameworkMethod.class)); verifyNoMoreInteractions(underTest); }
@Test public void testGenerateExplodedTestMethodsForShouldCallTestGeneratorWithFoundDataProviderMethodAndAddResult() { // Given: doReturn(asList(dataProviderMethod)).when(underTest).getDataProviderMethods(testMethod); List<FrameworkMethod> explodedMethods = new ArrayList<FrameworkMethod>(); explodedMethods.add(mock(FrameworkMethod.class)); explodedMethods.add(mock(FrameworkMethod.class)); doReturn(explodedMethods).when(testGenerator).generateExplodedTestMethodsFor(testMethod, dataProviderMethod); // When: List<FrameworkMethod> result = underTest.generateExplodedTestMethodsFor(asList(testMethod)); // Then: assertThat(result).hasSize(2).containsAll(explodedMethods); verify(testGenerator).generateExplodedTestMethodsFor(testMethod, dataProviderMethod); verifyNoMoreInteractions(testGenerator); }
@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); }
@Test public void testGenerateExplodedTestMethodsForShouldCallTestGeneratorForAllTestMethodsAndAddResult() { // Given: FrameworkMethod testMethod2 = mock(FrameworkMethod.class); FrameworkMethod dataProviderMethod21 = mock(FrameworkMethod.class); FrameworkMethod dataProviderMethod22 = mock(FrameworkMethod.class); doReturn(asList(dataProviderMethod)).when(underTest).getDataProviderMethods(testMethod); doReturn(asList(dataProviderMethod21, dataProviderMethod22)).when(underTest).getDataProviderMethods(testMethod2); List<FrameworkMethod> explodedMethods = new ArrayList<FrameworkMethod>(); explodedMethods.add(mock(FrameworkMethod.class)); explodedMethods.add(mock(FrameworkMethod.class)); doReturn(explodedMethods).when(testGenerator).generateExplodedTestMethodsFor(testMethod, dataProviderMethod); List<FrameworkMethod> explodedMethods21 = new ArrayList<FrameworkMethod>(); explodedMethods21.add(mock(FrameworkMethod.class)); explodedMethods21.add(mock(FrameworkMethod.class)); explodedMethods21.add(mock(FrameworkMethod.class)); doReturn(explodedMethods21).when(testGenerator).generateExplodedTestMethodsFor(testMethod2, dataProviderMethod21); List<FrameworkMethod> explodedMethods22 = new ArrayList<FrameworkMethod>(); explodedMethods22.add(mock(FrameworkMethod.class)); explodedMethods22.add(mock(FrameworkMethod.class)); doReturn(explodedMethods22).when(testGenerator).generateExplodedTestMethodsFor(testMethod2, dataProviderMethod22); // When: List<FrameworkMethod> result = underTest.generateExplodedTestMethodsFor(asList(testMethod, testMethod2)); // Then: assertThat(result).hasSize(7).containsAll(explodedMethods).containsAll(explodedMethods21).containsAll(explodedMethods22); verify(testGenerator).generateExplodedTestMethodsFor(testMethod, dataProviderMethod); verify(testGenerator).generateExplodedTestMethodsFor(testMethod2, dataProviderMethod21); verify(testGenerator).generateExplodedTestMethodsFor(testMethod2, dataProviderMethod22); verifyNoMoreInteractions(testGenerator); }