-
Notifications
You must be signed in to change notification settings - Fork 340
Expand file tree
/
Copy pathExpectedNaming.java
More file actions
55 lines (45 loc) · 2.31 KB
/
Copy pathExpectedNaming.java
File metadata and controls
55 lines (45 loc) · 2.31 KB
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
51
52
53
54
55
package com.tngtech.archunit.testutils;
public class ExpectedNaming {
public static Creator simpleNameOf(Class<?> clazz) {
return new Creator(clazz.getName(), clazz.getSimpleName());
}
public static Creator simpleNameOfAnonymousClassOf(Class<?> clazz) {
return new Creator(clazz.getName() + "$1", clazz.getSimpleName());
}
public static class Creator {
private static final String SYNTHETIC_CLASS_HINT =
"\n\nHint: The failing class appears to be a synthetic or anonymous class " +
"generated by the compiler (e.g., from lambdas, switch expressions, or inner classes). " +
"To exclude these from your rule, consider adding:\n" +
" .that().doNotHaveModifier(JavaModifier.SYNTHETIC)\n" +
"or:\n" +
" .that().areNotAnonymousClasses()";
private final String className;
private final String simpleName;
private final boolean isAnonymous;
private Creator(String className, String simpleName) {
this(className, simpleName, className.contains("$"));
}
private Creator(String className, String simpleName, boolean isAnonymous) {
this.className = className;
this.simpleName = simpleName;
this.isAnonymous = isAnonymous;
}
public ExpectedMessage notStartingWith(String prefix) {
return expectedClassViolation(String.format("does not have simple name starting with '%s'", prefix));
}
public ExpectedMessage notEndingWith(String suffix) {
return expectedClassViolation(String.format("does not have simple name ending with '%s'", suffix));
}
public ExpectedMessage containing(String infix) {
return expectedClassViolation(String.format("has simple name containing '%s'", infix));
}
private ExpectedMessage expectedClassViolation(String description) {
String message = String.format("Class <%s> %s in (%s.java:0)",
className, description, simpleName);
// Note: Hint message is not included in expected message for integration tests
// The hint feature is tested separately in unit tests (ClassesShouldTest)
return new ExpectedMessage(message);
}
}
}