Skip to content

Commit 4ece810

Browse files
committed
add compile time tests to ensure that the otto plugin does not generate code for non enhanced classes
1 parent f38d288 commit 4ece810

8 files changed

Lines changed: 190 additions & 1 deletion

File tree

‎AndroidAnnotations/androidannotations-otto/otto-test/pom.xml‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@
5858
<dependency>
5959
<groupId>com.squareup</groupId>
6060
<artifactId>otto</artifactId>
61-
<version>1.3.8</version>
6261
</dependency>
6362
<dependency>
6463
<groupId>org.robolectric</groupId>

‎AndroidAnnotations/androidannotations-otto/otto/pom.xml‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,16 @@
3838
<groupId>org.androidannotations</groupId>
3939
<artifactId>androidannotations</artifactId>
4040
</dependency>
41+
<dependency>
42+
<groupId>org.androidannotations</groupId>
43+
<artifactId>androidannotations-testutils</artifactId>
44+
<scope>test</scope>
45+
</dependency>
46+
<dependency>
47+
<groupId>com.squareup</groupId>
48+
<artifactId>otto</artifactId>
49+
<scope>test</scope>
50+
</dependency>
4151
<dependency>
4252
<groupId>com.helger</groupId>
4353
<artifactId>jcodemodel</artifactId>
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/**
2+
* Copyright (C) 2010-2015 eBusiness Information, Excilys Group
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
5+
* use this file except in compliance with the License. You may obtain a copy of
6+
* the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed To in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13+
* License for the specific language governing permissions and limitations under
14+
* the License.
15+
*/
16+
package org.androidannotations.otto;
17+
18+
import org.androidannotations.annotations.EBean;
19+
20+
import com.squareup.otto.Produce;
21+
import com.squareup.otto.Subscribe;
22+
23+
@EBean
24+
public class EnhancedBean {
25+
26+
@Subscribe
27+
public void subscriber(String fakeEvent) {
28+
}
29+
30+
@Produce
31+
public String producer() {
32+
return "";
33+
}
34+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/**
2+
* Copyright (C) 2010-2015 eBusiness Information, Excilys Group
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
5+
* use this file except in compliance with the License. You may obtain a copy of
6+
* the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed To in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13+
* License for the specific language governing permissions and limitations under
14+
* the License.
15+
*/
16+
package org.androidannotations.otto;
17+
18+
import com.squareup.otto.Produce;
19+
import com.squareup.otto.Subscribe;
20+
21+
public class NonEnhancedBean {
22+
23+
@Subscribe
24+
public void subscriber(String fakeEvent) {
25+
}
26+
27+
@Produce
28+
public String producer() {
29+
return "";
30+
}
31+
}
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
/**
2+
* Copyright (C) 2010-2015 eBusiness Information, Excilys Group
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
5+
* use this file except in compliance with the License. You may obtain a copy of
6+
* the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed To in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13+
* License for the specific language governing permissions and limitations under
14+
* the License.
15+
*/
16+
package org.androidannotations.otto;
17+
18+
import static org.junit.Assert.assertFalse;
19+
import static org.junit.Assert.assertTrue;
20+
21+
import java.io.File;
22+
23+
import org.androidannotations.internal.AndroidAnnotationProcessor;
24+
import org.androidannotations.testutils.AAProcessorTestHelper;
25+
import org.junit.Before;
26+
import org.junit.Test;
27+
28+
public class OttoGenerationTest extends AAProcessorTestHelper {
29+
30+
@Before
31+
public void setUp() {
32+
addManifestProcessorParameter(OttoGenerationTest.class);
33+
addProcessor(AndroidAnnotationProcessor.class);
34+
}
35+
36+
@Test
37+
public void enhancedClassCompilesSuccessfully() {
38+
assertCompilationSuccessful(compileFiles(EnhancedBean.class));
39+
}
40+
41+
@Test
42+
public void nonEnhancedClassCompilesSuccessfully() {
43+
assertCompilationSuccessful(compileFiles(NonEnhancedBean.class));
44+
}
45+
46+
@Test
47+
public void enhancedClassGeneratesCode() {
48+
CompileResult result = compileFiles(EnhancedBean.class);
49+
File generatedFile = toGeneratedFile(EnhancedBean.class);
50+
51+
assertCompilationSuccessful(result);
52+
53+
assertTrue(generatedFile.exists());
54+
}
55+
56+
@Test
57+
public void nonEnhancedClassDoesNotGenerateCode() {
58+
CompileResult result = compileFiles(NonEnhancedBean.class);
59+
File generatedFile = toGeneratedFile(NonEnhancedBean.class);
60+
61+
assertCompilationSuccessful(result);
62+
63+
assertFalse(generatedFile.exists());
64+
}
65+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/**
2+
* Copyright (C) 2010-2015 eBusiness Information, Excilys Group
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
5+
* use this file except in compliance with the License. You may obtain a copy of
6+
* the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed To in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13+
* License for the specific language governing permissions and limitations under
14+
* the License.
15+
*/
16+
package org.androidannotations.otto;
17+
18+
public class R {
19+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<!--
3+
4+
Copyright (C) 2010-2015 eBusiness Information, Excilys Group
5+
6+
Licensed under the Apache License, Version 2.0 (the "License"); you may not
7+
use this file except in compliance with the License. You may obtain a copy of
8+
the License at
9+
10+
http://www.apache.org/licenses/LICENSE-2.0
11+
12+
Unless required by applicable law or agreed To in writing, software
13+
distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
14+
WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
15+
License for the specific language governing permissions and limitations under
16+
the License.
17+
18+
-->
19+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
20+
package="org.androidannotations.otto"
21+
android:versionCode="1"
22+
android:versionName="1.0" >
23+
24+
<application />
25+
26+
</manifest>

‎AndroidAnnotations/androidannotations-otto/pom.xml‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,11 @@
4646
<artifactId>otto</artifactId>
4747
<version>${project.version}</version>
4848
</dependency>
49+
<dependency>
50+
<groupId>com.squareup</groupId>
51+
<artifactId>otto</artifactId>
52+
<version>1.3.8</version>
53+
</dependency>
4954
</dependencies>
5055

5156
</dependencyManagement>

0 commit comments

Comments
 (0)