DefaultDataProviderMethodResolver extends com.tngtech.junit.dataprovider.resolver.DefaultDataProviderMethodResolver implements DataProviderMethodResolver { protected FrameworkMethod findDataProviderMethod(TestClass location, String testMethodName, String useDataProviderValue) { List<FrameworkMethod> dataProviderMethods = location.getAnnotatedMethods(DataProvider.class); for (FrameworkMethod dataProviderMethod : dataProviderMethods) { if (UseDataProvider.DEFAULT_VALUE.equals(useDataProviderValue)) { if (isMatchingNameConvention(testMethodName, dataProviderMethod.getName())) { return dataProviderMethod; } } else if (dataProviderMethod.getName().equals(useDataProviderValue)) { return dataProviderMethod; } } return null; }  @Override List<FrameworkMethod> resolve(FrameworkMethod testMethod, UseDataProvider useDataProvider);  }
@Test public void testFindDataProviderMethodShouldReturnNullForNotFoundDataProviderMethod() { final String testMethodName = "testMethodName"; final String dataProviderMethodName = "availableDataProviderMethodName"; when(testClass.getAnnotatedMethods(DataProvider.class)).thenReturn(singletonList(dataProviderMethod)); when(dataProviderMethod.getName()).thenReturn(dataProviderMethodName); FrameworkMethod result = underTest.findDataProviderMethod(testClass, testMethodName, "notAvailableDataProviderMethodName"); assertThat(result).isNull(); }
@Test public void testFindDataProviderMethodShouldReturnDataProviderMethodHavingSameNameAsTestMethodIfItExists() { final String testMethodName = "testMethodName"; final String dataProviderMethodName = "testMethodName"; when(testClass.getAnnotatedMethods(DataProvider.class)).thenReturn(singletonList(dataProviderMethod)); when(dataProviderMethod.getName()).thenReturn(dataProviderMethodName); FrameworkMethod result = underTest.findDataProviderMethod(testClass, testMethodName, UseDataProvider.DEFAULT_VALUE); assertThat(result).isEqualTo(dataProviderMethod); }
@Test public void testFindDataProviderMethodShouldReturnListContainingDataProviderMethodHavingDataProviderPrefixInsteadOfTestIfItExists() { final String testMethodName = "testMethodName"; final String dataProviderMethodName = "dataProviderMethodName"; when(testClass.getAnnotatedMethods(DataProvider.class)).thenReturn(singletonList(dataProviderMethod)); when(dataProviderMethod.getName()).thenReturn(dataProviderMethodName); FrameworkMethod result = underTest.findDataProviderMethod(testClass, testMethodName, UseDataProvider.DEFAULT_VALUE); assertThat(result).isEqualTo(dataProviderMethod); }
@Test public void testFindDataProviderMethodShouldReturnListContainingDataProviderMethodHavingDataPrefixInsteadOfTestIfItExists() { final String testMethodName = "testMethodName"; final String dataProviderMethodName = "dataMethodName"; when(testClass.getAnnotatedMethods(DataProvider.class)).thenReturn(singletonList(dataProviderMethod)); when(dataProviderMethod.getName()).thenReturn(dataProviderMethodName); FrameworkMethod result = underTest.findDataProviderMethod(testClass, testMethodName, UseDataProvider.DEFAULT_VALUE); assertThat(result).isEqualTo(dataProviderMethod); }
@Test public void testFindDataProviderMethodShouldReturnListContainingDataProviderMethodHavingDataProviderPrefixIfItExists() { final String testMethodName = "methodName"; final String dataProviderMethodName = "dataProviderMethodName"; when(testClass.getAnnotatedMethods(DataProvider.class)).thenReturn(singletonList(dataProviderMethod)); when(dataProviderMethod.getName()).thenReturn(dataProviderMethodName); FrameworkMethod result = underTest.findDataProviderMethod(testClass, testMethodName, UseDataProvider.DEFAULT_VALUE); assertThat(result).isEqualTo(dataProviderMethod); }
@Test public void testFindDataProviderMethodShouldReturnListContainingDataProviderMethodHavingDataPrefixIfItExists() { final String testMethodName = "methodName"; final String dataProviderMethodName = "dataMethodName"; when(testClass.getAnnotatedMethods(DataProvider.class)).thenReturn(singletonList(dataProviderMethod)); when(dataProviderMethod.getName()).thenReturn(dataProviderMethodName); FrameworkMethod result = underTest.findDataProviderMethod(testClass, testMethodName, UseDataProvider.DEFAULT_VALUE); assertThat(result).isEqualTo(dataProviderMethod); }
@Test public void testFindDataProviderMethodShouldReturnListContainingDataProviderMethodHavingExplicitlyGivenNameIfItExists() { final String testMethodName = "testMethodName"; final String dataProviderMethodName = "availableDataProviderMethodName"; when(testClass.getAnnotatedMethods(DataProvider.class)).thenReturn(singletonList(dataProviderMethod)); when(dataProviderMethod.getName()).thenReturn(dataProviderMethodName); FrameworkMethod result = underTest.findDataProviderMethod(testClass, testMethodName, dataProviderMethodName); assertThat(result).isEqualTo(dataProviderMethod); }