DataProviderFrameworkMethod extends FrameworkMethod { @Override public String getName() { if (nameFormatter == null || DataProviderPlaceholderFormatter.class.equals(nameFormatter)) { return new DataProviderPlaceholderFormatter(nameFormat, Placeholders.all()).format(getMethod(), idx, Arrays.asList(parameters)); } try { return nameFormatter.getDeclaredConstructor().newInstance().format(getMethod(), idx, Arrays.asList(parameters)); } catch (InstantiationException e) { throw new IllegalStateException(String .format("Could not instantiate name formatter using default constructor '%s'.", nameFormatter), e); } catch (IllegalAccessException e) { throw new IllegalStateException( String.format("Default constructor not accessable of name formatter '%s'.", nameFormatter), e); } catch (InvocationTargetException e) { throw new IllegalStateException(String.format("Default constructor of name formatter '%s' has thrown: %s", nameFormatter, e.getMessage()), e); } catch (NoSuchMethodException e) { throw new IllegalStateException( String.format("Default constructor not found for name formatter '%s'.", nameFormatter), e); } catch (Exception e) { throw new IllegalStateException(String.format( "Unexpected exception while finding and invoking default constructor of name formatter '%s': %s", nameFormatter, e.getMessage()), e); } } DataProviderFrameworkMethod(Method method, int idx, Object[] parameters, String nameFormat);  DataProviderFrameworkMethod(Method method, int idx, Object[] parameters,
            String nameFormat, Class<? extends DataProviderTestNameFormatter> nameFormatter); @Override String getName(); @Override Object invokeExplosively(Object target, Object... params); @Override int hashCode(); @Override boolean equals(Object obj);  }
@Test public void testGetNameShouldCallPlaceholderSetContextAndProcess() { final Object[] parameters = new Object[] { 718, "718" }; Placeholders.all().clear(); Placeholders.all().add(placeholder); DataProviderFrameworkMethod underTest = new DataProviderFrameworkMethod(method, 20, parameters, "%m"); underTest.getName(); verify(placeholder).setContext(method, 20, parameters); verify(placeholder).process("%m"); verifyNoMoreInteractions(placeholder); }
@Test public void testGetNameShouldCallAllPlaceholdersProcessInOrder() { final Object[] parameters = new Object[] { 719, "719" }; BasePlaceholder placeholder2 = mock(BasePlaceholder.class); BasePlaceholder placeholder3 = mock(BasePlaceholder.class); Placeholders.all().clear(); Placeholders.all().add(placeholder); Placeholders.all().add(placeholder2); Placeholders.all().add(placeholder3); when(placeholder.process(any(String.class))).thenReturn("%cm2"); when(placeholder2.process(any(String.class))).thenReturn("%cm3"); when(placeholder3.process(any(String.class))).thenReturn("%cm4"); DataProviderFrameworkMethod underTest = new DataProviderFrameworkMethod(method, 21, parameters, "%cm1"); String result = underTest.getName(); assertThat(result).isEqualTo("%cm4"); InOrder inOrder = inOrder(placeholder, placeholder2, placeholder3); inOrder.verify(placeholder).setContext(method, 21, parameters); inOrder.verify(placeholder).process("%cm1"); inOrder.verify(placeholder2).setContext(method, 21, parameters); inOrder.verify(placeholder2).process("%cm2"); inOrder.verify(placeholder3).setContext(method, 21, parameters); inOrder.verify(placeholder3).process("%cm3"); verifyNoMoreInteractions(placeholder, placeholder2, placeholder3); }
@Test public void testGetNameShouldRetrunResultOfProcess() { final Method method = getMethod("testGetNameShouldRetrunResultOfProcess"); final Object[] parameters = new Object[] { 720, "720" }; final String nameFormat = "%m[%i: %p[0..-1]]"; DataProviderFrameworkMethod underTest = new DataProviderFrameworkMethod(method, 22, parameters, nameFormat); String result = underTest.getName(); assertThat(result).isEqualTo("testGetNameShouldRetrunResultOfProcess[22: 720, 720]"); }