@Override public String getName() { String result = nameFormat; for (BasePlaceholder placeHolder : Placeholders.all()) { placeHolder.setContext(getMethod(), idx, Arrays.copyOf(parameters, parameters.length)); result = placeHolder.process(result); } return result; }
@After public void tearDown() { Placeholders.reset(); }
@Override public String getName() { String result = nameFormat; for (BasePlaceholder placeHolder : Placeholders.all()) { synchronized (placeHolder) { placeHolder.setContext(getMethod(), idx, Arrays.copyOf(parameters, parameters.length)); result = placeHolder.process(result); } } return result; }
@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); } }
@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); } }
@Test public void testGetNameShouldCallPlaceholderSetContextAndProcess() { // Given: final Object[] parameters = new Object[] { 718, "718" }; Placeholders.all().clear(); Placeholders.all().add(placeholder); DataProviderFrameworkMethod underTest = new DataProviderFrameworkMethod(method, 20, parameters, "%m"); // When: underTest.getName(); // Then: verify(placeholder).setContext(method, 20, parameters); verify(placeholder).process("%m"); verifyNoMoreInteractions(placeholder); }
@Test public void testGetNameShouldCallAllPlaceholdersProcessInOrder() { // Given: 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"); // When: String result = underTest.getName(); // Then: 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); }