Added: @Before and @After methods can be injected with the current XmlTest


diff --git a/CHANGES.txt b/CHANGES.txt
index b6fd29d..dd85d53 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -1,8 +1,9 @@
 Current:
 
+Added: @Before and @After methods can be injected with the current XmlTest
 Added: Methods that time out now display the stack trace showing where the time out occurred
 Added: ITestResult#getAttribute and ITestResult#setAttribute
-Added: @After methods can now be injected an ITestResult
+Added: @After methods can now be injected with an ITestResult
 Added: @BeforeMethod and @AfterMethod methods can now be injected an ITestResult
 Added: ISuite#getAttribute and ISuite#setAttribute to share data within a suite
 Added: @Test(expectedExceptionsMessageRegExp = ".*foo.*")
diff --git a/doc/documentation-main.html b/doc/documentation-main.html
index 9072066..0568103 100644
--- a/doc/documentation-main.html
+++ b/doc/documentation-main.html
@@ -1882,6 +1882,8 @@
 <li>
   Any @After method can declare a parameter of type <tt>ITestResult</tt>, which will reflect the result of the test method that was just run.
 <li>
+  Any @Before and @After methods can declare a parameter of type <tt>XmlTest</tt>, which contain the current <tt>&lt;test&gt;</tt> tag.
+<li>
   Any @BeforeMethod can declare a parameter of type <tt>java.lang.reflect.Method</tt>.  This parameter will receive the test method that will be called once this @BeforeMethod finishes.
 <li>
   Any @BeforeMethod can declare a parameter of type <tt>Object[]</tt>.  This parameter will receive the list of parameters that are about to be fed to the upcoming test method, which could be either injected by TestNG, such as <tt>java.lang.reflect.Method</tt> or come from a <tt>@DataProvider</tt>.
diff --git a/src/main/org/testng/ITestContext.java b/src/main/org/testng/ITestContext.java
index 7589545..8aeff95 100644
--- a/src/main/org/testng/ITestContext.java
+++ b/src/main/org/testng/ITestContext.java
@@ -1,5 +1,7 @@
 package org.testng;
 
+import org.testng.xml.XmlTest;
+
 import java.util.Collection;
 import java.util.Date;
 
@@ -108,4 +110,9 @@
    * @return
    */
   public IResultMap getFailedConfigurations();
+
+  /**
+   * @return the current XmlTest.
+   */
+  public XmlTest getCurrentXmlTest();
 }
diff --git a/src/main/org/testng/TestRunner.java b/src/main/org/testng/TestRunner.java
index f50a42a..8ecd151 100644
--- a/src/main/org/testng/TestRunner.java
+++ b/src/main/org/testng/TestRunner.java
@@ -1,17 +1,6 @@
 package org.testng;
 
 
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.Date;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-import java.util.regex.Pattern;
-
 import org.testng.internal.ClassHelper;
 import org.testng.internal.ConfigurationGroupMethods;
 import org.testng.internal.Constants;
@@ -40,6 +29,17 @@
 import org.testng.xml.XmlSuite;
 import org.testng.xml.XmlTest;
 
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.regex.Pattern;
+
 /**
  * This class takes care of running one Test.
  *
@@ -1201,4 +1201,8 @@
   public void setMethodInterceptor(IMethodInterceptor methodInterceptor) {
     m_methodInterceptor = methodInterceptor;
   }
+
+  public XmlTest getCurrentXmlTest() {
+    return m_xmlTest;
+  }
 } // TestRunner
diff --git a/src/main/org/testng/internal/Parameters.java b/src/main/org/testng/internal/Parameters.java
index caaeeb7..59e6c79 100644
--- a/src/main/org/testng/internal/Parameters.java
+++ b/src/main/org/testng/internal/Parameters.java
@@ -13,6 +13,7 @@
 import org.testng.internal.annotations.AnnotationHelper;
 import org.testng.internal.annotations.IAnnotationFinder;
 import org.testng.xml.XmlSuite;
+import org.testng.xml.XmlTest;
 
 import java.lang.reflect.Constructor;
 import java.lang.reflect.Method;
@@ -106,6 +107,9 @@
         else if (ITestContext.class.equals(parameterTypes[i])) {
           vResult.add(params.context);
         }
+        else if (XmlTest.class.equals(parameterTypes[i])) {
+          vResult.add(params.context.getCurrentXmlTest());
+        }
         else if (ITestResult.class.equals(parameterTypes[i])) {
           vResult.add(params.testResult);
         }
@@ -154,6 +158,7 @@
       Class type = parameterTypes[i];
       if(!ITestContext.class.equals(type)
           && !ITestResult.class.equals(type)
+          && !XmlTest.class.equals(type)
           && !Method.class.equals(type)
           && !Object[].class.equals(type)) {
         throw new TestNGException( "Method " + methodName + " requires " 
diff --git a/test/src/test/inject/InjectTestContextTest.java b/test/src/test/inject/InjectTestContextTest.java
index 86a1f53..f75a97a 100644
--- a/test/src/test/inject/InjectTestContextTest.java
+++ b/test/src/test/inject/InjectTestContextTest.java
@@ -2,25 +2,24 @@
 
 import org.testng.Assert;
 import org.testng.ITestContext;
-import org.testng.ITestNGMethod;
 import org.testng.TestListenerAdapter;
 import org.testng.TestNG;
-import org.testng.annotations.BeforeMethod;
-import org.testng.annotations.DataProvider;
 import org.testng.annotations.Test;
+import org.testng.xml.XmlTest;
 
 import test.SimpleBaseTest;
 
 public class InjectTestContextTest extends SimpleBaseTest {
 
   @Test
-  public void verifyTestContextInjection(ITestContext tc) {
+  public void verifyTestContextInjection(ITestContext tc, XmlTest xmlTest) {
     TestNG tng = create();
     tng.setTestClasses(new Class[] { Sample.class });
     TestListenerAdapter tla = new TestListenerAdapter();
     tng.addListener(tla);
     tng.run();
     
+    Assert.assertEquals(xmlTest.getName(), "Injection");
     Assert.assertEquals(tla.getPassedTests().size(), 1);
     Assert.assertEquals(tla.getPassedTests().get(0).getMethod().getMethodName(), "f");
   }
diff --git a/test/src/test/tmp/A.java b/test/src/test/tmp/A.java
index dc3bec9..c335699 100644
--- a/test/src/test/tmp/A.java
+++ b/test/src/test/tmp/A.java
@@ -1,8 +1,25 @@
 package test.tmp;
 
+import org.testng.Assert;
+import org.testng.annotations.BeforeMethod;
 import org.testng.annotations.Test;
 
+import java.util.ArrayList;
+import java.util.List;
+
 public class A {
+  private List mList;
+  
+  public boolean putIfAbsent(List l, Object o) {
+    boolean absent = true;
+    synchronized(l) {
+      absent = ! l.contains(o);
+      if (absent) {
+        l.add(o);
+      }
+    }
+    return absent;
+  }
   
 //  @Test(expectedExceptions = RuntimeException.class)
 //  public void method1() {
@@ -15,18 +32,22 @@
 //    System.out.println("In method2");
 //    throw new RuntimeException("");
 //  }
-   
-  @Test(timeOut = 2000)
+
+  @BeforeMethod
+  public void init() {
+    mList = new ArrayList();
+  }
+
+  @Test(invocationCount = 100, threadPoolSize = 5)
   public void method3() {
-    System.out.println("Before loop");
-    for (int j = 0; j < 1000000000; j++) {
-      for (int i = 0; i < 1000000000; i++) {
-        for (int k = 0; k < 1000000000; k++) {
-          
-        }
-      }
-    }
-    System.out.println("After loop");
+    Integer n = new Integer(42);
+    Assert.assertEquals(mList.size(), 0);
+    boolean absent = putIfAbsent(mList, n);
+    Assert.assertTrue(absent);
+    Assert.assertEquals(mList.size(), 1);
+    boolean absent2 = putIfAbsent(mList, n);
+    Assert.assertFalse(absent2);
+    Assert.assertEquals(mList.size(), 1);
   }
 
   
diff --git a/test/testng-single.xml b/test/testng-single.xml
index 0967a38..3100c40 100644
--- a/test/testng-single.xml
+++ b/test/testng-single.xml
@@ -8,8 +8,9 @@
 
   <test name="Simple">
     <classes>
-      <class name="test.tmp.A" />
+      <class name="test.inject.InjectTestContextTest" />
 <!--
+      <class name="test.tmp.A" />
       <class name="test.expectedexceptions.ExpectedExceptionsTest" />
 -->
      </classes>