1package test.hook;
2
3import org.testng.*;
4import org.testng.annotations.DataProvider;
5import org.testng.annotations.Test;
6
7import javax.inject.Named;
8import java.lang.annotation.Annotation;
9import java.lang.reflect.Method;
10
11public class HookSuccess862Test implements IHookable {
12
13    @Override
14    public void run(IHookCallBack callBack, ITestResult testResult) {
15        Method method = testResult.getMethod().getConstructorOrMethod().getMethod();
16        for (int i = 0; i < callBack.getParameters().length; i++) {
17            Annotation[] annotations = method.getParameterAnnotations()[i];
18            for (Annotation annotation : annotations) {
19                if (annotation instanceof Named) {
20                    Named named = (Named) annotation;
21                    callBack.getParameters()[0] = callBack.getParameters()[0] + named.value();
22                }
23            }
24        }
25        callBack.runTestMethod(testResult);
26    }
27
28    @DataProvider
29    public Object[][] dp() {
30        return new Object[][]{
31                new Object[]{"foo", "test"}
32        };
33    }
34
35    @Test(dataProvider = "dp")
36    public void verify(@Named("bar") String bar, String test) {
37        Assert.assertEquals(bar, "foobar");
38        Assert.assertEquals(test, "test");
39    }
40}
41