Merge pull request #536 from grkvlt/listener-fix

Issue 830: Fixing NPE in test listener
This commit is contained in:
Adrian Cole 2012-03-31 07:11:54 -07:00
commit 991cf2833d
1 changed files with 6 additions and 3 deletions

View File

@ -28,7 +28,9 @@ import org.testng.ITestResult;
import org.testng.TestListenerAdapter;
import com.google.common.base.Joiner;
import com.google.common.base.Optional;
import com.google.common.base.Predicates;
import com.google.common.base.Strings;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Iterables;
@ -79,15 +81,16 @@ public class FormatApiResultsListener extends TestListenerAdapter {
}
private String getApi(ITestResult res) {
return Iterables.find(Arrays.asList(res.getMethod().getGroups()), Predicates.in(apis));
Optional<String> found = Iterables.tryFind(Arrays.asList(res.getMethod().getGroups()), Predicates.in(apis));
return found.isPresent() ? found.get() : "";
}
private String getOperation(ITestResult res) {
return res.getMethod().getDescription();
return Strings.nullToEmpty(res.getMethod().getDescription());
}
private String getTest(ITestResult res) {
return res.getName();
return Strings.nullToEmpty(res.getName());
}
private String getStart(ITestResult res) {