|
| 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 | + // CHECKSTYLE:OFF |
| 37 | + String[] methodSignature = { // |
| 38 | + " @Override", // |
| 39 | + " public void onSaveInstanceState(Bundle bundle_) {", // |
| 40 | + " super.onSaveInstanceState(bundle_);", // |
| 41 | + " bundle_.putSparseParcelableArray(\"sparseArrayWithParcelable\", sparseArrayWithParcelable);", // |
| 42 | + " bundle_.putSparseParcelableArray(\"sparseArrayWithExtendParcelable\", sparseArrayWithExtendParcelable);", // |
| 43 | + " }", // |
| 44 | + "", // |
| 45 | + " private void restoreSavedInstanceState_(Bundle savedInstanceState) {", // |
| 46 | + " if (savedInstanceState == null) {", // |
| 47 | + " return;", // |
| 48 | + " }", // |
| 49 | + " sparseArrayWithParcelable = savedInstanceState.getSparseParcelableArray(\"sparseArrayWithParcelable\");", // |
| 50 | + " sparseArrayWithExtendParcelable = savedInstanceState.getSparseParcelableArray(\"sparseArrayWithExtendParcelable\");", // |
| 51 | + " }"}; |
| 52 | + // CHECKSTYLE:ON |
| 53 | + |
| 54 | + CompileResult result = compileFiles(BundleSparseArrayCompileSuccessActivity.class); |
| 55 | + assertCompilationSuccessful(result); |
| 56 | + assertGeneratedClassContains(toGeneratedFile(BundleSparseArrayCompileSuccessActivity.class), methodSignature); |
| 57 | + } |
| 58 | + |
| 59 | + @Test |
| 60 | + public void compileFailWithNoGenericsType() throws IOException { |
| 61 | + CompileResult result = compileFiles(BundleSparseArrayNoGenericsTypeActivity.class); |
| 62 | + assertCompilationErrorOn(BundleSparseArrayNoGenericsTypeActivity.class, "@InstanceState", result); |
| 63 | + } |
| 64 | + |
| 65 | + @Test |
| 66 | + public void compileFailWithNonParcelableType() throws IOException { |
| 67 | + CompileResult result = compileFiles(BundleSparseArrayNoParcelableTypeActivity.class); |
| 68 | + assertCompilationErrorOn(BundleSparseArrayNoParcelableTypeActivity.class, "@InstanceState", result); |
| 69 | + } |
| 70 | + |
| 71 | +} |
0 commit comments