Skip to content

Commit 070c55b

Browse files
authored
Merge pull request #11 from imperial-crystalline-recursion/0.4
0.4
2 parents cccead1 + 9ef4d43 commit 070c55b

File tree

11 files changed

+542
-600
lines changed

11 files changed

+542
-600
lines changed

README.md

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ TextView thirdTextView;
2828
And that will generate a class which will create two tests that will cover those three TextViews.
2929

3030

31-
There's also a `DefinedTest` class which allows you to define more complex tests that may not be possible to generate with the annotation processor.
31+
There's also a `CustomTest` class which allows you to define more complex tests that may not be possible to generate with the annotation processor.
3232

3333
By default, tests will be weighted to have an equal chance to be selected. However, by extending the `TestPicker` class you can weight the tests however you like.
3434

@@ -50,10 +50,7 @@ apply plugin: 'com.neenbedankt.android-apt'
5050
```
5151
Then, you'll want to bang these bad boys into your `build.gradle`s' dependencies:
5252
```groovy
53-
apt 'com.github.imperial-crystalline-recursion.abtestgen:ab-compiler:0.3.2'
54-
compile 'com.github.imperial-crystalline-recursion.abtestgen:ab-annotations:0.3.2'
55-
compile 'com.github.imperial-crystalline-recursion.abtestgen:ab-lib:0.3.2'
53+
apt 'com.github.imperial-crystalline-recursion.abtestgen:ab-compiler:0.4'
54+
compile 'com.github.imperial-crystalline-recursion.abtestgen:ab-annotations:0.4'
55+
compile 'com.github.imperial-crystalline-recursion.abtestgen:ab-lib:0.4'
5656
```
57-
##Build status
58-
![Build status](https://circleci.com/gh/imperial-crystalline-recursion/abtestgen.svg?style=shield&circle-token=02adbc662080afafe062fdd8ee467cafa703014b "Build status")
59-

ab-annotations/build.gradle

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ apply plugin: 'java'
22
apply plugin: 'com.github.dcendents.android-maven'
33

44
group='com.github.imperial-crystalline-recursion'
5+
version='0.4'
56

67
sourceCompatibility = 1.7
78
targetCompatibility = 1.7
@@ -17,22 +18,4 @@ task sourcesJar(type: Jar, dependsOn: classes) {
1718

1819
artifacts {
1920
archives sourcesJar
20-
}
21-
22-
Task task = task writePom {
23-
pom {
24-
project {
25-
inceptionYear '2016'
26-
version '0.3.1'
27-
licenses {
28-
license {
29-
name 'The Apache Software License, Version 2.0'
30-
url 'http://www.apache.org/licenses/LICENSE-2.0.txt'
31-
distribution 'repo'
32-
}
33-
}
34-
}
35-
}.writeTo("$buildDir/pom/pom.xml")
36-
}
37-
38-
task.mustRunAfter(assemble)
21+
}

ab-compiler/build.gradle

Lines changed: 5 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
1+
import org.gradle.internal.jvm.Jvm
2+
13
apply plugin: 'java'
24
apply plugin: 'maven'
35

46
group='com.github.imperial-crystalline-recursion'
7+
version='0.4'
58

69
sourceCompatibility = 1.7
710
targetCompatibility = 1.7
@@ -22,7 +25,7 @@ dependencies {
2225
compile 'com.squareup:javapoet:1.7.0'
2326
testCompile 'junit:junit:4.12'
2427
testCompile 'com.google.testing.compile:compile-testing:0.9'
25-
testCompile files(org.gradle.internal.jvm.Jvm.current().getToolsJar()) //gradle kinda sucks so we need this
28+
testCompile files(Jvm.current().getToolsJar()) //gradle kinda sucks so we need this
2629
}
2730

2831
task sourcesJar(type: Jar, dependsOn: classes) {
@@ -32,22 +35,4 @@ task sourcesJar(type: Jar, dependsOn: classes) {
3235

3336
artifacts {
3437
archives sourcesJar
35-
}
36-
37-
Task task = task writePom {
38-
pom {
39-
project {
40-
inceptionYear '2016'
41-
version '0.3.1'
42-
licenses {
43-
license {
44-
name 'The Apache Software License, Version 2.0'
45-
url 'http://www.apache.org/licenses/LICENSE-2.0.txt'
46-
distribution 'repo'
47-
}
48-
}
49-
}
50-
}.writeTo("$buildDir/pom/pom.xml")
51-
}
52-
53-
task.mustRunAfter(assemble)
38+
}

ab-compiler/src/main/java/com/afewroosloose/abtesting/compiler/ABTestProcessor.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ private void getTextTests(RoundEnvironment roundEnv, Multimap<String, ViewTestDa
9191
for (Element element : roundEnv.getElementsAnnotatedWith(TextTest.class)) {
9292
TextTest testAnnotation = element.getAnnotation(TextTest.class);
9393
if (element.getKind() != ElementKind.FIELD) {
94-
throw new IllegalArgumentException("Can only run ABView tests on a field!");
94+
messager.printMessage(Diagnostic.Kind.ERROR, "Can only run ABView tests on a field!");
9595
} else {
9696
TypeMirror typeMirror = element.asType();
9797
String type = typeMirror.toString();
@@ -108,7 +108,7 @@ private void getResTests(RoundEnvironment roundEnv, Multimap<String, ViewTestDat
108108
for (Element element : roundEnv.getElementsAnnotatedWith(ResourceTest.class)) {
109109
ResourceTest testAnnotation = element.getAnnotation(ResourceTest.class);
110110
if (element.getKind() != ElementKind.FIELD) {
111-
throw new IllegalArgumentException("Can only run ABView tests on a field!");
111+
messager.printMessage(Diagnostic.Kind.ERROR, "Can only run ABView tests on a field!");
112112
} else {
113113
TypeMirror typeMirror = element.asType();
114114
String type = typeMirror.toString();
@@ -167,6 +167,7 @@ private void createTest(String name, Collection<ViewTestData> viewTestDatas) {
167167
MethodSpec constructor = constructorBuilder.addModifiers(Modifier.PUBLIC).build();
168168
abstractTestClassBuilder.addMethod(constructor);
169169

170+
//we construct our test chooser method here
170171
MethodSpec.Builder runMethod = MethodSpec.methodBuilder("run") //
171172
.addModifiers(Modifier.PUBLIC) //
172173
.addAnnotation(Override.class) //
@@ -197,7 +198,7 @@ private void createTest(String name, Collection<ViewTestData> viewTestDatas) {
197198
try {
198199
javaFile.writeTo(filer);
199200
} catch (IOException e) {
200-
throw new RuntimeException(e);
201+
messager.printMessage(Diagnostic.Kind.ERROR, e.getMessage());
201202
}
202203
}
203204

@@ -208,11 +209,9 @@ private void validateTestData(ViewTestData[] datas) {
208209
if (data.getValues().length != numberOfParams) {
209210
messager.printMessage(Diagnostic.Kind.ERROR,
210211
"Each element in a test must have the same number of values!");
211-
throw new RuntimeException("Each element in a test must have the same number of values!");
212212
}
213213
if (data.getElementAttachedTo().getModifiers().contains(Modifier.PRIVATE)) {
214214
messager.printMessage(Diagnostic.Kind.ERROR, "You can't annotate a private field!");
215-
throw new RuntimeException("You can't annotate a private field!");
216215
}
217216
}
218217
}

ab-compiler/src/test/java/com/afewroosloose/abtesting/MixedTest.java

Lines changed: 76 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22

33
import com.afewroosloose.abtesting.compiler.ABTestProcessor;
44
import com.google.testing.compile.JavaFileObjects;
5+
56
import javax.tools.JavaFileObject;
7+
68
import org.junit.Test;
79

810
import static com.google.common.truth.Truth.assertAbout;
@@ -13,84 +15,84 @@
1315
*/
1416
public class MixedTest {
1517

16-
String sourceClass = //
17-
"package test;" //
18-
+ "\n" //
19-
+ "\nimport com.afewroosloose.abtesting.api.annotations.ResourceTest;" //
20-
+ "\nimport com.afewroosloose.abtesting.api.annotations.TextTest;" //
21-
+ "\n" //
22-
+ "\npublic class Test {" //
23-
+ "\n @TextTest(testName = \"Test1\", values = {\"A\", \"Z\"})" //
24-
+ "\n Dummy hello;" //
25-
+ "\n" //
26-
+ "\n @ResourceTest(method = \"setInt\", testName = \"Test1\", values = {0, 1})" //
27-
+ "\n Dummy bye;" //
28-
+ "\n" //
29-
+ "\n public static class Dummy {" //
30-
+ "\n void setText(String value) {" //
31-
+ "\n" //
32-
+ "\n }" //
33-
+ "\n" //
34-
+ "\n void setInt(int value) {" //
35-
+ "\n" //
36-
+ "\n }" //
37-
+ "\n }" //
38-
+ "\n}"; //
18+
String sourceClass = //
19+
"package test;" //
20+
+ "\n" //
21+
+ "\nimport com.afewroosloose.abtesting.api.annotations.ResourceTest;" //
22+
+ "\nimport com.afewroosloose.abtesting.api.annotations.TextTest;" //
23+
+ "\n" //
24+
+ "\npublic class Test {" //
25+
+ "\n @TextTest(testName = \"Test1\", values = {\"A\", \"Z\"})" //
26+
+ "\n Dummy hello;" //
27+
+ "\n" //
28+
+ "\n @ResourceTest(method = \"setInt\", testName = \"Test1\", values = {0, 1})" //
29+
+ "\n Dummy bye;" //
30+
+ "\n" //
31+
+ "\n public static class Dummy {" //
32+
+ "\n void setText(String value) {" //
33+
+ "\n" //
34+
+ "\n }" //
35+
+ "\n" //
36+
+ "\n void setInt(int value) {" //
37+
+ "\n" //
38+
+ "\n }" //
39+
+ "\n }" //
40+
+ "\n}"; //
3941

40-
String generatedClass = //
41-
"package test;" //
42-
+ "\n" //
43-
+ "\nimport com.afewroosloose.abtesting.api.AbstractTest;" //
44-
+ "\nimport java.lang.Override;" //
45-
+ "\nimport java.lang.SuppressWarnings;" //
46-
+ "\nimport javax.annotation.Generated;" //
47-
+ "\n" //
48-
+ "\n@Generated(\"com.afewroosloose.abtesting.compiler.ABTestProcessor\")"
49-
+ "\n@SuppressWarnings(\"ResourceType, unused\")" //
50-
+ "\npublic class Test$$Test1 extends AbstractTest {" //
51-
+ "\n private int numberOfTests;" //
52-
+ "\n" //
53-
+ "\n Test.Dummy hello;" //
54-
+ "\n" //
55-
+ "\n Test.Dummy bye;" //
56-
+ "\n" //
57-
+ "\n public Test$$Test1() {" //
58-
+ "\n numberOfTests = 2;" //
59-
+ "\n }" //
60-
+ "\n" //
61-
+ "\n @Override" //
62-
+ "\n public int getNumberOfTests() {" //
63-
+ "\n return numberOfTests;" //
64-
+ "\n }" //
65-
+ "\n" + "\n @Override" //
66-
+ "\n public void run(int testToChoose) {" //
67-
+ "\n if (testToChoose == 0) {" //
68-
+ "\n hello.setText(\"A\");"//
69-
+ "\n bye.setInt(0);" //
70-
+ "\n return;" //
71-
+ "\n }" //
72-
+ "\n if (testToChoose == 1) {" //
73-
+ "\n hello.setText(\"Z\");" //
74-
+ "\n bye.setInt(1);" //
75-
+ "\n return;" //
76-
+ "\n }" //
77-
+ "\n }" //
78-
+ "\n}"; //
42+
String generatedClass = //
43+
"package test;" //
44+
+ "\n" //
45+
+ "\nimport com.afewroosloose.abtesting.api.AbstractTest;" //
46+
+ "\nimport java.lang.Override;" //
47+
+ "\nimport java.lang.SuppressWarnings;" //
48+
+ "\nimport javax.annotation.Generated;" //
49+
+ "\n" //
50+
+ "\n@Generated(\"com.afewroosloose.abtesting.compiler.ABTestProcessor\")"
51+
+ "\n@SuppressWarnings(\"ResourceType, unused\")" //
52+
+ "\npublic class Test$$Test1 extends AbstractTest {" //
53+
+ "\n private int numberOfTests;" //
54+
+ "\n" //
55+
+ "\n Test.Dummy hello;" //
56+
+ "\n" //
57+
+ "\n Test.Dummy bye;" //
58+
+ "\n" //
59+
+ "\n public Test$$Test1() {" //
60+
+ "\n numberOfTests = 2;" //
61+
+ "\n }" //
62+
+ "\n" //
63+
+ "\n @Override" //
64+
+ "\n public int getNumberOfTests() {" //
65+
+ "\n return numberOfTests;" //
66+
+ "\n }" //
67+
+ "\n" + "\n @Override" //
68+
+ "\n public void run(int testToChoose) {" //
69+
+ "\n if (testToChoose == 0) {" //
70+
+ "\n hello.setText(\"A\");"//
71+
+ "\n bye.setInt(0);" //
72+
+ "\n return;" //
73+
+ "\n }" //
74+
+ "\n if (testToChoose == 1) {" //
75+
+ "\n hello.setText(\"Z\");" //
76+
+ "\n bye.setInt(1);" //
77+
+ "\n return;" //
78+
+ "\n }" //
79+
+ "\n }" //
80+
+ "\n}"; //
7981

80-
@Test
81-
public void testResourceTest() throws Exception {
82+
@Test
83+
public void testResourceTest() throws Exception {
8284

83-
JavaFileObject sourceObj =
84-
JavaFileObjects.forSourceString("test.Test", sourceClass);
85+
JavaFileObject sourceObj =
86+
JavaFileObjects.forSourceString("test.Test", sourceClass);
8587

86-
JavaFileObject genObj =
87-
JavaFileObjects.forSourceString("test/Test$$Test1", generatedClass);
88+
JavaFileObject genObj =
89+
JavaFileObjects.forSourceString("test/Test$$Test1", generatedClass);
8890

89-
assertAbout(javaSource()).that(sourceObj)
90-
.processedWith(new ABTestProcessor())
91-
.compilesWithoutError()
92-
.and()
93-
.generatesSources(genObj);
94-
}
91+
assertAbout(javaSource()).that(sourceObj)
92+
.processedWith(new ABTestProcessor())
93+
.compilesWithoutError()
94+
.and()
95+
.generatesSources(genObj);
96+
}
9597
}
9698

0 commit comments

Comments
 (0)