Skip to content

Commit 1b9f70e

Browse files
committed
Add processing tests.
1 parent 696b90a commit 1b9f70e

9 files changed

Lines changed: 337 additions & 1 deletion

File tree

‎AndroidAnnotations/androidannotations/pom.xml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
<dependency>
3333
<groupId>com.google.android</groupId>
3434
<artifactId>android</artifactId>
35-
<version>1.6_r2</version>
35+
<version>4.1.1.4</version>
3636
<scope>provided</scope>
3737
</dependency>
3838
<dependency>
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/**
2+
* Copyright (C) 2010-2013 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.receiver;
17+
18+
import android.app.Activity;
19+
import org.androidannotations.annotations.EActivity;
20+
import org.androidannotations.annotations.Receiver;
21+
22+
@EActivity
23+
public class ActivityWithInvalidRegisterAt extends Activity {
24+
25+
@Receiver(actions = "org.androidannotations.ACTION_1", registerAt = Receiver.RegisterAt.OnAttachOnDetach)
26+
protected void badRegisterAtValue() {
27+
28+
}
29+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/**
2+
* Copyright (C) 2010-2013 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.receiver;
17+
18+
import android.app.Activity;
19+
import android.content.Intent;
20+
import org.androidannotations.annotations.EActivity;
21+
import org.androidannotations.annotations.Receiver;
22+
23+
@EActivity
24+
public class ActivityWithTwoSameNameMethod extends Activity {
25+
26+
@Receiver(actions = "org.androidannotations.ACTION_1")
27+
protected void methodWithSameName() {
28+
29+
}
30+
31+
@Receiver(actions = "org.androidannotations.ACTION_1", registerAt = Receiver.RegisterAt.OnResumeOnPause)
32+
protected void methodWithSameName(Intent intent) {
33+
34+
}
35+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/**
2+
* Copyright (C) 2010-2013 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.receiver;
17+
18+
import android.app.Activity;
19+
import android.content.Intent;
20+
import org.androidannotations.annotations.EActivity;
21+
import org.androidannotations.annotations.Receiver;
22+
23+
@EActivity
24+
public class ActivityWithValidReceiver extends Activity {
25+
26+
@Receiver(actions = "org.androidannotations.ACTION_1")
27+
protected void onAction1() {
28+
29+
}
30+
31+
@Receiver(actions = "org.androidannotations.ACTION_1", registerAt = Receiver.RegisterAt.OnStartOnStop)
32+
protected void onAction1Bis() {
33+
34+
}
35+
36+
@Receiver(actions = "org.androidannotations.ACTION_2", registerAt = Receiver.RegisterAt.OnResumeOnPause)
37+
protected void onAction2(Intent intent) {
38+
39+
}
40+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/**
2+
* Copyright (C) 2010-2013 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.receiver;
17+
18+
import android.app.Fragment;
19+
import android.content.Intent;
20+
import org.androidannotations.annotations.EFragment;
21+
import org.androidannotations.annotations.Receiver;
22+
23+
@EFragment
24+
public class FragmentWithValidReceiver extends Fragment {
25+
26+
@Receiver(actions = "org.androidannotations")
27+
protected void registeredOnCreateOnDestroy() {
28+
29+
}
30+
31+
@Receiver(actions = "org.androidannotations", registerAt = Receiver.RegisterAt.OnAttachOnDetach)
32+
protected void registeredOnAttachOnDetach(Intent intent) {
33+
34+
}
35+
36+
@Receiver(actions = "org.androidannotations", registerAt = Receiver.RegisterAt.OnStartOnStop)
37+
protected void registeredOnStartOnStop() {
38+
39+
}
40+
41+
@Receiver(actions = "org.androidannotations", registerAt = Receiver.RegisterAt.OnResumeOnPause)
42+
protected void registeredOnResumeOnPause(Intent intent) {
43+
44+
}
45+
46+
}
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
/**
2+
* Copyright (C) 2010-2013 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.receiver;
17+
18+
import org.androidannotations.AndroidAnnotationProcessor;
19+
import org.androidannotations.utils.AAProcessorTestHelper;
20+
import org.junit.Before;
21+
import org.junit.Test;
22+
23+
import java.io.IOException;
24+
25+
public class ReceiverRegistrationTest extends AAProcessorTestHelper {
26+
27+
@Before
28+
public void setup() {
29+
addManifestProcessorParameter(ActivityWithValidReceiver.class);
30+
addProcessor(AndroidAnnotationProcessor.class);
31+
}
32+
33+
@Test
34+
public void activity_with_valid_receiver_annotation_compile() throws IOException {
35+
CompileResult result = compileFiles(ActivityWithValidReceiver.class);
36+
assertCompilationSuccessful(result);
37+
}
38+
39+
@Test
40+
public void activity_with_invalid_registerAt_not_compile() throws IOException {
41+
CompileResult result = compileFiles(ActivityWithInvalidRegisterAt.class);
42+
assertCompilationErrorOn(ActivityWithInvalidRegisterAt.class, "@Receiver", result);
43+
}
44+
45+
@Test
46+
public void activity_with_two_method_with_same_name_not_compile() throws IOException {
47+
CompileResult result = compileFiles(ActivityWithTwoSameNameMethod.class);
48+
assertCompilationErrorOn(ActivityWithTwoSameNameMethod.class, "@Receiver", result);
49+
assertCompilationErrorCount(2, result);
50+
}
51+
52+
@Test
53+
public void fragment_with_valid_receiver_annotation_compile() throws IOException {
54+
CompileResult result = compileFiles(FragmentWithValidReceiver.class);
55+
assertCompilationSuccessful(result);
56+
}
57+
58+
@Test
59+
public void service_with_valid_receiver_annotation_compile() throws IOException {
60+
CompileResult result = compileFiles(ServiceWithValidReceiver.class);
61+
assertCompilationSuccessful(result);
62+
}
63+
64+
@Test
65+
public void service_with_invalid_registerAt_not_compile() throws IOException {
66+
CompileResult result = compileFiles(ServiceWithInvalidReceiver.class);
67+
assertCompilationErrorOn(ServiceWithInvalidReceiver.class, "@Receiver", result);
68+
assertCompilationErrorCount(3, result);
69+
}
70+
71+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/**
2+
* Copyright (C) 2010-2013 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.receiver;
17+
18+
import android.app.Service;
19+
import android.content.Intent;
20+
import android.os.IBinder;
21+
import org.androidannotations.annotations.EService;
22+
import org.androidannotations.annotations.Receiver;
23+
24+
@EService
25+
public class ServiceWithInvalidReceiver extends Service {
26+
27+
@Receiver(actions = "org.androidannotations.ACTION_1", registerAt = Receiver.RegisterAt.OnResumeOnPause)
28+
protected void onActionOnResume() {
29+
30+
}
31+
32+
@Receiver(actions = "org.androidannotations.ACTION_1", registerAt = Receiver.RegisterAt.OnStartOnStop)
33+
protected void onActionOnStart() {
34+
35+
}
36+
37+
@Receiver(actions = "org.androidannotations.ACTION_1", registerAt = Receiver.RegisterAt.OnAttachOnDetach)
38+
protected void onActionOnAttach() {
39+
40+
}
41+
42+
@Override
43+
public IBinder onBind(Intent intent) {
44+
return null;
45+
}
46+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/**
2+
* Copyright (C) 2010-2013 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.receiver;
17+
18+
import android.app.Service;
19+
import android.content.Intent;
20+
import android.os.IBinder;
21+
import org.androidannotations.annotations.EService;
22+
import org.androidannotations.annotations.Receiver;
23+
24+
@EService
25+
public class ServiceWithValidReceiver extends Service {
26+
27+
@Receiver(actions = "org.androidannotations.ACTION_1")
28+
protected void onActionOnCreate() {
29+
30+
}
31+
32+
@Override
33+
public IBinder onBind(Intent intent) {
34+
return null;
35+
}
36+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<!--
3+
4+
Copyright (C) 2010-2013 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.testprocessor"
21+
android:versionCode="1"
22+
android:versionName="1.0" >
23+
24+
25+
<application>
26+
<activity android:name="org.androidannotations.receiver.ActivityWithValidReceiver_" />
27+
<activity android:name="org.androidannotations.receiver.ActivityWithInvalidRegisterAt_" />
28+
<activity android:name="org.androidannotations.receiver.ActivityWithTwoSameNameMethod_" />
29+
<service android:name="org.androidannotations.receiver.ServiceWithValidReceiver_" />
30+
<service android:name="org.androidannotations.receiver.ServiceWithInvalidReceiver_" />
31+
</application>
32+
33+
</manifest>

0 commit comments

Comments
 (0)