blob: 720e7a89da91712dc6ec91308fe9f10fb5ca9eb4 (
plain)
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
|
package org.robolectric.annotation.processing.validator;
import static com.google.common.truth.Truth.assertAbout;
import static com.google.common.truth.Truth.assertThat;
import static org.robolectric.annotation.processing.validator.SingleClassSubject.singleClass;
import org.junit.Test;
import org.robolectric.annotation.processing.DocumentedMethod;
public class ImplementsValidatorTest {
@Test
public void implementsWithoutClassOrClassName_shouldNotCompile() {
final String testClass = "org.robolectric.annotation.processing.shadows.ShadowImplementsWithoutClass";
assertAbout(singleClass())
.that(testClass)
.failsToCompile()
.withErrorContaining("@Implements: must specify <value> or <className>")
.onLine(5);
}
@Test
public void anything_withoutClassName_shouldNotCompile() {
final String testClass = "org.robolectric.annotation.processing.shadows.ShadowImplementsAnythingWithoutClassName";
assertAbout(singleClass())
.that(testClass)
.failsToCompile()
.withErrorContaining("@Implements: Anything class specified but no <className> attribute")
.onLine(6);
}
@Test
public void anything_withUnresolvableClassName_shouldNotCompile() {
final String testClass = "org.robolectric.annotation.processing.shadows.ShadowImplementsAnythingWithUnresolvableClassName";
assertAbout(singleClass())
.that(testClass)
.failsToCompile()
.withErrorContaining("@Implements: could not resolve class <some.Stuff>")
.onLine(6);
}
@Test
public void value_withUnresolvableClassNameAndOldMaxSdk_shouldNotCompile() {
final String testClass = "org.robolectric.annotation.processing.shadows.ShadowImplementsAnythingWithUnresolvableClassNameAndOldMaxSdk";
assertAbout(singleClass())
.that(testClass)
.compilesWithoutError();
}
@Test
public void value_withClassName_shouldNotCompile() {
final String testClass = "org.robolectric.annotation.processing.shadows.ShadowImplementsDummyWithOuterDummyClassName";
assertAbout(singleClass())
.that(testClass)
.failsToCompile()
.withErrorContaining("@Implements: cannot specify both <value> and <className> attributes")
.onLine(6);
}
@Test
public void implementsWithParameterMismatch_shouldNotCompile() {
final String testClass = "org.robolectric.annotation.processing.shadows.ShadowImplementsWithParameterMismatch";
assertAbout(singleClass())
.that(testClass)
.failsToCompile()
.withErrorContaining("Shadow type must have same type parameters as its real counterpart: expected <T,N extends java.lang.Number>, was <N extends java.lang.Number,T>")
.onLine(7);
}
@Test
public void implementsWithMissingParameters_shouldNotCompile() {
final String testClass = "org.robolectric.annotation.processing.shadows.ShadowImplementsWithMissingParameters";
assertAbout(singleClass())
.that(testClass)
.failsToCompile()
.withErrorContaining("Shadow type is missing type parameters, expected <T,N extends java.lang.Number>")
.onLine(7);
}
@Test
public void implementsWithExtraParameters_shouldNotCompile() {
final String testClass = "org.robolectric.annotation.processing.shadows.ShadowImplementsWithExtraParameters";
assertAbout(singleClass())
.that(testClass)
.failsToCompile()
.withErrorContaining("Shadow type has type parameters but real type does not")
.onLine(7);
}
@Test
public void constructorShadowWithoutImplementation_shouldNotCompile() {
final String testClass =
"org.robolectric.annotation.processing.shadows.ShadowWithImplementationlessShadowMethods";
assertAbout(singleClass())
.that(testClass)
.failsToCompile()
.withErrorContaining("Shadow methods must be annotated @Implementation")
.onLine(9)
.and()
.withErrorContaining("Shadow methods must be annotated @Implementation")
.onLine(12);
}
@Test
public void javadocMarkdownFormatting() throws Exception {
DocumentedMethod documentedMethod = new DocumentedMethod("name");
documentedMethod.setDocumentation(
" First sentence.\n \n Second sentence.\n \n ASCII art:\n * * *\n @return null\n"
);
assertThat(documentedMethod.getDocumentation())
.isEqualTo("First sentence.\n\nSecond sentence.\n\nASCII art:\n * * *\n@return null\n");
}
}
|