-
Notifications
You must be signed in to change notification settings - Fork 282
/
ExpectedMethod.java
50 lines (39 loc) · 1.84 KB
/
ExpectedMethod.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package com.tngtech.archunit.testutils;
import java.lang.annotation.Annotation;
import com.tngtech.archunit.core.domain.JavaClass;
import static java.lang.String.format;
import static com.tngtech.archunit.core.domain.Formatters.formatMethod;
public class ExpectedMethod {
public static ExpectedMethod.Creator of(Class<?> owner, String methodName, Class<?>... params) {
return new ExpectedMethod.Creator(owner, methodName, params);
}
public static class Creator {
private final Class<?> clazz;
private final String methodName;
private final Class<?>[] params;
private int lineNumber;
private Creator(Class<?> clazz, String methodName, Class<?>[] params) {
this.clazz = clazz;
this.methodName = methodName;
this.params = params;
}
public Creator inLine(int lineNumber) {
this.lineNumber = lineNumber;
return this;
}
public ExpectedMessage toNotHaveRawReturnType(Class<?> type) {
return method("does not have raw return type " + type.getName());
}
public ExpectedMessage throwsException(Class<?> type) {
return method("does declare throwable of type " + type.getName());
}
public ExpectedMessage beingAnnotatedWith(Class<? extends Annotation> annotationType) {
return method("is annotated with @" + annotationType.getSimpleName());
}
private ExpectedMessage method(String message) {
String methodDescription = format("Method <%s>", formatMethod(clazz.getName(), methodName, JavaClass.namesOf(params)));
String sourceCodeLocation = format("(%s.java:%d)", clazz.getSimpleName(), lineNumber);
return new ExpectedMessage(format("%s %s in %s", methodDescription, message, sourceCodeLocation));
}
}
}