Issue 830: Fixing NPE in test listener

This commit is contained in:
Andrew Donald Kennedy 2012-03-31 13:16:05 +01:00
parent 7e6b419068
commit 4324edc1d2
1 changed files with 6 additions and 3 deletions

View File

@ -28,7 +28,9 @@ import org.testng.ITestResult;
import org.testng.TestListenerAdapter; import org.testng.TestListenerAdapter;
import com.google.common.base.Joiner; import com.google.common.base.Joiner;
import com.google.common.base.Optional;
import com.google.common.base.Predicates; import com.google.common.base.Predicates;
import com.google.common.base.Strings;
import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Iterables; import com.google.common.collect.Iterables;
@ -79,15 +81,16 @@ public class FormatApiResultsListener extends TestListenerAdapter {
} }
private String getApi(ITestResult res) { 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) { private String getOperation(ITestResult res) {
return res.getMethod().getDescription(); return Strings.nullToEmpty(res.getMethod().getDescription());
} }
private String getTest(ITestResult res) { private String getTest(ITestResult res) {
return res.getName(); return Strings.nullToEmpty(res.getName());
} }
private String getStart(ITestResult res) { private String getStart(ITestResult res) {