1 | |
package org.jbehave.core.failures; |
2 | |
|
3 | |
import java.lang.annotation.Annotation; |
4 | |
import java.lang.reflect.Method; |
5 | |
import java.util.ArrayList; |
6 | |
import java.util.List; |
7 | |
|
8 | |
import org.apache.commons.lang.StringUtils; |
9 | |
|
10 | |
import static java.text.MessageFormat.format; |
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
@SuppressWarnings("serial") |
17 | |
public class BeforeOrAfterFailed extends RuntimeException { |
18 | |
|
19 | |
public BeforeOrAfterFailed(Method method, Throwable cause) { |
20 | 3 | super(format("Method {0} (annotated with {1} in class {2}) failed: {3}", method.getName(), toAnnotationNames(method.getAnnotations()), method.getDeclaringClass().getName(), cause), cause); |
21 | 3 | } |
22 | |
|
23 | |
private static String toAnnotationNames(Annotation[] annotations) { |
24 | 3 | List<String> names = new ArrayList<String>(); |
25 | 5 | for (Annotation annotation : annotations) { |
26 | 2 | names.add("@"+annotation.annotationType().getSimpleName()); |
27 | |
} |
28 | 3 | return StringUtils.join(names, ","); |
29 | |
} |
30 | |
|
31 | |
public BeforeOrAfterFailed(Throwable cause) { |
32 | 0 | super(cause); |
33 | 0 | } |
34 | |
} |