|
6 | 6 | import org.testng.ITestResult; |
7 | 7 | import org.testng.SkipException; |
8 | 8 |
|
9 | | -public class MethodListener |
10 | | - implements IInvokedMethodListener |
11 | | -{ |
12 | | - |
| 9 | +public class MethodListener implements IInvokedMethodListener { |
| 10 | + |
13 | 11 | private String lastClassWithoutPackage; |
14 | 12 |
|
15 | | - private String getClassNameWithoutPackage( String canonicalName ) |
16 | | - { |
17 | | - int lastIndexOf = canonicalName.lastIndexOf( '.' ); |
18 | | - return canonicalName.substring( lastIndexOf + 1 ); |
| 13 | + private String getClassNameWithoutPackage(String canonicalName) { |
| 14 | + int lastIndexOf = canonicalName.lastIndexOf('.'); |
| 15 | + return canonicalName.substring(lastIndexOf + 1); |
19 | 16 | } |
20 | 17 |
|
21 | 18 | @Override |
22 | | - public void beforeInvocation( IInvokedMethod method, ITestResult testResult ) |
23 | | - { |
24 | | - if ( method.isTestMethod() ) |
25 | | - { |
| 19 | + public void beforeInvocation(IInvokedMethod method, ITestResult testResult) { |
| 20 | + if (method.isTestMethod()) { |
26 | 21 | ITestNGMethod testMethod = method.getTestMethod(); |
27 | | - String classNameWithoutPackage = getClassNameWithoutPackage( testMethod.getTestClass().getName() ); |
28 | | - |
| 22 | + String classNameWithoutPackage = getClassNameWithoutPackage(testMethod.getTestClass().getName()); |
| 23 | + |
29 | 24 | if (lastClassWithoutPackage == null) { |
30 | | - System.out.println( classNameWithoutPackage + ":" ); |
31 | | - System.out.print( " " + testMethod.getMethodName() + "..." ); |
| 25 | + System.out.println(classNameWithoutPackage + ":"); |
32 | 26 | } else { |
33 | | - if (lastClassWithoutPackage.equals( classNameWithoutPackage )) { |
34 | | - System.out.print( " " + testMethod.getMethodName() + "..." ); |
35 | | - } else { |
36 | | - System.out.println( classNameWithoutPackage + ":" ); |
37 | | - System.out.print( " " + testMethod.getMethodName() + "..." ); |
| 27 | + if (!lastClassWithoutPackage.equals(classNameWithoutPackage)) { |
| 28 | + System.out.println(classNameWithoutPackage + ":"); |
38 | 29 | } |
39 | 30 | } |
40 | 31 | lastClassWithoutPackage = classNameWithoutPackage; |
41 | 32 | } |
42 | 33 | } |
43 | 34 |
|
44 | 35 | @Override |
45 | | - public void afterInvocation( IInvokedMethod method, ITestResult testResult ) |
46 | | - { |
47 | | - if ( method.isTestMethod() ) |
48 | | - { |
49 | | - if ( testResult.isSuccess() ) |
50 | | - { |
51 | | - System.out.println( "Done." ); |
52 | | - } |
53 | | - else |
54 | | - { |
55 | | - //Isn't there an more elegant way? |
| 36 | + public void afterInvocation(IInvokedMethod method, ITestResult testResult) { |
| 37 | + if (method.isTestMethod()) { |
| 38 | + ITestNGMethod testMethod = method.getTestMethod(); |
| 39 | + String classNameWithoutPackage = getClassNameWithoutPackage(testMethod.getTestClass().getName()); |
| 40 | + |
| 41 | + if (testResult.isSuccess()) { |
| 42 | + System.out.print(" SUCCESS "); |
| 43 | + } else { |
| 44 | + // Isn't there an more elegant way? |
56 | 45 | if (testResult.getThrowable() instanceof SkipException) { |
57 | | - System.out.println( "SKIPPED. ( " + testResult.getThrowable().getMessage() + " )" ); |
| 46 | + System.out.print(" SKIPPED ( " + testResult.getThrowable().getMessage() + " ) "); |
58 | 47 | } else { |
59 | | - System.out.println( "FAILURE." ); |
| 48 | + System.out.print(" FAILURE "); |
60 | 49 | } |
61 | 50 | } |
| 51 | + |
| 52 | + System.out.println(" " + testMethod.getMethodName()); |
| 53 | + lastClassWithoutPackage = classNameWithoutPackage; |
| 54 | + |
62 | 55 | } |
63 | 56 | } |
64 | 57 |
|
|
0 commit comments