cbeust/testng — Issue #126: o.t.internal.Utils recognizes all @After* annotations as @AfterMethod
Author: lukasj
Created: 2011-11-05 22:07:50+00:00
State: open

-pass following listener to TestNG (6.4/beta):

```java
package tnl;
import org.testng.*;
import org.testng.internal.Utils;

public class Tnl2 implements IConfigurationListener {

public void onConfigurationSuccess(ITestResult itr) {
System.out.println(Utils.detailedMethodName(itr.getMethod(), true));
}

public void onConfigurationFailure(ITestResult itr) {
}

public void onConfigurationSkip(ITestResult itr) {
}
}
```

-and run following test:

```java
package test;
import org.testng.annotations.*;

public class StTest {

@Test
public void y() {
//empty
}

@AfterMethod
public void afterMethod() {
System.out.println("AM");
}

@AfterSuite
public void afterSuite() {
System.out.println("AS");
}

@AfterGroups
public void afterGroups() {
System.out.println("AG");
}

@AfterClass
public void afterClass() {
System.out.println("AC");
}
}
```

=> listener reports:

```
[TestNG] Running:
Ant suite

AM
@AfterMethod StTest.afterMethod()[pri:0, instance:test.StTest@475b73eb]
AC
@AfterMethod StTest.afterClass()[pri:0, instance:test.StTest@475b73eb]
AS
@AfterMethod StTest.afterSuite()[pri:0, instance:test.StTest@475b73eb]

===============================================
Ant suite
Total tests run: 1, Failures: 0, Skips: 0
===============================================
```

Bit of debugging on my end showed that inner state of an instance of ITestNGMethod returned by ITestResult.getMethod() (where ITestResult is passed to listener.onConfigurationSuccess() by testng internals) looks strange:

-added following snippet to o.t.reporters.TextReporter:

```java
@Override
public void onConfigurationSuccess(ITestResult tr) {
System.out.println(Utils.detailedMethodName(tr.getMethod(), true));
ITestNGMethod m = tr.getMethod();
System.out.print(m.isBeforeMethodConfiguration() + " (BM) + ");
System.out.print(m.isBeforeClassConfiguration() + " (BC) + ");
System.out.print(m.isBeforeTestConfiguration()+ " (BT) + ");
System.out.print(m.isBeforeGroupsConfiguration() + " (BG) + ");
System.out.println(m.isBeforeSuiteConfiguration() + " (BS)");
System.out.print(m.isAfterMethodConfiguration() + " (AM) + ");
System.out.print(m.isAfterClassConfiguration() + " (AC) + ");
System.out.print(m.isAfterTestConfiguration() + " (AT) + ");
System.out.print(m.isAfterGroupsConfiguration() + " (AG) + ");
System.out.println(m.isAfterSuiteConfiguration() + " (AS)");
}
```

shown in the test output:

```
[TestNG] Running:
Ant suite

PASSED: StTest.y()[pri:0, instance:test.StTest@2253d4bf]
AM
@AfterMethod StTest.afterMethod()[pri:0, instance:test.StTest@2253d4bf]
false (BM) + false (BC) + false (BT) + false (BG) + false (BS)
true (AM) + true (AC) + true (AT) + false (AG) + true (AS)
AC
@AfterMethod StTest.afterClass()[pri:0, instance:test.StTest@2253d4bf]
false (BM) + false (BC) + false (BT) + false (BG) + false (BS)
true (AM) + true (AC) + true (AT) + false (AG) + true (AS)
...
AS
@AfterMethod StTest.afterSuite()[pri:0, instance:test.StTest@2253d4bf]
false (BM) + false (BC) + false (BT) + false (BG) + false (BS)
true (AM) + true (AC) + true (AT) + false (AG) + true (AS)
```

Since I don't now much about internals I'm afraid that if I try to fix this (somewhere in *o.t.internal.ConfigurationMethod.createAfterConfigurationMethods()* ?) I'll break some other, more important functionality, so I can possibly get around this by using *ITestNGMethod.getMethod().getAnnotation()* for now