package com.tngtech.test.java.junit.dataprovider;

import static org.assertj.core.api.Assertions.assertThat;

import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;

import com.tngtech.java.junit.dataprovider.DataProvider;
import com.tngtech.java.junit.dataprovider.DataProviderRunner;
import com.tngtech.java.junit.dataprovider.Placeholders;
import com.tngtech.java.junit.dataprovider.internal.placeholder.ParameterPlaceholder;

@RunWith(DataProviderRunner.class)
public class CustomPlaceholderAcceptanceTest {

    public static class StripParameterLengthPlaceholder extends ParameterPlaceholder {
        private final int maxLength;

        public StripParameterLengthPlaceholder(int maxLength) {
            this.maxLength = maxLength;
        }

        @Override
        protected String formatAll(Object[] parameters) {
            StringBuilder stringBuilder = new StringBuilder();
            for (int i = 0; i < parameters.length; i++) {
                String formattedParameter = format(parameters[i]);
                if (formattedParameter.length() > maxLength) {
                    stringBuilder.append(formattedParameter.substring(0, maxLength - 5));
                    stringBuilder.append("...");
                    stringBuilder.append(formattedParameter.substring(formattedParameter.length() - 2));
                } else {
                    stringBuilder.append(formattedParameter);
                }
                if (i < parameters.length - 1) {
                    stringBuilder.append(", ");
                }
            }
            return stringBuilder.toString();
        }
    }

    @BeforeClass
    public static void setup() {
        Placeholders.all().add(0, new StripParameterLengthPlaceholder(10));
    }

    @AfterClass
    public static void teardown() {
        Placeholders.reset();
    }

    @Test
    // @formatter:off
    @DataProvider({
        "veryVeryLongMethodNameWhichMustBeStripped,                                      null, false",
        "veryVeryLongMethodNameWhichMustBeStripped,                                          , false",
        "veryVeryLongMethodNameWhichMustBeStripped, veryVeryLongMethodNameWhichMustBeStripped,  true",
        "veryverylongmethodnamewhichmustbestripped, veryVeryLongMethodNameWhichMustBeStripped,  true",
        "veryVeryLongMethodNameWhichMustBeStripped, veryverylongmethodnamewhichmustbestripped,  true"
    })
    // @formatter:on
    public void testEqualsIgnoreCase(String methodName1, String methodName2, boolean expected) {
        // Expected:
        assertThat(methodName1.equalsIgnoreCase(methodName2)).isEqualTo(expected);
    }
}

@@ -107,67 +107,8 @@
 t;%0A%0A
-import org.junit.AfterClass;%0Aimport org.junit.BeforeClass;%0A
 impo
@@ -337,16 +337,76 @@
 olders;%0A
+import com.tngtech.java.junit.dataprovider.UseDataProvider;%0A
 import c
@@ -1682,51 +1682,165 @@
     
-@BeforeClass%0A    public static void setup()
+// Note: is only called before test initialization in Runner's constructor if at least one %22external%22%0A    // dataprovider (= static method) exists%0A    static
  %7B%0A 
@@ -1930,18 +1930,20 @@
    @
-AfterClass
+DataProvider
 %0A   
@@ -1961,73 +1961,54 @@
 tic 
-void teardown() %7B%0A        Placeholders.re
+String%5B%5D dataProviderEqualsIgnoreCa
 se
-t
 ()
-;%0A    %7D%0A%0A    @Test%0A
+ %7B%0A    
     
@@ -2033,32 +2033,45 @@
     
-@DataProvider(%7B%0A
+    return new String%5B%5D %7B%0A   
         
 %22ver
@@ -2058,32 +2058,37 @@
 %5B%5D %7B%0A           
+     
 %22veryVeryLongMet
@@ -2166,32 +2166,40 @@
 false%22,%0A        
+      
+  
 %22veryVeryLongMet
@@ -2277,32 +2277,40 @@
 false%22,%0A        
+    
+    
 %22veryVeryLongMet
@@ -2392,24 +2392,32 @@
 e%22,%0A        
+ 
+       
 %22veryverylon
@@ -2499,32 +2499,40 @@
  true%22,%0A        
+    
+    
 %22veryVeryLongMet
@@ -2612,16 +2612,25 @@
 rue%22
+,%0A        %7D;
 %0A    
-%7D)%0A
     
@@ -2646,16 +2646,54 @@
 tter:on%0A
+    %7D%0A%0A    @Test%0A    @UseDataProvider%0A
     publ

fix placeholder customization example (#101)