Skip to content
This repository was archived by the owner on Feb 26, 2023. It is now read-only.

Commit 43d4878

Browse files
committed
Added test cases for new bundle types
1 parent 309c776 commit 43d4878

7 files changed

Lines changed: 218 additions & 0 deletions

File tree

‎AndroidAnnotations/androidannotations-core/androidannotations-test/src/main/java/org/androidannotations/test/instancestate/SaveInstanceStateActivity.java‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424

2525
import android.app.Activity;
2626
import android.os.Bundle;
27+
import android.util.SparseArray;
2728

2829
@EActivity(R.layout.main)
2930
public class SaveInstanceStateActivity extends Activity {
@@ -70,6 +71,12 @@ public class SaveInstanceStateActivity extends Activity {
7071
@InstanceState
7172
CharSequence myCharSequence;
7273

74+
@InstanceState
75+
CharSequence[] myCharSequenceArray;
76+
77+
@InstanceState
78+
ArrayList<CharSequence> myCharSequenceArrayList;
79+
7380
@InstanceState
7481
double myDouble;
7582

@@ -183,4 +190,14 @@ public class SaveInstanceStateActivity extends Activity {
183190

184191
@InstanceState
185192
ParcelerBean parcelerBean;
193+
194+
/**
195+
* This member is not tested at SaveInstanceStateActivityParameterizedTest.
196+
*
197+
* The parameters are generating using the system classloader, but the test
198+
* is ran using the special Robolectric classloader which does not contains
199+
* SparseArray.
200+
*/
201+
@InstanceState
202+
SparseArray<MyGenericParcelableBean<Integer>> mySparseParcelableArray;
186203
}

‎AndroidAnnotations/androidannotations-core/androidannotations-test/src/test/java/org/androidannotations/test/instancestate/SaveInstanceStateActivityParameterizedTest.java‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,8 @@ public static Collection<Object[]> generateTestCases() throws Exception {
9494
{ "myParcelableBeanArrayList", Lists.newArrayList(new MyParcelableBean(1), new MyParcelableBean(2), new MyParcelableBean(3)) }, //
9595
{ "myGenericParcelableBeanArrayList", myGenericParcelableBeanArrayList }, //
9696
{ "mySerializableBeanArrayList", Lists.newArrayList(new MySerializableBean(1), new MySerializableBean(2), new MySerializableBean(3)) }, //
97+
{ "myCharSequenceArray", new CharSequence[] { "C1", "C2" } }, //
98+
{ "myCharSequenceArrayList", Lists.newArrayList("C1", "C2") }, //
9799
{ "nullWrappedLong", null }, //
98100
};
99101
// CHECKSTYLE:ON
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
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.helper;
17+
18+
import java.io.IOException;
19+
20+
import org.androidannotations.internal.AndroidAnnotationProcessor;
21+
import org.androidannotations.testutils.AAProcessorTestHelper;
22+
import org.junit.Before;
23+
import org.junit.Test;
24+
25+
public class BundleSparseArrayActivityTest extends AAProcessorTestHelper {
26+
27+
@Before
28+
public void setUp() {
29+
addManifestProcessorParameter(BundleSparseArrayActivityTest.class);
30+
addProcessor(AndroidAnnotationProcessor.class);
31+
addManifestProcessorParameter(BundleSparseArrayActivityTest.class, "AndroidManifest.xml");
32+
}
33+
34+
@Test
35+
public void compileSuccessForBundleSparseArray() {
36+
CompileResult result = compileFiles(BundleSparseArrayCompileSuccessActivity.class);
37+
assertCompilationSuccessful(result);
38+
}
39+
40+
@Test
41+
public void compileFailWithNoGenericsType() throws IOException {
42+
CompileResult result = compileFiles(BundleSparseArrayNoGenericsTypeActivity.class);
43+
assertCompilationErrorOn(BundleSparseArrayNoGenericsTypeActivity.class, "@InstanceState", result);
44+
}
45+
46+
@Test
47+
public void compileFailWithNonParcelableType() throws IOException {
48+
CompileResult result = compileFiles(BundleSparseArrayNoParcelableTypeActivity.class);
49+
assertCompilationErrorOn(BundleSparseArrayNoParcelableTypeActivity.class, "@InstanceState", result);
50+
}
51+
52+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
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.helper;
17+
18+
import org.androidannotations.annotations.EActivity;
19+
import org.androidannotations.annotations.InstanceState;
20+
21+
import android.app.Activity;
22+
import android.os.Parcel;
23+
import android.os.Parcelable;
24+
import android.util.SparseArray;
25+
26+
@EActivity
27+
public class BundleSparseArrayCompileSuccessActivity extends Activity {
28+
29+
@InstanceState
30+
SparseArray<Parcelable> sparseArrayWithParcelable;
31+
32+
@InstanceState
33+
SparseArray<ExtendParcelable> sparseArrayWithExtendParcelable;
34+
35+
static class ExtendParcelable implements Parcelable {
36+
37+
public static final Creator<ExtendParcelable> CREATOR = new Creator<ExtendParcelable>() {
38+
@Override
39+
public ExtendParcelable createFromParcel(Parcel in) {
40+
return new ExtendParcelable(in);
41+
}
42+
43+
@Override
44+
public ExtendParcelable[] newArray(int size) {
45+
return new ExtendParcelable[size];
46+
}
47+
};
48+
49+
protected ExtendParcelable(Parcel in) {
50+
}
51+
52+
@Override
53+
public int describeContents() {
54+
return 0;
55+
}
56+
57+
@Override
58+
public void writeToParcel(Parcel parcel, int i) {
59+
}
60+
}
61+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
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.helper;
17+
18+
import org.androidannotations.annotations.EActivity;
19+
import org.androidannotations.annotations.InstanceState;
20+
21+
import android.app.Activity;
22+
import android.util.SparseArray;
23+
24+
@EActivity
25+
public class BundleSparseArrayNoGenericsTypeActivity extends Activity {
26+
@InstanceState
27+
SparseArray noGenericsType;
28+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
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.helper;
17+
18+
import org.androidannotations.annotations.EActivity;
19+
import org.androidannotations.annotations.InstanceState;
20+
21+
import android.app.Activity;
22+
import android.util.SparseArray;
23+
24+
@EActivity
25+
public class BundleSparseArrayNoParcelableTypeActivity extends Activity {
26+
@InstanceState
27+
SparseArray<Object> noParcelable;
28+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
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 package="org.androidannotations.testprocessor"
20+
xmlns:android="http://schemas.android.com/apk/res/android"
21+
android:versionCode="1"
22+
android:versionName="1.0">
23+
24+
<uses-permission android:name="android.permission.INTERNET"/>
25+
26+
<application
27+
android:debuggable="true">
28+
</application>
29+
30+
</manifest>

0 commit comments

Comments
 (0)